@loaders.gl/gltf 3.4.0-alpha.3 → 3.4.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +15 -0
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +23 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/es5/webp/webp.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +19 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
- package/dist/esm/webp/webp.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +23 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/lib/gltf-utils/gltf-utils.ts +25 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gltf-scenegraph.js","names":["getBinaryImageMetadata","padToNBytes","copyToArray","assert","getAccessorArrayTypeAndLength","getAccessorTypeFromSize","getComponentTypeFromArray","DEFAULT_GLTF_JSON","asset","version","generator","buffers","GLTFScenegraph","constructor","gltf","_defineProperty","json","sourceBuffers","byteLength","getApplicationData","key","data","getExtraData","extras","getExtension","extensionName","isExtension","getUsedExtensions","find","name","extensions","getRequiredExtension","isRequired","getRequiredExtensions","extensionsRequired","extensionsUsed","getRemovedExtensions","extensionsRemoved","getObjectExtension","object","getScene","index","getObject","getNode","getSkin","getMesh","getMaterial","getAccessor","getTexture","getSampler","getImage","getBufferView","getBuffer","array","Error","concat","getTypedArrayForBufferView","bufferView","bufferIndex","buffer","binChunk","byteOffset","Uint8Array","arrayBuffer","getTypedArrayForAccessor","accessor","ArrayType","length","getTypedArrayForImageData","image","addApplicationData","addExtraData","addObjectExtension","registerUsedExtension","setObjectExtension","removeObjectExtension","extension","addExtension","extensionData","arguments","undefined","addRequiredExtension","registerRequiredExtension","ext","push","removeExtension","_removeStringFromArray","Array","isArray","includes","setDefaultScene","sceneIndex","scene","addScene","nodeIndices","scenes","nodes","addNode","node","meshIndex","matrix","nodeData","mesh","addMesh","attributes","indices","material","mode","accessors","_addAttributes","glTFMesh","primitives","indicesAccessor","_addIndices","Number","isFinite","meshes","addPointCloud","accessorIndices","addImage","imageData","mimeTypeOpt","metadata","mimeType","bufferViewIndex","addBufferView","glTFImage","images","glTFBufferView","bufferViews","addAccessor","glTFAccessor","type","size","componentType","count","max","min","addBinaryBuffer","sourceBuffer","minMax","_getAccessorMinMax","accessorDefaults","Math","round","Object","assign","addTexture","texture","imageIndex","glTFTexture","source","textures","addMaterial","pbrMaterialInfo","materials","createBinaryChunk","_this$json","_this$json$buffers","totalByteLength","ArrayBuffer","targetArray","dstByteOffset","binary","string","found","indexOf","splice","result","attributeKey","attributeData","attrName","_getGltfAttributeName","value","attributeName","toLowerCase","initValues","subarray","componentIndex"],"sources":["../../../../src/lib/api/gltf-scenegraph.ts"],"sourcesContent":["import type {\n GLTF,\n GLTFScene,\n GLTFNode,\n GLTFMesh,\n GLTFSkin,\n GLTFMaterial,\n GLTFAccessor,\n GLTFSampler,\n GLTFTexture,\n GLTFImage,\n GLTFBuffer,\n GLTFBufferView,\n GLTFWithBuffers\n} from '../types/gltf-types';\n\nimport {getBinaryImageMetadata} from '@loaders.gl/images';\nimport {padToNBytes, copyToArray} from '@loaders.gl/loader-utils';\nimport {assert} from '../utils/assert';\nimport {\n getAccessorArrayTypeAndLength,\n getAccessorTypeFromSize,\n getComponentTypeFromArray\n} from '../gltf-utils/gltf-utils';\n\nconst DEFAULT_GLTF_JSON: GLTF = {\n asset: {\n version: '2.0',\n generator: 'loaders.gl'\n },\n buffers: []\n};\n\ntype Extension = {[key: string]: any};\n/**\n * Class for structured access to GLTF data\n */\nexport default class GLTFScenegraph {\n // internal\n gltf: GLTFWithBuffers;\n sourceBuffers: any[];\n byteLength: number;\n\n constructor(gltf?: {json: GLTF; buffers?: any[]}) {\n // @ts-ignore\n this.gltf = gltf || {\n json: {...DEFAULT_GLTF_JSON},\n buffers: []\n };\n this.sourceBuffers = [];\n this.byteLength = 0;\n\n // Initialize buffers\n if (this.gltf.buffers && this.gltf.buffers[0]) {\n this.byteLength = this.gltf.buffers[0].byteLength;\n this.sourceBuffers = [this.gltf.buffers[0]];\n }\n }\n\n // Accessors\n\n get json(): GLTF {\n return this.gltf.json;\n }\n\n getApplicationData(key: string): unknown {\n // TODO - Data is already unpacked by GLBParser\n const data = this.json[key];\n return data;\n }\n\n getExtraData(key: string): {[key: string]: unknown} {\n // TODO - Data is already unpacked by GLBParser\n const extras = this.json.extras || {};\n return extras[key];\n }\n\n getExtension<T = Extension>(extensionName: string): T | null {\n const isExtension = this.getUsedExtensions().find((name) => name === extensionName);\n const extensions = this.json.extensions || {};\n return isExtension ? extensions[extensionName] || true : null;\n }\n\n getRequiredExtension<T = Extension>(extensionName: string): T | null {\n const isRequired = this.getRequiredExtensions().find((name) => name === extensionName);\n return isRequired ? this.getExtension(extensionName) : null;\n }\n\n getRequiredExtensions(): string[] {\n return this.json.extensionsRequired || [];\n }\n\n getUsedExtensions(): string[] {\n return this.json.extensionsUsed || [];\n }\n\n getRemovedExtensions(): string[] {\n return (this.json.extensionsRemoved || []) as string[];\n }\n\n getObjectExtension<T = Extension>(object: {[key: string]: any}, extensionName: string): T | null {\n const extensions = object.extensions || {};\n return extensions[extensionName];\n }\n\n getScene(index: number): GLTFScene {\n return this.getObject('scenes', index) as GLTFScene;\n }\n\n getNode(index: number): GLTFNode {\n return this.getObject('nodes', index) as GLTFNode;\n }\n\n getSkin(index: number): GLTFSkin {\n return this.getObject('skins', index) as GLTFSkin;\n }\n\n getMesh(index: number): GLTFMesh {\n return this.getObject('meshes', index) as GLTFMesh;\n }\n\n getMaterial(index: number): GLTFMaterial {\n return this.getObject('materials', index) as GLTFMaterial;\n }\n\n getAccessor(index: number): GLTFAccessor {\n return this.getObject('accessors', index) as GLTFAccessor;\n }\n\n // getCamera(index: number): object | null {\n // return null; // TODO: fix thi: object as null;\n // }\n\n getTexture(index: number): GLTFTexture {\n return this.getObject('textures', index) as GLTFTexture;\n }\n\n getSampler(index: number): GLTFSampler {\n return this.getObject('samplers', index) as GLTFSampler;\n }\n\n getImage(index: number): GLTFImage {\n return this.getObject('images', index) as GLTFImage;\n }\n\n getBufferView(index: number | object): GLTFBufferView {\n return this.getObject('bufferViews', index) as GLTFBufferView;\n }\n\n getBuffer(index: number): GLTFBuffer {\n return this.getObject('buffers', index) as GLTFBuffer;\n }\n\n getObject(array: string, index: number | object): object {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = this.json[array] && (this.json[array] as {}[])[index];\n if (!object) {\n throw new Error(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object;\n }\n\n /**\n * Accepts buffer view index or buffer view object\n * @returns a `Uint8Array`\n */\n getTypedArrayForBufferView(bufferView: number | object): Uint8Array {\n bufferView = this.getBufferView(bufferView);\n // @ts-ignore\n const bufferIndex = bufferView.buffer;\n\n // Get hold of the arrayBuffer\n // const buffer = this.getBuffer(bufferIndex);\n const binChunk = this.gltf.buffers[bufferIndex];\n assert(binChunk);\n\n // @ts-ignore\n const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;\n // @ts-ignore\n return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);\n }\n\n /** Accepts accessor index or accessor object\n * @returns a typed array with type that matches the types\n */\n getTypedArrayForAccessor(accessor: number | object): any {\n // @ts-ignore\n accessor = this.getAccessor(accessor);\n // @ts-ignore\n const bufferView = this.getBufferView(accessor.bufferView);\n const buffer = this.getBuffer(bufferView.buffer);\n // @ts-ignore\n const arrayBuffer = buffer.data;\n\n // Create a new typed array as a view into the combined buffer\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // @ts-ignore\n const byteOffset = bufferView.byteOffset + accessor.byteOffset;\n return new ArrayType(arrayBuffer, byteOffset, length);\n }\n\n /** accepts accessor index or accessor object\n * returns a `Uint8Array`\n */\n getTypedArrayForImageData(image: number | object): Uint8Array {\n // @ts-ignore\n image = this.getAccessor(image);\n // @ts-ignore\n const bufferView = this.getBufferView(image.bufferView);\n const buffer = this.getBuffer(bufferView.buffer);\n // @ts-ignore\n const arrayBuffer = buffer.data;\n\n const byteOffset = bufferView.byteOffset || 0;\n return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);\n }\n\n // MODIFERS\n\n /**\n * Add an extra application-defined key to the top-level data structure\n */\n addApplicationData(key: string, data: object): GLTFScenegraph {\n this.json[key] = data;\n return this;\n }\n\n /**\n * `extras` - Standard GLTF field for storing application specific data\n */\n addExtraData(key: string, data: object): GLTFScenegraph {\n this.json.extras = this.json.extras || {};\n (this.json.extras as Record<string, unknown>)[key] = data;\n return this;\n }\n\n addObjectExtension(object: object, extensionName: string, data: object): GLTFScenegraph {\n // @ts-ignore\n object.extensions = object.extensions || {};\n // TODO - clobber or merge?\n // @ts-ignore\n object.extensions[extensionName] = data;\n this.registerUsedExtension(extensionName);\n return this;\n }\n\n setObjectExtension(object: object, extensionName: string, data: object): void {\n // @ts-ignore\n const extensions = object.extensions || {};\n extensions[extensionName] = data;\n // TODO - add to usedExtensions...\n }\n\n removeObjectExtension(object: object, extensionName: string): object {\n // @ts-ignore\n const extensions = object.extensions || {};\n const extension = extensions[extensionName];\n delete extensions[extensionName];\n return extension;\n }\n\n /**\n * Add to standard GLTF top level extension object, mark as used\n */\n addExtension(extensionName: string, extensionData: object = {}): object {\n assert(extensionData);\n this.json.extensions = this.json.extensions || {};\n (this.json.extensions as Record<string, unknown>)[extensionName] = extensionData;\n this.registerUsedExtension(extensionName);\n return extensionData;\n }\n\n /**\n * Standard GLTF top level extension object, mark as used and required\n */\n addRequiredExtension(extensionName, extensionData: object = {}): object {\n assert(extensionData);\n this.addExtension(extensionName, extensionData);\n this.registerRequiredExtension(extensionName);\n return extensionData;\n }\n\n /**\n * Add extensionName to list of used extensions\n */\n registerUsedExtension(extensionName: string): void {\n this.json.extensionsUsed = this.json.extensionsUsed || [];\n if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) {\n this.json.extensionsUsed.push(extensionName);\n }\n }\n\n /**\n * Add extensionName to list of required extensions\n */\n registerRequiredExtension(extensionName: string): void {\n this.registerUsedExtension(extensionName);\n this.json.extensionsRequired = this.json.extensionsRequired || [];\n if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) {\n this.json.extensionsRequired.push(extensionName);\n }\n }\n\n /**\n * Removes an extension from the top-level list\n */\n removeExtension(extensionName: string): void {\n if (!this.getExtension(extensionName)) {\n return;\n }\n if (this.json.extensionsRequired) {\n this._removeStringFromArray(this.json.extensionsRequired, extensionName);\n }\n if (this.json.extensionsUsed) {\n this._removeStringFromArray(this.json.extensionsUsed, extensionName);\n }\n if (this.json.extensions) {\n delete this.json.extensions[extensionName];\n }\n if (!Array.isArray(this.json.extensionsRemoved)) {\n this.json.extensionsRemoved = [];\n }\n const extensionsRemoved = this.json.extensionsRemoved as string[];\n if (!extensionsRemoved.includes(extensionName)) {\n extensionsRemoved.push(extensionName);\n }\n }\n\n /**\n * Set default scene which is to be displayed at load time\n */\n setDefaultScene(sceneIndex: number): void {\n this.json.scene = sceneIndex;\n }\n\n /**\n * @todo: add more properties for scene initialization:\n * name`, `extensions`, `extras`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene\n */\n addScene(scene: {nodeIndices: number[]}): number {\n const {nodeIndices} = scene;\n this.json.scenes = this.json.scenes || [];\n this.json.scenes.push({nodes: nodeIndices});\n return this.json.scenes.length - 1;\n }\n\n /**\n * @todo: add more properties for node initialization:\n * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node\n */\n addNode(node: {meshIndex: number; matrix?: number[]}): number {\n const {meshIndex, matrix} = node;\n this.json.nodes = this.json.nodes || [];\n const nodeData = {mesh: meshIndex};\n if (matrix) {\n // @ts-ignore\n nodeData.matrix = matrix;\n }\n this.json.nodes.push(nodeData);\n return this.json.nodes.length - 1;\n }\n\n /** Adds a mesh to the json part */\n addMesh(mesh: {attributes: object; indices?: object; material?: number; mode?: number}): number {\n const {attributes, indices, material, mode = 4} = mesh;\n const accessors = this._addAttributes(attributes);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: accessors,\n mode\n }\n ]\n };\n\n if (indices) {\n const indicesAccessor = this._addIndices(indices);\n // @ts-ignore\n glTFMesh.primitives[0].indices = indicesAccessor;\n }\n\n if (Number.isFinite(material)) {\n // @ts-ignore\n glTFMesh.primitives[0].material = material;\n }\n\n this.json.meshes = this.json.meshes || [];\n this.json.meshes.push(glTFMesh);\n return this.json.meshes.length - 1;\n }\n\n addPointCloud(attributes: object): number {\n // @ts-ignore\n const accessorIndices = this._addAttributes(attributes);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: accessorIndices,\n mode: 0 // GL.POINTS\n }\n ]\n };\n\n this.json.meshes = this.json.meshes || [];\n this.json.meshes.push(glTFMesh);\n return this.json.meshes.length - 1;\n }\n\n /**\n * Adds a binary image. Builds glTF \"JSON metadata\" and saves buffer reference\n * Buffer will be copied into BIN chunk during \"pack\"\n * Currently encodes as glTF image\n * @param imageData\n * @param mimeType\n */\n addImage(imageData: any, mimeTypeOpt?: string): number {\n // If image is referencing a bufferView instead of URI, mimeType must be defined:\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images\n // \"a reference to a bufferView; in that case mimeType must be defined.\"\n const metadata = getBinaryImageMetadata(imageData);\n const mimeType = mimeTypeOpt || metadata?.mimeType;\n\n const bufferViewIndex = this.addBufferView(imageData);\n\n const glTFImage = {\n bufferView: bufferViewIndex,\n mimeType\n };\n\n this.json.images = this.json.images || [];\n this.json.images.push(glTFImage);\n return this.json.images.length - 1;\n }\n\n /**\n * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index\n * @param buffer\n */\n addBufferView(buffer: any): number {\n const byteLength = buffer.byteLength;\n assert(Number.isFinite(byteLength));\n\n // Add this buffer to the list of buffers to be written to the body.\n this.sourceBuffers = this.sourceBuffers || [];\n this.sourceBuffers.push(buffer);\n\n const glTFBufferView = {\n buffer: 0,\n // Write offset from the start of the binary body\n byteOffset: this.byteLength,\n byteLength\n };\n\n // We've now added the contents to the body, so update the total length\n // Every sub-chunk needs to be 4-byte align ed\n this.byteLength += padToNBytes(byteLength, 4);\n\n // Add a bufferView indicating start and length of this binary sub-chunk\n this.json.bufferViews = this.json.bufferViews || [];\n this.json.bufferViews.push(glTFBufferView);\n return this.json.bufferViews.length - 1;\n }\n\n /**\n * Adds an accessor to a bufferView\n * @param bufferViewIndex\n * @param accessor\n */\n addAccessor(bufferViewIndex: number, accessor: object): number {\n const glTFAccessor = {\n bufferView: bufferViewIndex,\n // @ts-ignore\n type: getAccessorTypeFromSize(accessor.size),\n // @ts-ignore\n componentType: accessor.componentType,\n // @ts-ignore\n count: accessor.count,\n // @ts-ignore\n max: accessor.max,\n // @ts-ignore\n min: accessor.min\n };\n\n this.json.accessors = this.json.accessors || [];\n this.json.accessors.push(glTFAccessor);\n return this.json.accessors.length - 1;\n }\n\n /**\n * Add a binary buffer. Builds glTF \"JSON metadata\" and saves buffer reference\n * Buffer will be copied into BIN chunk during \"pack\"\n * Currently encodes buffers as glTF accessors, but this could be optimized\n * @param sourceBuffer\n * @param accessor\n */\n addBinaryBuffer(sourceBuffer: any, accessor: object = {size: 3}): number {\n const bufferViewIndex = this.addBufferView(sourceBuffer);\n // @ts-ignore\n let minMax = {min: accessor.min, max: accessor.max};\n if (!minMax.min || !minMax.max) {\n // @ts-ignore\n minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);\n }\n\n const accessorDefaults = {\n // @ts-ignore\n size: accessor.size,\n componentType: getComponentTypeFromArray(sourceBuffer),\n // @ts-ignore\n count: Math.round(sourceBuffer.length / accessor.size),\n min: minMax.min,\n max: minMax.max\n };\n\n return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));\n }\n\n /**\n * Adds a texture to the json part\n * @todo: add more properties for texture initialization\n * `sampler`, `name`, `extensions`, `extras`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\n */\n addTexture(texture: {imageIndex: number}): number {\n const {imageIndex} = texture;\n const glTFTexture = {\n source: imageIndex\n };\n\n this.json.textures = this.json.textures || [];\n this.json.textures.push(glTFTexture);\n return this.json.textures.length - 1;\n }\n\n /** Adds a material to the json part */\n addMaterial(pbrMaterialInfo: Object): number {\n this.json.materials = this.json.materials || [];\n this.json.materials.push(pbrMaterialInfo);\n return this.json.materials.length - 1;\n }\n\n /** Pack the binary chunk */\n createBinaryChunk(): void {\n // Encoder expects this array undefined or empty\n this.gltf.buffers = [];\n\n // Allocate total array\n const totalByteLength = this.byteLength;\n const arrayBuffer = new ArrayBuffer(totalByteLength);\n const targetArray = new Uint8Array(arrayBuffer);\n\n // Copy each array into\n let dstByteOffset = 0;\n for (const sourceBuffer of this.sourceBuffers || []) {\n dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);\n }\n\n // Update the glTF BIN CHUNK byte length\n if (this.json?.buffers?.[0]) {\n this.json.buffers[0].byteLength = totalByteLength;\n } else {\n this.json.buffers = [{byteLength: totalByteLength}];\n }\n\n // Save generated arrayBuffer\n this.gltf.binary = arrayBuffer;\n\n // Put arrayBuffer to sourceBuffers for possible additional writing data in the chunk\n this.sourceBuffers = [arrayBuffer];\n }\n\n // PRIVATE\n\n _removeStringFromArray(array, string) {\n let found = true;\n while (found) {\n const index = array.indexOf(string);\n if (index > -1) {\n array.splice(index, 1);\n } else {\n found = false;\n }\n }\n }\n\n /**\n * Add attributes to buffers and create `attributes` object which is part of `mesh`\n */\n _addAttributes(attributes = {}) {\n const result = {};\n for (const attributeKey in attributes) {\n const attributeData = attributes[attributeKey];\n const attrName = this._getGltfAttributeName(attributeKey);\n const accessor = this.addBinaryBuffer(attributeData.value, attributeData);\n result[attrName] = accessor;\n }\n return result;\n }\n\n /**\n * Add indices to buffers\n */\n _addIndices(indices) {\n return this.addBinaryBuffer(indices, {size: 1});\n }\n\n /**\n * Deduce gltf specific attribue name from input attribute name\n */\n _getGltfAttributeName(attributeName) {\n switch (attributeName.toLowerCase()) {\n case 'position':\n case 'positions':\n case 'vertices':\n return 'POSITION';\n case 'normal':\n case 'normals':\n return 'NORMAL';\n case 'color':\n case 'colors':\n return 'COLOR_0';\n case 'texcoord':\n case 'texcoords':\n return 'TEXCOORD_0';\n default:\n return attributeName;\n }\n }\n\n /**\n * Calculate `min` and `max` arrays of accessor according to spec:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor\n */\n _getAccessorMinMax(buffer, size) {\n const result = {min: null, max: null};\n if (buffer.length < size) {\n return result;\n }\n // @ts-ignore\n result.min = [];\n // @ts-ignore\n result.max = [];\n const initValues = buffer.subarray(0, size);\n for (const value of initValues) {\n // @ts-ignore\n result.min.push(value);\n // @ts-ignore\n result.max.push(value);\n }\n\n for (let index = size; index < buffer.length; index += size) {\n for (let componentIndex = 0; componentIndex < size; componentIndex++) {\n // @ts-ignore\n result.min[0 + componentIndex] = Math.min(\n // @ts-ignore\n result.min[0 + componentIndex],\n buffer[index + componentIndex]\n );\n // @ts-ignore\n result.max[0 + componentIndex] = Math.max(\n // @ts-ignore\n result.max[0 + componentIndex],\n buffer[index + componentIndex]\n );\n }\n }\n return result;\n }\n}\n"],"mappings":";AAgBA,SAAQA,sBAAsB,QAAO,oBAAoB;AACzD,SAAQC,WAAW,EAAEC,WAAW,QAAO,0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C,EAC9BvH,MAAM,CAAClB,KAAK,GAAGyI,cAAc,CAAC,CAC/B;QAEDV,MAAM,CAAChC,GAAG,CAAC,CAAC,GAAG0C,cAAc,CAAC,GAAGnC,IAAI,CAACP,GAAG,CAEvCgC,MAAM,CAAChC,GAAG,CAAC,CAAC,GAAG0C,cAAc,CAAC,EAC9BvH,MAAM,CAAClB,KAAK,GAAGyI,cAAc,CAAC,CAC/B;MACH;IACF;IACA,OAAOV,MAAM;EACf;AACF"}
|
|
1
|
+
{"version":3,"file":"gltf-scenegraph.js","names":["getBinaryImageMetadata","padToNBytes","copyToArray","assert","getAccessorArrayTypeAndLength","getAccessorTypeFromSize","getComponentTypeFromArray","DEFAULT_GLTF_JSON","asset","version","generator","buffers","GLTFScenegraph","constructor","gltf","_defineProperty","json","sourceBuffers","byteLength","getApplicationData","key","data","getExtraData","extras","getExtension","extensionName","isExtension","getUsedExtensions","find","name","extensions","getRequiredExtension","isRequired","getRequiredExtensions","extensionsRequired","extensionsUsed","getRemovedExtensions","extensionsRemoved","getObjectExtension","object","getScene","index","getObject","getNode","getSkin","getMesh","getMaterial","getAccessor","getTexture","getSampler","getImage","getBufferView","getBuffer","array","Error","concat","getTypedArrayForBufferView","bufferView","bufferIndex","buffer","binChunk","byteOffset","Uint8Array","arrayBuffer","getTypedArrayForAccessor","accessor","ArrayType","length","getTypedArrayForImageData","image","addApplicationData","addExtraData","addObjectExtension","registerUsedExtension","setObjectExtension","removeObjectExtension","extension","addExtension","extensionData","arguments","undefined","addRequiredExtension","registerRequiredExtension","ext","push","removeExtension","_removeStringFromArray","Array","isArray","includes","setDefaultScene","sceneIndex","scene","addScene","nodeIndices","scenes","nodes","addNode","node","meshIndex","matrix","nodeData","mesh","addMesh","attributes","indices","material","mode","accessors","_addAttributes","glTFMesh","primitives","indicesAccessor","_addIndices","Number","isFinite","meshes","addPointCloud","accessorIndices","addImage","imageData","mimeTypeOpt","metadata","mimeType","bufferViewIndex","addBufferView","glTFImage","images","glTFBufferView","bufferViews","addAccessor","glTFAccessor","type","size","componentType","count","max","min","addBinaryBuffer","sourceBuffer","minMax","_getAccessorMinMax","accessorDefaults","Math","round","Object","assign","addTexture","texture","imageIndex","glTFTexture","source","textures","addMaterial","pbrMaterialInfo","materials","createBinaryChunk","_this$json","_this$json$buffers","totalByteLength","ArrayBuffer","targetArray","dstByteOffset","binary","string","found","indexOf","splice","result","attributeKey","attributeData","attrName","_getGltfAttributeName","value","attributeName","toLowerCase","initValues","subarray","componentIndex"],"sources":["../../../../src/lib/api/gltf-scenegraph.ts"],"sourcesContent":["import type {\n GLTF,\n GLTFScene,\n GLTFNode,\n GLTFMesh,\n GLTFSkin,\n GLTFMaterial,\n GLTFAccessor,\n GLTFSampler,\n GLTFTexture,\n GLTFImage,\n GLTFBuffer,\n GLTFBufferView,\n GLTFWithBuffers\n} from '../types/gltf-types';\n\nimport {getBinaryImageMetadata} from '@loaders.gl/images';\nimport {padToNBytes, copyToArray} from '@loaders.gl/loader-utils';\nimport {assert} from '../utils/assert';\nimport {\n getAccessorArrayTypeAndLength,\n getAccessorTypeFromSize,\n getComponentTypeFromArray\n} from '../gltf-utils/gltf-utils';\n\nconst DEFAULT_GLTF_JSON: GLTF = {\n asset: {\n version: '2.0',\n generator: 'loaders.gl'\n },\n buffers: []\n};\n\ntype Extension = {[key: string]: any};\n/**\n * Class for structured access to GLTF data\n */\nexport default class GLTFScenegraph {\n // internal\n gltf: GLTFWithBuffers;\n sourceBuffers: any[];\n byteLength: number;\n\n constructor(gltf?: {json: GLTF; buffers?: any[]}) {\n // @ts-ignore\n this.gltf = gltf || {\n json: {...DEFAULT_GLTF_JSON},\n buffers: []\n };\n this.sourceBuffers = [];\n this.byteLength = 0;\n\n // Initialize buffers\n if (this.gltf.buffers && this.gltf.buffers[0]) {\n this.byteLength = this.gltf.buffers[0].byteLength;\n this.sourceBuffers = [this.gltf.buffers[0]];\n }\n }\n\n // Accessors\n\n get json(): GLTF {\n return this.gltf.json;\n }\n\n getApplicationData(key: string): unknown {\n // TODO - Data is already unpacked by GLBParser\n const data = this.json[key];\n return data;\n }\n\n getExtraData(key: string): {[key: string]: unknown} {\n // TODO - Data is already unpacked by GLBParser\n const extras = this.json.extras || {};\n return extras[key];\n }\n\n getExtension<T = Extension>(extensionName: string): T | null {\n const isExtension = this.getUsedExtensions().find((name) => name === extensionName);\n const extensions = this.json.extensions || {};\n return isExtension ? extensions[extensionName] || true : null;\n }\n\n getRequiredExtension<T = Extension>(extensionName: string): T | null {\n const isRequired = this.getRequiredExtensions().find((name) => name === extensionName);\n return isRequired ? this.getExtension(extensionName) : null;\n }\n\n getRequiredExtensions(): string[] {\n return this.json.extensionsRequired || [];\n }\n\n getUsedExtensions(): string[] {\n return this.json.extensionsUsed || [];\n }\n\n getRemovedExtensions(): string[] {\n return (this.json.extensionsRemoved || []) as string[];\n }\n\n getObjectExtension<T = Extension>(object: {[key: string]: any}, extensionName: string): T | null {\n const extensions = object.extensions || {};\n return extensions[extensionName];\n }\n\n getScene(index: number): GLTFScene {\n return this.getObject('scenes', index) as GLTFScene;\n }\n\n getNode(index: number): GLTFNode {\n return this.getObject('nodes', index) as GLTFNode;\n }\n\n getSkin(index: number): GLTFSkin {\n return this.getObject('skins', index) as GLTFSkin;\n }\n\n getMesh(index: number): GLTFMesh {\n return this.getObject('meshes', index) as GLTFMesh;\n }\n\n getMaterial(index: number): GLTFMaterial {\n return this.getObject('materials', index) as GLTFMaterial;\n }\n\n getAccessor(index: number): GLTFAccessor {\n return this.getObject('accessors', index) as GLTFAccessor;\n }\n\n // getCamera(index: number): object | null {\n // return null; // TODO: fix thi: object as null;\n // }\n\n getTexture(index: number): GLTFTexture {\n return this.getObject('textures', index) as GLTFTexture;\n }\n\n getSampler(index: number): GLTFSampler {\n return this.getObject('samplers', index) as GLTFSampler;\n }\n\n getImage(index: number): GLTFImage {\n return this.getObject('images', index) as GLTFImage;\n }\n\n getBufferView(index: number | object): GLTFBufferView {\n return this.getObject('bufferViews', index) as GLTFBufferView;\n }\n\n getBuffer(index: number): GLTFBuffer {\n return this.getObject('buffers', index) as GLTFBuffer;\n }\n\n getObject(array: string, index: number | object): object {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = this.json[array] && (this.json[array] as {}[])[index];\n if (!object) {\n throw new Error(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object;\n }\n\n /**\n * Accepts buffer view index or buffer view object\n * @returns a `Uint8Array`\n */\n getTypedArrayForBufferView(bufferView: number | object): Uint8Array {\n bufferView = this.getBufferView(bufferView);\n // @ts-ignore\n const bufferIndex = bufferView.buffer;\n\n // Get hold of the arrayBuffer\n // const buffer = this.getBuffer(bufferIndex);\n const binChunk = this.gltf.buffers[bufferIndex];\n assert(binChunk);\n\n // @ts-ignore\n const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;\n // @ts-ignore\n return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);\n }\n\n /** Accepts accessor index or accessor object\n * @returns a typed array with type that matches the types\n */\n getTypedArrayForAccessor(accessor: number | object): any {\n // @ts-ignore\n accessor = this.getAccessor(accessor);\n // @ts-ignore\n const bufferView = this.getBufferView(accessor.bufferView);\n const buffer = this.getBuffer(bufferView.buffer);\n // @ts-ignore\n const arrayBuffer = buffer.data;\n\n // Create a new typed array as a view into the combined buffer\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // @ts-ignore\n const byteOffset = bufferView.byteOffset + accessor.byteOffset;\n return new ArrayType(arrayBuffer, byteOffset, length);\n }\n\n /** accepts accessor index or accessor object\n * returns a `Uint8Array`\n */\n getTypedArrayForImageData(image: number | object): Uint8Array {\n // @ts-ignore\n image = this.getAccessor(image);\n // @ts-ignore\n const bufferView = this.getBufferView(image.bufferView);\n const buffer = this.getBuffer(bufferView.buffer);\n // @ts-ignore\n const arrayBuffer = buffer.data;\n\n const byteOffset = bufferView.byteOffset || 0;\n return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);\n }\n\n // MODIFERS\n\n /**\n * Add an extra application-defined key to the top-level data structure\n */\n addApplicationData(key: string, data: object): GLTFScenegraph {\n this.json[key] = data;\n return this;\n }\n\n /**\n * `extras` - Standard GLTF field for storing application specific data\n */\n addExtraData(key: string, data: object): GLTFScenegraph {\n this.json.extras = this.json.extras || {};\n (this.json.extras as Record<string, unknown>)[key] = data;\n return this;\n }\n\n addObjectExtension(object: object, extensionName: string, data: object): GLTFScenegraph {\n // @ts-ignore\n object.extensions = object.extensions || {};\n // TODO - clobber or merge?\n // @ts-ignore\n object.extensions[extensionName] = data;\n this.registerUsedExtension(extensionName);\n return this;\n }\n\n setObjectExtension(object: object, extensionName: string, data: object): void {\n // @ts-ignore\n const extensions = object.extensions || {};\n extensions[extensionName] = data;\n // TODO - add to usedExtensions...\n }\n\n removeObjectExtension(object: object, extensionName: string): object {\n // @ts-ignore\n const extensions = object.extensions || {};\n const extension = extensions[extensionName];\n delete extensions[extensionName];\n return extension;\n }\n\n /**\n * Add to standard GLTF top level extension object, mark as used\n */\n addExtension(extensionName: string, extensionData: object = {}): object {\n assert(extensionData);\n this.json.extensions = this.json.extensions || {};\n (this.json.extensions as Record<string, unknown>)[extensionName] = extensionData;\n this.registerUsedExtension(extensionName);\n return extensionData;\n }\n\n /**\n * Standard GLTF top level extension object, mark as used and required\n */\n addRequiredExtension(extensionName, extensionData: object = {}): object {\n assert(extensionData);\n this.addExtension(extensionName, extensionData);\n this.registerRequiredExtension(extensionName);\n return extensionData;\n }\n\n /**\n * Add extensionName to list of used extensions\n */\n registerUsedExtension(extensionName: string): void {\n this.json.extensionsUsed = this.json.extensionsUsed || [];\n if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) {\n this.json.extensionsUsed.push(extensionName);\n }\n }\n\n /**\n * Add extensionName to list of required extensions\n */\n registerRequiredExtension(extensionName: string): void {\n this.registerUsedExtension(extensionName);\n this.json.extensionsRequired = this.json.extensionsRequired || [];\n if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) {\n this.json.extensionsRequired.push(extensionName);\n }\n }\n\n /**\n * Removes an extension from the top-level list\n */\n removeExtension(extensionName: string): void {\n if (!this.getExtension(extensionName)) {\n return;\n }\n if (this.json.extensionsRequired) {\n this._removeStringFromArray(this.json.extensionsRequired, extensionName);\n }\n if (this.json.extensionsUsed) {\n this._removeStringFromArray(this.json.extensionsUsed, extensionName);\n }\n if (this.json.extensions) {\n delete this.json.extensions[extensionName];\n }\n if (!Array.isArray(this.json.extensionsRemoved)) {\n this.json.extensionsRemoved = [];\n }\n const extensionsRemoved = this.json.extensionsRemoved as string[];\n if (!extensionsRemoved.includes(extensionName)) {\n extensionsRemoved.push(extensionName);\n }\n }\n\n /**\n * Set default scene which is to be displayed at load time\n */\n setDefaultScene(sceneIndex: number): void {\n this.json.scene = sceneIndex;\n }\n\n /**\n * @todo: add more properties for scene initialization:\n * name`, `extensions`, `extras`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene\n */\n addScene(scene: {nodeIndices: number[]}): number {\n const {nodeIndices} = scene;\n this.json.scenes = this.json.scenes || [];\n this.json.scenes.push({nodes: nodeIndices});\n return this.json.scenes.length - 1;\n }\n\n /**\n * @todo: add more properties for node initialization:\n * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node\n */\n addNode(node: {meshIndex: number; matrix?: number[]}): number {\n const {meshIndex, matrix} = node;\n this.json.nodes = this.json.nodes || [];\n const nodeData = {mesh: meshIndex};\n if (matrix) {\n // @ts-ignore\n nodeData.matrix = matrix;\n }\n this.json.nodes.push(nodeData);\n return this.json.nodes.length - 1;\n }\n\n /** Adds a mesh to the json part */\n addMesh(mesh: {attributes: object; indices?: object; material?: number; mode?: number}): number {\n const {attributes, indices, material, mode = 4} = mesh;\n const accessors = this._addAttributes(attributes);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: accessors,\n mode\n }\n ]\n };\n\n if (indices) {\n const indicesAccessor = this._addIndices(indices);\n // @ts-ignore\n glTFMesh.primitives[0].indices = indicesAccessor;\n }\n\n if (Number.isFinite(material)) {\n // @ts-ignore\n glTFMesh.primitives[0].material = material;\n }\n\n this.json.meshes = this.json.meshes || [];\n this.json.meshes.push(glTFMesh);\n return this.json.meshes.length - 1;\n }\n\n addPointCloud(attributes: object): number {\n // @ts-ignore\n const accessorIndices = this._addAttributes(attributes);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: accessorIndices,\n mode: 0 // GL.POINTS\n }\n ]\n };\n\n this.json.meshes = this.json.meshes || [];\n this.json.meshes.push(glTFMesh);\n return this.json.meshes.length - 1;\n }\n\n /**\n * Adds a binary image. Builds glTF \"JSON metadata\" and saves buffer reference\n * Buffer will be copied into BIN chunk during \"pack\"\n * Currently encodes as glTF image\n * @param imageData\n * @param mimeType\n */\n addImage(imageData: any, mimeTypeOpt?: string): number {\n // If image is referencing a bufferView instead of URI, mimeType must be defined:\n // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images\n // \"a reference to a bufferView; in that case mimeType must be defined.\"\n const metadata = getBinaryImageMetadata(imageData);\n const mimeType = mimeTypeOpt || metadata?.mimeType;\n\n const bufferViewIndex = this.addBufferView(imageData);\n\n const glTFImage = {\n bufferView: bufferViewIndex,\n mimeType\n };\n\n this.json.images = this.json.images || [];\n this.json.images.push(glTFImage);\n return this.json.images.length - 1;\n }\n\n /**\n * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index\n * @param buffer\n */\n addBufferView(buffer: any): number {\n const byteLength = buffer.byteLength;\n assert(Number.isFinite(byteLength));\n\n // Add this buffer to the list of buffers to be written to the body.\n this.sourceBuffers = this.sourceBuffers || [];\n this.sourceBuffers.push(buffer);\n\n const glTFBufferView = {\n buffer: 0,\n // Write offset from the start of the binary body\n byteOffset: this.byteLength,\n byteLength\n };\n\n // We've now added the contents to the body, so update the total length\n // Every sub-chunk needs to be 4-byte align ed\n this.byteLength += padToNBytes(byteLength, 4);\n\n // Add a bufferView indicating start and length of this binary sub-chunk\n this.json.bufferViews = this.json.bufferViews || [];\n this.json.bufferViews.push(glTFBufferView);\n return this.json.bufferViews.length - 1;\n }\n\n /**\n * Adds an accessor to a bufferView\n * @param bufferViewIndex\n * @param accessor\n */\n addAccessor(bufferViewIndex: number, accessor: object): number {\n const glTFAccessor = {\n bufferView: bufferViewIndex,\n // @ts-ignore\n type: getAccessorTypeFromSize(accessor.size),\n // @ts-ignore\n componentType: accessor.componentType,\n // @ts-ignore\n count: accessor.count,\n // @ts-ignore\n max: accessor.max,\n // @ts-ignore\n min: accessor.min\n };\n\n this.json.accessors = this.json.accessors || [];\n this.json.accessors.push(glTFAccessor);\n return this.json.accessors.length - 1;\n }\n\n /**\n * Add a binary buffer. Builds glTF \"JSON metadata\" and saves buffer reference\n * Buffer will be copied into BIN chunk during \"pack\"\n * Currently encodes buffers as glTF accessors, but this could be optimized\n * @param sourceBuffer\n * @param accessor\n */\n addBinaryBuffer(sourceBuffer: any, accessor: object = {size: 3}): number {\n const bufferViewIndex = this.addBufferView(sourceBuffer);\n // @ts-ignore\n let minMax = {min: accessor.min, max: accessor.max};\n if (!minMax.min || !minMax.max) {\n // @ts-ignore\n minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);\n }\n\n const accessorDefaults = {\n // @ts-ignore\n size: accessor.size,\n componentType: getComponentTypeFromArray(sourceBuffer),\n // @ts-ignore\n count: Math.round(sourceBuffer.length / accessor.size),\n min: minMax.min,\n max: minMax.max\n };\n\n return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));\n }\n\n /**\n * Adds a texture to the json part\n * @todo: add more properties for texture initialization\n * `sampler`, `name`, `extensions`, `extras`\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\n */\n addTexture(texture: {imageIndex: number}): number {\n const {imageIndex} = texture;\n const glTFTexture = {\n source: imageIndex\n };\n\n this.json.textures = this.json.textures || [];\n this.json.textures.push(glTFTexture);\n return this.json.textures.length - 1;\n }\n\n /** Adds a material to the json part */\n addMaterial(pbrMaterialInfo: Object): number {\n this.json.materials = this.json.materials || [];\n this.json.materials.push(pbrMaterialInfo);\n return this.json.materials.length - 1;\n }\n\n /** Pack the binary chunk */\n createBinaryChunk(): void {\n // Encoder expects this array undefined or empty\n this.gltf.buffers = [];\n\n // Allocate total array\n const totalByteLength = this.byteLength;\n const arrayBuffer = new ArrayBuffer(totalByteLength);\n const targetArray = new Uint8Array(arrayBuffer);\n\n // Copy each array into\n let dstByteOffset = 0;\n for (const sourceBuffer of this.sourceBuffers || []) {\n dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);\n }\n\n // Update the glTF BIN CHUNK byte length\n if (this.json?.buffers?.[0]) {\n this.json.buffers[0].byteLength = totalByteLength;\n } else {\n this.json.buffers = [{byteLength: totalByteLength}];\n }\n\n // Save generated arrayBuffer\n this.gltf.binary = arrayBuffer;\n\n // Put arrayBuffer to sourceBuffers for possible additional writing data in the chunk\n this.sourceBuffers = [arrayBuffer];\n }\n\n // PRIVATE\n\n _removeStringFromArray(array, string) {\n let found = true;\n while (found) {\n const index = array.indexOf(string);\n if (index > -1) {\n array.splice(index, 1);\n } else {\n found = false;\n }\n }\n }\n\n /**\n * Add attributes to buffers and create `attributes` object which is part of `mesh`\n */\n _addAttributes(attributes = {}) {\n const result = {};\n for (const attributeKey in attributes) {\n const attributeData = attributes[attributeKey];\n const attrName = this._getGltfAttributeName(attributeKey);\n const accessor = this.addBinaryBuffer(attributeData.value, attributeData);\n result[attrName] = accessor;\n }\n return result;\n }\n\n /**\n * Add indices to buffers\n */\n _addIndices(indices) {\n return this.addBinaryBuffer(indices, {size: 1});\n }\n\n /**\n * Deduce gltf specific attribue name from input attribute name\n */\n _getGltfAttributeName(attributeName) {\n switch (attributeName.toLowerCase()) {\n case 'position':\n case 'positions':\n case 'vertices':\n return 'POSITION';\n case 'normal':\n case 'normals':\n return 'NORMAL';\n case 'color':\n case 'colors':\n return 'COLOR_0';\n case 'texcoord':\n case 'texcoords':\n return 'TEXCOORD_0';\n default:\n return attributeName;\n }\n }\n\n /**\n * Calculate `min` and `max` arrays of accessor according to spec:\n * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor\n */\n _getAccessorMinMax(buffer, size) {\n const result = {min: null, max: null};\n if (buffer.length < size) {\n return result;\n }\n // @ts-ignore\n result.min = [];\n // @ts-ignore\n result.max = [];\n const initValues = buffer.subarray(0, size);\n for (const value of initValues) {\n // @ts-ignore\n result.min.push(value);\n // @ts-ignore\n result.max.push(value);\n }\n\n for (let index = size; index < buffer.length; index += size) {\n for (let componentIndex = 0; componentIndex < size; componentIndex++) {\n // @ts-ignore\n result.min[0 + componentIndex] = Math.min(\n // @ts-ignore\n result.min[0 + componentIndex],\n buffer[index + componentIndex]\n );\n // @ts-ignore\n result.max[0 + componentIndex] = Math.max(\n // @ts-ignore\n result.max[0 + componentIndex],\n buffer[index + componentIndex]\n );\n }\n }\n return result;\n }\n}\n"],"mappings":";AAgBA,SAAQA,sBAAsB,QAAO,oBAAoB;AACzD,SAAQC,WAAW,EAAEC,WAAW,QAAO,0BAA0B;AACjE,SAAQC,MAAM,QAAO,iBAAiB;AACtC,SACEC,6BAA6B,EAC7BC,uBAAuB,EACvBC,yBAAyB,QACpB,0BAA0B;AAEjC,MAAMC,iBAAuB,GAAG;EAC9BC,KAAK,EAAE;IACLC,OAAO,EAAE,KAAK;IACdC,SAAS,EAAE;EACb,CAAC;EACDC,OAAO,EAAE;AACX,CAAC;AAMD,eAAe,MAAMC,cAAc,CAAC;EAMlCC,WAAWA,CAACC,IAAoC,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAEhD,IAAI,CAACD,IAAI,GAAGA,IAAI,IAAI;MAClBE,IAAI,EAAE;QAAC,GAAGT;MAAiB,CAAC;MAC5BI,OAAO,EAAE;IACX,CAAC;IACD,IAAI,CAACM,aAAa,GAAG,EAAE;IACvB,IAAI,CAACC,UAAU,G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,EAAE;MACxB,OAAOmC,MAAM;IACf;IAEAA,MAAM,CAAC/B,GAAG,GAAG,EAAE;IAEf+B,MAAM,CAAChC,GAAG,GAAG,EAAE;IACf,MAAMwC,UAAU,GAAGrH,MAAM,CAACsH,QAAQ,CAAC,CAAC,EAAE5C,IAAI,CAAC;IAC3C,KAAK,MAAMwC,KAAK,IAAIG,UAAU,EAAE;MAE9BR,MAAM,CAAC/B,GAAG,CAACrD,IAAI,CAACyF,KAAK,CAAC;MAEtBL,MAAM,CAAChC,GAAG,CAACpD,IAAI,CAACyF,KAAK,CAAC;IACxB;IAEA,KAAK,IAAIpI,KAAK,GAAG4F,IAAI,EAAE5F,KAAK,GAAGkB,MAAM,CAACQ,MAAM,EAAE1B,KAAK,IAAI4F,IAAI,EAAE;MAC3D,KAAK,IAAI6C,cAAc,GAAG,CAAC,EAAEA,cAAc,GAAG7C,IAAI,EAAE6C,cAAc,EAAE,EAAE;QAEpEV,MAAM,CAAC/B,GAAG,CAAC,CAAC,GAAGyC,cAAc,CAAC,GAAGnC,IAAI,CAACN,GAAG,CAEvC+B,MAAM,CAAC/B,GAAG,CAAC,CAAC,GAAGyC,cAAc,CAAC,EAC9BvH,MAAM,CAAClB,KAAK,GAAGyI,cAAc,CAC/B,CAAC;QAEDV,MAAM,CAAChC,GAAG,CAAC,CAAC,GAAG0C,cAAc,CAAC,GAAGnC,IAAI,CAACP,GAAG,CAEvCgC,MAAM,CAAChC,GAAG,CAAC,CAAC,GAAG0C,cAAc,CAAC,EAC9BvH,MAAM,CAAClB,KAAK,GAAGyI,cAAc,CAC/B,CAAC;MACH;IACF;IACA,OAAOV,MAAM;EACf;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-gltf-v1.js","names":["KHR_binary_glTF","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","constructor","_defineProperty","normalize","gltf","options","json","asset","version","undefined","console","warn","concat","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","_material$values","_material$values2","_material$values3","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","texture2d_0","diffuseTex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1","arguments"],"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"mappings":";AACA,OAAO,KAAKA,eAAe,MAAM,+BAA+B;AA+ChE,MAAMC,WAAW,GAAG;EAClBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,OAAO,EAAE,QAAQ;EACjBC,WAAW,EAAE,YAAY;EACzBC,MAAM,EAAE,OAAO;EACfC,SAAS,EAAE,UAAU;EACrBC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE,MAAM;EACbC,QAAQ,EAAE,SAAS;EACnBC,MAAM,EAAE,OAAO;EACfC,KAAK,EA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E,CAAC,CAAC;QAC7BC,cAAc,EAAE,CAAC;QACjBC,eAAe,EAAE;MACnB,CAAC;MAED,MAAMC,SAAS,GACb,EAAAP,gBAAA,GAAA5D,QAAQ,CAACoE,MAAM,cAAAR,gBAAA,uBAAfA,gBAAA,CAAiBS,GAAG,OAAAR,iBAAA,GAAI7D,QAAQ,CAACoE,MAAM,cAAAP,iBAAA,uBAAfA,iBAAA,CAAiBS,WAAW,OAAAR,iBAAA,GAAI9D,QAAQ,CAACoE,MAAM,cAAAN,iBAAA,uBAAfA,iBAAA,CAAiBS,UAAU;MACrF,MAAMC,YAAY,GAAG3D,IAAI,CAACnB,QAAQ,CAAC+E,SAAS,CAAEnE,OAAO,IAAKA,OAAO,CAAC4B,EAAE,KAAKiC,SAAS,CAAC;MACnF,IAAIK,YAAY,KAAK,CAAC,CAAC,EAAE;QACvBxE,QAAQ,CAAC+D,oBAAoB,CAACW,gBAAgB,GAAG;UAACtC,KAAK,EAAEoC;QAAY,CAAC;MACxE;IACF;EACF;AACF;AAEA,OAAO,SAASG,eAAeA,CAAChE,IAAI,EAAgB;EAAA,IAAdC,OAAO,GAAAgE,SAAA,CAAAvC,MAAA,QAAAuC,SAAA,QAAA5D,SAAA,GAAA4D,SAAA,MAAG,CAAC,CAAC;EAChD,OAAO,IAAIrE,gBAAgB,EAAE,CAACG,SAAS,CAACC,IAAI,EAAEC,OAAO,CAAC;AACxD"}
|
|
1
|
+
{"version":3,"file":"normalize-gltf-v1.js","names":["KHR_binary_glTF","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","constructor","_defineProperty","normalize","gltf","options","json","asset","version","undefined","console","warn","concat","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","_material$values","_material$values2","_material$values3","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","texture2d_0","diffuseTex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1","arguments"],"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"mappings":";AACA,OAAO,KAAKA,eAAe,MAAM,+BAA+B;AA+ChE,MAAMC,WAAW,GAAG;EAClBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,OAAO,EAAE,QAAQ;EACjBC,WAAW,EAAE,YAAY;EACzBC,MAAM,EAAE,OAAO;EACfC,SAAS,EAAE,UAAU;EACrBC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE,MAAM;EACbC,QAAQ,EAAE,SAAS;EACnBC,MAAM,EAAE,OAAO;EACfC,KAAK,EAAE,MAAM;EACbC,QAAQ,EAAE;AACZ,CAAC;AAED,MAAMC,SAAS,GAAG;EAChBC,QAAQ,EAAE,WAAW;EACrBZ,UAAU,EAAE,WAAW;EACvBa,MAAM,EAAE,SAAS;EACjBC,UAAU,EAAE,aAAa;EACzBC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AfA,gBAAA,CAAiBS,GAAG,OAAAR,iBAAA,GAAI7D,QAAQ,CAACoE,MAAM,cAAAP,iBAAA,uBAAfA,iBAAA,CAAiBS,WAAW,OAAAR,iBAAA,GAAI9D,QAAQ,CAACoE,MAAM,cAAAN,iBAAA,uBAAfA,iBAAA,CAAiBS,UAAU;MACrF,MAAMC,YAAY,GAAG3D,IAAI,CAACnB,QAAQ,CAAC+E,SAAS,CAAEnE,OAAO,IAAKA,OAAO,CAAC4B,EAAE,KAAKiC,SAAS,CAAC;MACnF,IAAIK,YAAY,KAAK,CAAC,CAAC,EAAE;QACvBxE,QAAQ,CAAC+D,oBAAoB,CAACW,gBAAgB,GAAG;UAACtC,KAAK,EAAEoC;QAAY,CAAC;MACxE;IACF;EACF;AACF;AAEA,OAAO,SAASG,eAAeA,CAAChE,IAAI,EAAgB;EAAA,IAAdC,OAAO,GAAAgE,SAAA,CAAAvC,MAAA,QAAAuC,SAAA,QAAA5D,SAAA,GAAA4D,SAAA,MAAG,CAAC,CAAC;EAChD,OAAO,IAAIrE,gBAAgB,CAAC,CAAC,CAACG,SAAS,CAACC,IAAI,EAAEC,OAAO,CAAC;AACxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-process-gltf.js","names":["assert","getAccessorArrayTypeAndLength","COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BYTES","GL_SAMPLER","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","REPEAT","LINEAR","NEAREST_MIPMAP_LINEAR","SAMPLER_PARAMETER_GLTF_TO_GL","magFilter","minFilter","wrapS","wrapT","DEFAULT_SAMPLER","getBytesFromComponentType","componentType","getSizeFromAccessorType","type","GLTFPostProcessor","constructor","_defineProperty","postProcess","gltf","options","arguments","length","undefined","json","buffers","images","baseUri","_resolveTree","bufferViews","map","bufView","i","_resolveBufferView","image","_resolveImage","samplers","sampler","_resolveSampler","textures","texture","_resolveTexture","accessors","accessor","_resolveAccessor","materials","material","_resolveMaterial","meshes","mesh","_resolveMesh","nodes","node","_resolveNode","skins","skin","_resolveSkin","scenes","scene","_resolveScene","getScene","index","_get","getNode","getSkin","getMesh","getMaterial","getAccessor","getCamera","getTexture","getSampler","getImage","getBufferView","getBuffer","array","object","console","warn","concat","id","children","child","reduce","accum","meshIndex","primitives","camera","inverseBindMatrices","primitive","attributes","attribute","indices","normalTexture","occlusionTexture","occlustionTexture","emissiveTexture","emmisiveTexture","emissiveFactor","pbrMetallicRoughness","mr","baseColorTexture","metallicRoughnessTexture","bufferView","bytesPerComponent","components","bytesPerElement","buffer","ArrayType","byteLength","byteOffset","cutBuffer","arrayBuffer","slice","byteStride","_getValueFromInterleavedBuffer","count","value","result","Uint8Array","elementOffset","set","source","parameters","key","glEnum","_enumSamplerParameter","preloadedImage","bufferIndex","data","_resolveCamera","perspective","orthographic","postProcessGLTF"],"sources":["../../../../src/lib/api/post-process-gltf.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BufferView} from '../types/gltf-json-schema';\nimport {BufferView as BufferViewPostprocessed} from '../types/gltf-postprocessed-schema';\n\n// This is a post processor for loaded glTF files\n// The goal is to make the loaded data easier to use in WebGL applications\n//\n// Functions:\n// * Resolve indexed arrays structure of glTF into a linked tree.\n// * Translate stringified enum keys and values into WebGL constants.\n// * Load images (optional)\n\n// ENUM LOOKUP\n\nconst COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst BYTES = {\n 5120: 1, // BYTE\n 5121: 1, // UNSIGNED_BYTE\n 5122: 2, // SHORT\n 5123: 2, // UNSIGNED_SHORT\n 5125: 4, // UNSIGNED_INT\n 5126: 4 // FLOAT\n};\n\nconst GL_SAMPLER = {\n // Sampler parameters\n TEXTURE_MAG_FILTER: 0x2800,\n TEXTURE_MIN_FILTER: 0x2801,\n TEXTURE_WRAP_S: 0x2802,\n TEXTURE_WRAP_T: 0x2803,\n\n // Sampler default values\n REPEAT: 0x2901,\n LINEAR: 0x2601,\n NEAREST_MIPMAP_LINEAR: 0x2702\n};\n\nconst SAMPLER_PARAMETER_GLTF_TO_GL = {\n magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,\n minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,\n wrapS: GL_SAMPLER.TEXTURE_WRAP_S,\n wrapT: GL_SAMPLER.TEXTURE_WRAP_T\n};\n\n// When undefined, a sampler with repeat wrapping and auto filtering should be used.\n// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\nconst DEFAULT_SAMPLER = {\n [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,\n [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,\n [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,\n [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT\n};\n\nfunction getBytesFromComponentType(componentType) {\n return BYTES[componentType];\n}\n\nfunction getSizeFromAccessorType(type) {\n return COMPONENTS[type];\n}\n\nclass GLTFPostProcessor {\n baseUri: string = '';\n json: Record<string, any> = {};\n buffers: [] = [];\n images: [] = [];\n\n postProcess(gltf, options = {}) {\n const {json, buffers = [], images = [], baseUri = ''} = gltf;\n assert(json);\n\n this.baseUri = baseUri;\n this.json = json;\n this.buffers = buffers;\n this.images = images;\n\n this._resolveTree(this.json, options);\n\n return this.json;\n }\n\n // Convert indexed glTF structure into tree structure\n // cross-link index resolution, enum lookup, convenience calculations\n // eslint-disable-next-line complexity\n _resolveTree(json, options = {}) {\n if (json.bufferViews) {\n json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));\n }\n if (json.images) {\n json.images = json.images.map((image, i) => this._resolveImage(image, i));\n }\n if (json.samplers) {\n json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));\n }\n if (json.textures) {\n json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));\n }\n if (json.accessors) {\n json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));\n }\n if (json.materials) {\n json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));\n }\n if (json.meshes) {\n json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));\n }\n if (json.nodes) {\n json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));\n }\n if (json.skins) {\n json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));\n }\n if (json.scenes) {\n json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));\n }\n if (json.scene !== undefined) {\n json.scene = json.scenes[this.json.scene];\n }\n }\n\n getScene(index) {\n return this._get('scenes', index);\n }\n\n getNode(index) {\n return this._get('nodes', index);\n }\n\n getSkin(index) {\n return this._get('skins', index);\n }\n\n getMesh(index) {\n return this._get('meshes', index);\n }\n\n getMaterial(index) {\n return this._get('materials', index);\n }\n\n getAccessor(index) {\n return this._get('accessors', index);\n }\n\n getCamera(index) {\n return null; // TODO: fix this\n }\n\n getTexture(index) {\n return this._get('textures', index);\n }\n\n getSampler(index) {\n return this._get('samplers', index);\n }\n\n getImage(index) {\n return this._get('images', index);\n }\n\n getBufferView(index) {\n return this._get('bufferViews', index);\n }\n\n getBuffer(index) {\n return this._get('buffers', index);\n }\n\n _get(array, index) {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = this.json[array] && this.json[array][index];\n if (!object) {\n console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object;\n }\n\n // PARSING HELPERS\n\n _resolveScene(scene, index) {\n // scene = {...scene};\n scene.id = scene.id || `scene-${index}`;\n scene.nodes = (scene.nodes || []).map((node) => this.getNode(node));\n return scene;\n }\n\n _resolveNode(node, index) {\n // node = {...node};\n node.id = node.id || `node-${index}`;\n if (node.children) {\n node.children = node.children.map((child) => this.getNode(child));\n }\n if (node.mesh !== undefined) {\n node.mesh = this.getMesh(node.mesh);\n } else if (node.meshes !== undefined && node.meshes.length) {\n node.mesh = node.meshes.reduce(\n (accum, meshIndex) => {\n const mesh = this.getMesh(meshIndex);\n accum.id = mesh.id;\n accum.primitives = accum.primitives.concat(mesh.primitives);\n return accum;\n },\n {primitives: []}\n );\n }\n if (node.camera !== undefined) {\n node.camera = this.getCamera(node.camera);\n }\n if (node.skin !== undefined) {\n node.skin = this.getSkin(node.skin);\n }\n return node;\n }\n\n _resolveSkin(skin, index) {\n // skin = {...skin};\n skin.id = skin.id || `skin-${index}`;\n skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);\n return skin;\n }\n\n _resolveMesh(mesh, index) {\n // mesh = {...mesh};\n mesh.id = mesh.id || `mesh-${index}`;\n if (mesh.primitives) {\n mesh.primitives = mesh.primitives.map((primitive) => {\n primitive = {...primitive};\n const attributes = primitive.attributes;\n primitive.attributes = {};\n for (const attribute in attributes) {\n primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);\n }\n if (primitive.indices !== undefined) {\n primitive.indices = this.getAccessor(primitive.indices);\n }\n if (primitive.material !== undefined) {\n primitive.material = this.getMaterial(primitive.material);\n }\n return primitive;\n });\n }\n return mesh;\n }\n\n _resolveMaterial(material, index) {\n // material = {...material};\n material.id = material.id || `material-${index}`;\n if (material.normalTexture) {\n material.normalTexture = {...material.normalTexture};\n material.normalTexture.texture = this.getTexture(material.normalTexture.index);\n }\n if (material.occlusionTexture) {\n material.occlustionTexture = {...material.occlustionTexture};\n material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);\n }\n if (material.emissiveTexture) {\n material.emmisiveTexture = {...material.emmisiveTexture};\n material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);\n }\n if (!material.emissiveFactor) {\n material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];\n }\n\n if (material.pbrMetallicRoughness) {\n material.pbrMetallicRoughness = {...material.pbrMetallicRoughness};\n const mr = material.pbrMetallicRoughness;\n if (mr.baseColorTexture) {\n mr.baseColorTexture = {...mr.baseColorTexture};\n mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);\n }\n if (mr.metallicRoughnessTexture) {\n mr.metallicRoughnessTexture = {...mr.metallicRoughnessTexture};\n mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);\n }\n }\n return material;\n }\n\n _resolveAccessor(accessor, index) {\n // accessor = {...accessor};\n accessor.id = accessor.id || `accessor-${index}`;\n if (accessor.bufferView !== undefined) {\n // Draco encoded meshes don't have bufferView\n accessor.bufferView = this.getBufferView(accessor.bufferView);\n }\n\n // Look up enums\n accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);\n accessor.components = getSizeFromAccessorType(accessor.type);\n accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;\n\n // Create TypedArray for the accessor\n // Note: The canonical way to instantiate is to ignore this array and create\n // WebGLBuffer's using the bufferViews.\n if (accessor.bufferView) {\n const buffer = accessor.bufferView.buffer;\n const {ArrayType, byteLength} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);\n const byteOffset =\n (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;\n let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);\n if (accessor.bufferView.byteStride) {\n cutBuffer = this._getValueFromInterleavedBuffer(\n buffer,\n byteOffset,\n accessor.bufferView.byteStride,\n accessor.bytesPerElement,\n accessor.count\n );\n }\n accessor.value = new ArrayType(cutBuffer);\n }\n\n return accessor;\n }\n\n /**\n * Take values of particular accessor from interleaved buffer\n * various parts of the buffer\n * @param buffer\n * @param byteOffset\n * @param byteStride\n * @param bytesPerElement\n * @param count\n * @returns\n */\n _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {\n const result = new Uint8Array(count * bytesPerElement);\n for (let i = 0; i < count; i++) {\n const elementOffset = byteOffset + i * byteStride;\n result.set(\n new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)),\n i * bytesPerElement\n );\n }\n return result.buffer;\n }\n\n _resolveTexture(texture, index) {\n // texture = {...texture};\n texture.id = texture.id || `texture-${index}`;\n texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;\n texture.source = this.getImage(texture.source);\n return texture;\n }\n\n _resolveSampler(sampler, index) {\n // sampler = {...sampler};\n sampler.id = sampler.id || `sampler-${index}`;\n // Map textual parameters to GL parameter values\n sampler.parameters = {};\n for (const key in sampler) {\n const glEnum = this._enumSamplerParameter(key);\n if (glEnum !== undefined) {\n sampler.parameters[glEnum] = sampler[key];\n }\n }\n return sampler;\n }\n\n _enumSamplerParameter(key) {\n return SAMPLER_PARAMETER_GLTF_TO_GL[key];\n }\n\n _resolveImage(image, index) {\n // image = {...image};\n image.id = image.id || `image-${index}`;\n if (image.bufferView !== undefined) {\n image.bufferView = this.getBufferView(image.bufferView);\n }\n\n // Check if image has been preloaded by the GLTFLoader\n // If so, link it into the JSON and drop the URI\n const preloadedImage = this.images[index];\n if (preloadedImage) {\n image.image = preloadedImage;\n }\n\n return image;\n }\n\n _resolveBufferView(bufferView: BufferView, index: number): BufferViewPostprocessed {\n // bufferView = {...bufferView};\n const bufferIndex = bufferView.buffer;\n const result: BufferViewPostprocessed = {\n id: `bufferView-${index}`,\n ...bufferView,\n buffer: this.buffers[bufferIndex]\n };\n\n // @ts-expect-error\n const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;\n // @ts-expect-error\n let byteOffset = this.buffers[bufferIndex].byteOffset || 0;\n\n if ('byteOffset' in bufferView) {\n byteOffset += bufferView.byteOffset;\n }\n\n result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);\n return result;\n }\n\n _resolveCamera(camera, index) {\n camera.id = camera.id || `camera-${index}`;\n // TODO - create 4x4 matrices\n if (camera.perspective) {\n // camera.matrix = createPerspectiveMatrix(camera.perspective);\n }\n if (camera.orthographic) {\n // camera.matrix = createOrthographicMatrix(camera.orthographic);\n }\n return camera;\n }\n}\n\nexport function postProcessGLTF(gltf, options?) {\n return new GLTFPostProcessor().postProcess(gltf, options);\n}\n"],"mappings":";AAAA,SAAQA,MAAM,QAAO,iBAAiB;AACtC,SAAQC,6BAA6B,QAAO,0BAA0B;AActE,MAAMC,UAAU,GAAG;EACjBC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,KAAK,GAAG;EACZ,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,UAAU,GAAG;EAEjBC,kBAAkB,EAAE,MAAM;EAC1BC,kBAAkB,EAAE,MAAM;EAC1BC,cAAc,EAAE,MAAM;EACtBC,cAAc,EAAE,MAAM;EAGtBC,MAAM,EAAE,MAAM;EACdC,MAAM,EAAE,MAAM;EACdC,qBAAqB,EAAE;AACzB,CAAC;AAED,MAAMC,4BAA4B,GAAG;EACnCC,SAAS,EAAET,UAAU,CAACC,kBAAkB;EACxCS,SAAS,EAAEV,UAAU,CAACE,kBAAkB;EACxCS,KAAK,EAAEX,UAAU,CAACG,cAAc;EAChCS,KAAK,EAAEZ,UAAU,CAACI;AACpB,CAAC;AAID,MAAMS,eAAe,GAAG;EACtB,CAACb,UAAU,CAACC,kBAAkB,GAAGD,UAAU,CAACM,MAAM;EAClD,CAACN,UAAU,CAACE,kBAAkB,GAAGF,UAAU,CAACO,qBAAqB;EACjE,CAACP,UAAU,CAACG,cAAc,GAAGH,UAAU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AAQ,EAAE;EAC9C,OAAO,IAAIL,iBAAiB,EAAE,CAACG,WAAW,CAACC,IAAI,EAAEC,OAAO,CAAC;AAC3D"}
|
|
1
|
+
{"version":3,"file":"post-process-gltf.js","names":["assert","getAccessorArrayTypeAndLength","COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BYTES","GL_SAMPLER","TEXTURE_MAG_FILTER","TEXTURE_MIN_FILTER","TEXTURE_WRAP_S","TEXTURE_WRAP_T","REPEAT","LINEAR","NEAREST_MIPMAP_LINEAR","SAMPLER_PARAMETER_GLTF_TO_GL","magFilter","minFilter","wrapS","wrapT","DEFAULT_SAMPLER","getBytesFromComponentType","componentType","getSizeFromAccessorType","type","GLTFPostProcessor","constructor","_defineProperty","postProcess","gltf","options","arguments","length","undefined","json","buffers","images","baseUri","_resolveTree","bufferViews","map","bufView","i","_resolveBufferView","image","_resolveImage","samplers","sampler","_resolveSampler","textures","texture","_resolveTexture","accessors","accessor","_resolveAccessor","materials","material","_resolveMaterial","meshes","mesh","_resolveMesh","nodes","node","_resolveNode","skins","skin","_resolveSkin","scenes","scene","_resolveScene","getScene","index","_get","getNode","getSkin","getMesh","getMaterial","getAccessor","getCamera","getTexture","getSampler","getImage","getBufferView","getBuffer","array","object","console","warn","concat","id","children","child","reduce","accum","meshIndex","primitives","camera","inverseBindMatrices","primitive","attributes","attribute","indices","normalTexture","occlusionTexture","occlustionTexture","emissiveTexture","emmisiveTexture","emissiveFactor","pbrMetallicRoughness","mr","baseColorTexture","metallicRoughnessTexture","bufferView","bytesPerComponent","components","bytesPerElement","buffer","ArrayType","byteLength","byteOffset","cutBuffer","arrayBuffer","slice","byteStride","_getValueFromInterleavedBuffer","count","value","result","Uint8Array","elementOffset","set","source","parameters","key","glEnum","_enumSamplerParameter","preloadedImage","bufferIndex","data","_resolveCamera","perspective","orthographic","postProcessGLTF"],"sources":["../../../../src/lib/api/post-process-gltf.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';\nimport {BufferView} from '../types/gltf-json-schema';\nimport {BufferView as BufferViewPostprocessed} from '../types/gltf-postprocessed-schema';\n\n// This is a post processor for loaded glTF files\n// The goal is to make the loaded data easier to use in WebGL applications\n//\n// Functions:\n// * Resolve indexed arrays structure of glTF into a linked tree.\n// * Translate stringified enum keys and values into WebGL constants.\n// * Load images (optional)\n\n// ENUM LOOKUP\n\nconst COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst BYTES = {\n 5120: 1, // BYTE\n 5121: 1, // UNSIGNED_BYTE\n 5122: 2, // SHORT\n 5123: 2, // UNSIGNED_SHORT\n 5125: 4, // UNSIGNED_INT\n 5126: 4 // FLOAT\n};\n\nconst GL_SAMPLER = {\n // Sampler parameters\n TEXTURE_MAG_FILTER: 0x2800,\n TEXTURE_MIN_FILTER: 0x2801,\n TEXTURE_WRAP_S: 0x2802,\n TEXTURE_WRAP_T: 0x2803,\n\n // Sampler default values\n REPEAT: 0x2901,\n LINEAR: 0x2601,\n NEAREST_MIPMAP_LINEAR: 0x2702\n};\n\nconst SAMPLER_PARAMETER_GLTF_TO_GL = {\n magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,\n minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,\n wrapS: GL_SAMPLER.TEXTURE_WRAP_S,\n wrapT: GL_SAMPLER.TEXTURE_WRAP_T\n};\n\n// When undefined, a sampler with repeat wrapping and auto filtering should be used.\n// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture\nconst DEFAULT_SAMPLER = {\n [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,\n [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,\n [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,\n [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT\n};\n\nfunction getBytesFromComponentType(componentType) {\n return BYTES[componentType];\n}\n\nfunction getSizeFromAccessorType(type) {\n return COMPONENTS[type];\n}\n\nclass GLTFPostProcessor {\n baseUri: string = '';\n json: Record<string, any> = {};\n buffers: [] = [];\n images: [] = [];\n\n postProcess(gltf, options = {}) {\n const {json, buffers = [], images = [], baseUri = ''} = gltf;\n assert(json);\n\n this.baseUri = baseUri;\n this.json = json;\n this.buffers = buffers;\n this.images = images;\n\n this._resolveTree(this.json, options);\n\n return this.json;\n }\n\n // Convert indexed glTF structure into tree structure\n // cross-link index resolution, enum lookup, convenience calculations\n // eslint-disable-next-line complexity\n _resolveTree(json, options = {}) {\n if (json.bufferViews) {\n json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));\n }\n if (json.images) {\n json.images = json.images.map((image, i) => this._resolveImage(image, i));\n }\n if (json.samplers) {\n json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));\n }\n if (json.textures) {\n json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));\n }\n if (json.accessors) {\n json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));\n }\n if (json.materials) {\n json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));\n }\n if (json.meshes) {\n json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));\n }\n if (json.nodes) {\n json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));\n }\n if (json.skins) {\n json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));\n }\n if (json.scenes) {\n json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));\n }\n if (json.scene !== undefined) {\n json.scene = json.scenes[this.json.scene];\n }\n }\n\n getScene(index) {\n return this._get('scenes', index);\n }\n\n getNode(index) {\n return this._get('nodes', index);\n }\n\n getSkin(index) {\n return this._get('skins', index);\n }\n\n getMesh(index) {\n return this._get('meshes', index);\n }\n\n getMaterial(index) {\n return this._get('materials', index);\n }\n\n getAccessor(index) {\n return this._get('accessors', index);\n }\n\n getCamera(index) {\n return null; // TODO: fix this\n }\n\n getTexture(index) {\n return this._get('textures', index);\n }\n\n getSampler(index) {\n return this._get('samplers', index);\n }\n\n getImage(index) {\n return this._get('images', index);\n }\n\n getBufferView(index) {\n return this._get('bufferViews', index);\n }\n\n getBuffer(index) {\n return this._get('buffers', index);\n }\n\n _get(array, index) {\n // check if already resolved\n if (typeof index === 'object') {\n return index;\n }\n const object = this.json[array] && this.json[array][index];\n if (!object) {\n console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line\n }\n return object;\n }\n\n // PARSING HELPERS\n\n _resolveScene(scene, index) {\n // scene = {...scene};\n scene.id = scene.id || `scene-${index}`;\n scene.nodes = (scene.nodes || []).map((node) => this.getNode(node));\n return scene;\n }\n\n _resolveNode(node, index) {\n // node = {...node};\n node.id = node.id || `node-${index}`;\n if (node.children) {\n node.children = node.children.map((child) => this.getNode(child));\n }\n if (node.mesh !== undefined) {\n node.mesh = this.getMesh(node.mesh);\n } else if (node.meshes !== undefined && node.meshes.length) {\n node.mesh = node.meshes.reduce(\n (accum, meshIndex) => {\n const mesh = this.getMesh(meshIndex);\n accum.id = mesh.id;\n accum.primitives = accum.primitives.concat(mesh.primitives);\n return accum;\n },\n {primitives: []}\n );\n }\n if (node.camera !== undefined) {\n node.camera = this.getCamera(node.camera);\n }\n if (node.skin !== undefined) {\n node.skin = this.getSkin(node.skin);\n }\n return node;\n }\n\n _resolveSkin(skin, index) {\n // skin = {...skin};\n skin.id = skin.id || `skin-${index}`;\n skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);\n return skin;\n }\n\n _resolveMesh(mesh, index) {\n // mesh = {...mesh};\n mesh.id = mesh.id || `mesh-${index}`;\n if (mesh.primitives) {\n mesh.primitives = mesh.primitives.map((primitive) => {\n primitive = {...primitive};\n const attributes = primitive.attributes;\n primitive.attributes = {};\n for (const attribute in attributes) {\n primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);\n }\n if (primitive.indices !== undefined) {\n primitive.indices = this.getAccessor(primitive.indices);\n }\n if (primitive.material !== undefined) {\n primitive.material = this.getMaterial(primitive.material);\n }\n return primitive;\n });\n }\n return mesh;\n }\n\n _resolveMaterial(material, index) {\n // material = {...material};\n material.id = material.id || `material-${index}`;\n if (material.normalTexture) {\n material.normalTexture = {...material.normalTexture};\n material.normalTexture.texture = this.getTexture(material.normalTexture.index);\n }\n if (material.occlusionTexture) {\n material.occlustionTexture = {...material.occlustionTexture};\n material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);\n }\n if (material.emissiveTexture) {\n material.emmisiveTexture = {...material.emmisiveTexture};\n material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);\n }\n if (!material.emissiveFactor) {\n material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];\n }\n\n if (material.pbrMetallicRoughness) {\n material.pbrMetallicRoughness = {...material.pbrMetallicRoughness};\n const mr = material.pbrMetallicRoughness;\n if (mr.baseColorTexture) {\n mr.baseColorTexture = {...mr.baseColorTexture};\n mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);\n }\n if (mr.metallicRoughnessTexture) {\n mr.metallicRoughnessTexture = {...mr.metallicRoughnessTexture};\n mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);\n }\n }\n return material;\n }\n\n _resolveAccessor(accessor, index) {\n // accessor = {...accessor};\n accessor.id = accessor.id || `accessor-${index}`;\n if (accessor.bufferView !== undefined) {\n // Draco encoded meshes don't have bufferView\n accessor.bufferView = this.getBufferView(accessor.bufferView);\n }\n\n // Look up enums\n accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);\n accessor.components = getSizeFromAccessorType(accessor.type);\n accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;\n\n // Create TypedArray for the accessor\n // Note: The canonical way to instantiate is to ignore this array and create\n // WebGLBuffer's using the bufferViews.\n if (accessor.bufferView) {\n const buffer = accessor.bufferView.buffer;\n const {ArrayType, byteLength} = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);\n const byteOffset =\n (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;\n let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);\n if (accessor.bufferView.byteStride) {\n cutBuffer = this._getValueFromInterleavedBuffer(\n buffer,\n byteOffset,\n accessor.bufferView.byteStride,\n accessor.bytesPerElement,\n accessor.count\n );\n }\n accessor.value = new ArrayType(cutBuffer);\n }\n\n return accessor;\n }\n\n /**\n * Take values of particular accessor from interleaved buffer\n * various parts of the buffer\n * @param buffer\n * @param byteOffset\n * @param byteStride\n * @param bytesPerElement\n * @param count\n * @returns\n */\n _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {\n const result = new Uint8Array(count * bytesPerElement);\n for (let i = 0; i < count; i++) {\n const elementOffset = byteOffset + i * byteStride;\n result.set(\n new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)),\n i * bytesPerElement\n );\n }\n return result.buffer;\n }\n\n _resolveTexture(texture, index) {\n // texture = {...texture};\n texture.id = texture.id || `texture-${index}`;\n texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;\n texture.source = this.getImage(texture.source);\n return texture;\n }\n\n _resolveSampler(sampler, index) {\n // sampler = {...sampler};\n sampler.id = sampler.id || `sampler-${index}`;\n // Map textual parameters to GL parameter values\n sampler.parameters = {};\n for (const key in sampler) {\n const glEnum = this._enumSamplerParameter(key);\n if (glEnum !== undefined) {\n sampler.parameters[glEnum] = sampler[key];\n }\n }\n return sampler;\n }\n\n _enumSamplerParameter(key) {\n return SAMPLER_PARAMETER_GLTF_TO_GL[key];\n }\n\n _resolveImage(image, index) {\n // image = {...image};\n image.id = image.id || `image-${index}`;\n if (image.bufferView !== undefined) {\n image.bufferView = this.getBufferView(image.bufferView);\n }\n\n // Check if image has been preloaded by the GLTFLoader\n // If so, link it into the JSON and drop the URI\n const preloadedImage = this.images[index];\n if (preloadedImage) {\n image.image = preloadedImage;\n }\n\n return image;\n }\n\n _resolveBufferView(bufferView: BufferView, index: number): BufferViewPostprocessed {\n // bufferView = {...bufferView};\n const bufferIndex = bufferView.buffer;\n const result: BufferViewPostprocessed = {\n id: `bufferView-${index}`,\n ...bufferView,\n buffer: this.buffers[bufferIndex]\n };\n\n // @ts-expect-error\n const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;\n // @ts-expect-error\n let byteOffset = this.buffers[bufferIndex].byteOffset || 0;\n\n if ('byteOffset' in bufferView) {\n byteOffset += bufferView.byteOffset;\n }\n\n result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);\n return result;\n }\n\n _resolveCamera(camera, index) {\n camera.id = camera.id || `camera-${index}`;\n // TODO - create 4x4 matrices\n if (camera.perspective) {\n // camera.matrix = createPerspectiveMatrix(camera.perspective);\n }\n if (camera.orthographic) {\n // camera.matrix = createOrthographicMatrix(camera.orthographic);\n }\n return camera;\n }\n}\n\nexport function postProcessGLTF(gltf, options?) {\n return new GLTFPostProcessor().postProcess(gltf, options);\n}\n"],"mappings":";AAAA,SAAQA,MAAM,QAAO,iBAAiB;AACtC,SAAQC,6BAA6B,QAAO,0BAA0B;AActE,MAAMC,UAAU,GAAG;EACjBC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,KAAK,GAAG;EACZ,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE,CAAC;EACP,IAAI,EAAE;AACR,CAAC;AAED,MA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AAG,IAAI,CAACpF,OAAO,CAACsG,WAAW,CAAC,CAAClB,UAAU,IAAI,CAAC;IAE1D,IAAI,YAAY,IAAIP,UAAU,EAAE;MAC9BO,UAAU,IAAIP,UAAU,CAACO,UAAU;IACrC;IAEAQ,MAAM,CAACW,IAAI,GAAG,IAAIV,UAAU,CAACP,WAAW,EAAEF,UAAU,EAAEP,UAAU,CAACM,UAAU,CAAC;IAC5E,OAAOS,MAAM;EACf;EAEAY,cAAcA,CAAC3C,MAAM,EAAEzB,KAAK,EAAE;IAC5ByB,MAAM,CAACP,EAAE,GAAGO,MAAM,CAACP,EAAE,cAAAD,MAAA,CAAcjB,KAAK,CAAE;IAE1C,IAAIyB,MAAM,CAAC4C,WAAW,EAAE,CAExB;IACA,IAAI5C,MAAM,CAAC6C,YAAY,EAAE,CAEzB;IACA,OAAO7C,MAAM;EACf;AACF;AAEA,OAAO,SAAS8C,eAAeA,CAACjH,IAAI,EAAEC,OAAQ,EAAE;EAC9C,OAAO,IAAIL,iBAAiB,CAAC,CAAC,CAACG,WAAW,CAACC,IAAI,EAAEC,OAAO,CAAC;AAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_meshopt_compression.js","names":["GLTFScenegraph","meshoptDecodeGltfBuffer","DEFAULT_MESHOPT_OPTIONS","byteOffset","filter","EXT_MESHOPT_COMPRESSION","name","decode","gltfData","options","_options$gltf","scenegraph","gltf","decompressMeshes","promises","bufferViewIndex","json","bufferViews","push","decodeMeshoptBufferView","Promise","all","removeExtension","bufferView","meshoptExtension","getObjectExtension","byteLength","byteStride","count","mode","buffer","bufferIndex","buffers","source","Uint8Array","arrayBuffer","result"],"sources":["../../../../src/lib/extensions/EXT_meshopt_compression.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\nimport {meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';\n\n// @ts-ignore\n// eslint-disable-next-line\nconst DEFAULT_MESHOPT_OPTIONS = {\n byteOffset: 0,\n filter: 'NONE'\n};\n\n/** Extension name */\nconst EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';\n\nexport const name = EXT_MESHOPT_COMPRESSION;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const promises: Promise<any>[] = [];\n for (const bufferViewIndex of gltfData.json.bufferViews || []) {\n promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);\n}\n\n/** Decode one meshopt buffer view */\nasync function decodeMeshoptBufferView(\n scenegraph: GLTFScenegraph,\n bufferView: GLTFBufferView\n): Promise<ArrayBuffer | null> {\n const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(\n bufferView,\n EXT_MESHOPT_COMPRESSION\n );\n if (meshoptExtension) {\n const {\n byteOffset = 0,\n byteLength = 0,\n byteStride,\n count,\n mode,\n filter = 'NONE',\n buffer: bufferIndex\n } = meshoptExtension;\n const buffer = scenegraph.gltf.buffers[bufferIndex];\n\n const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);\n const result = new Uint8Array(\n scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,\n bufferView.byteOffset,\n bufferView.byteLength\n );\n await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);\n return result;\n }\n\n return null;\n}\n"],"mappings":"AAGA,OAAOA,cAAc,MAAM,wBAAwB;AACnD,SAAQC,uBAAuB,QAAO,+BAA+B;AAIrE,MAAMC,uBAAuB,GAAG;EAC9BC,UAAU,EAAE,CAAC;EACbC,MAAM,EAAE;AACV,CAAC;AAGD,MAAMC,uBAAuB,GAAG,yBAAyB;AAEzD,OAAO,MAAMC,IAAI,GAAGD,uBAAuB;AAE3C,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAE;EAAA,IAAAC,aAAA;EAC/E,MAAMC,UAAU,GAAG,IAAIX,cAAc,CAACQ,QAAQ,CAAC;EAE/C,IAAI,EAACC,OAAO,aAAPA,OAAO,gBAAAC,aAAA,GAAPD,OAAO,CAAEG,IAAI,cAAAF,aAAA,eAAbA,aAAA,CAAeG,gBAAgB,GAAE;IACpC;EACF;EAEA,MAAMC,QAAwB,GAAG,EAAE;EACnC,KAAK,MAAMC,eAAe,IAAIP,QAAQ,CAACQ,IAAI,CAACC,WAAW,IAAI,EAAE,EAAE;IAC7DH,QAAQ,CAACI,IAAI,CAACC,uBAAuB,CAACR,UAAU,EAAEI,eAAe,CAAC,CAAC;EACrE;EAGA,MAAMK,OAAO,CAACC,GAAG,CAACP,QAAQ,CAAC;EAG3BH,UAAU,CAACW,eAAe,CAACjB,uBAAuB,CAAC;AACrD;AAGA,eAAec,uBAAuBA,CACpCR,UAA0B,EAC1BY,UAA0B,EACG;EAC7B,MAAMC,gBAAgB,GAAGb,UAAU,CAACc,kBAAkB,CACpDF,UAAU,EACVlB,
|
|
1
|
+
{"version":3,"file":"EXT_meshopt_compression.js","names":["GLTFScenegraph","meshoptDecodeGltfBuffer","DEFAULT_MESHOPT_OPTIONS","byteOffset","filter","EXT_MESHOPT_COMPRESSION","name","decode","gltfData","options","_options$gltf","scenegraph","gltf","decompressMeshes","promises","bufferViewIndex","json","bufferViews","push","decodeMeshoptBufferView","Promise","all","removeExtension","bufferView","meshoptExtension","getObjectExtension","byteLength","byteStride","count","mode","buffer","bufferIndex","buffers","source","Uint8Array","arrayBuffer","result"],"sources":["../../../../src/lib/extensions/EXT_meshopt_compression.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\nimport {meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';\n\n// @ts-ignore\n// eslint-disable-next-line\nconst DEFAULT_MESHOPT_OPTIONS = {\n byteOffset: 0,\n filter: 'NONE'\n};\n\n/** Extension name */\nconst EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';\n\nexport const name = EXT_MESHOPT_COMPRESSION;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const promises: Promise<any>[] = [];\n for (const bufferViewIndex of gltfData.json.bufferViews || []) {\n promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);\n}\n\n/** Decode one meshopt buffer view */\nasync function decodeMeshoptBufferView(\n scenegraph: GLTFScenegraph,\n bufferView: GLTFBufferView\n): Promise<ArrayBuffer | null> {\n const meshoptExtension = scenegraph.getObjectExtension<GLTF_EXT_meshopt_compression>(\n bufferView,\n EXT_MESHOPT_COMPRESSION\n );\n if (meshoptExtension) {\n const {\n byteOffset = 0,\n byteLength = 0,\n byteStride,\n count,\n mode,\n filter = 'NONE',\n buffer: bufferIndex\n } = meshoptExtension;\n const buffer = scenegraph.gltf.buffers[bufferIndex];\n\n const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);\n const result = new Uint8Array(\n scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,\n bufferView.byteOffset,\n bufferView.byteLength\n );\n await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);\n return result;\n }\n\n return null;\n}\n"],"mappings":"AA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D,MAAME,MAAM,GAAG,IAAIC,UAAU,CAACJ,MAAM,CAACK,WAAW,EAAEL,MAAM,CAAC3B,UAAU,GAAGA,UAAU,EAAEuB,UAAU,CAAC;IAC7F,MAAMU,MAAM,GAAG,IAAIF,UAAU,CAC3BvB,UAAU,CAACC,IAAI,CAACoB,OAAO,CAACT,UAAU,CAACO,MAAM,CAAC,CAACK,WAAW,EACtDZ,UAAU,CAACpB,UAAU,EACrBoB,UAAU,CAACG,UACb,CAAC;IACD,MAAMzB,uBAAuB,CAACmC,MAAM,EAAER,KAAK,EAAED,UAAU,EAAEM,MAAM,EAAEJ,IAAI,EAAEzB,MAAM,CAAC;IAC9E,OAAOgC,MAAM;EACf;EAEA,OAAO,IAAI;AACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EXT_texture_webp.js","names":["isImageFormatSupported","GLTFScenegraph","EXT_TEXTURE_WEBP","name","preprocess","gltfData","options","scenegraph","getRequiredExtensions","includes","Error","concat","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/EXT_texture_webp.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_TEXTURE_WEBP\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {isImageFormatSupported} from '@loaders.gl/images';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst EXT_TEXTURE_WEBP = 'EXT_texture_webp';\n\n/** Extension name */\nexport const name = EXT_TEXTURE_WEBP;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!isImageFormatSupported('image/webp')) {\n if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {\n throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);\n }\n return;\n }\n\n const {json} = scenegraph;\n\n for (const texture of json.textures || []) {\n const extension = scenegraph.getObjectExtension<GLTF_EXT_texture_webp>(\n texture,\n EXT_TEXTURE_WEBP\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n }\n scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);\n }\n\n // Remove the top-level extension\n scenegraph.removeExtension(EXT_TEXTURE_WEBP);\n}\n"],"mappings":"AAOA,SAAQA,sBAAsB,QAAO,oBAAoB;AACzD,OAAOC,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,gBAAgB,GAAG,kBAAkB;AAG3C,OAAO,MAAMC,IAAI,GAAGD,gBAAgB;AAMpC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,UAAU,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAE/C,IAAI,CAACL,sBAAsB,CAAC,YAAY,CAAC,EAAE;IACzC,IAAIO,UAAU,CAACC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"EXT_texture_webp.js","names":["isImageFormatSupported","GLTFScenegraph","EXT_TEXTURE_WEBP","name","preprocess","gltfData","options","scenegraph","getRequiredExtensions","includes","Error","concat","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/EXT_texture_webp.ts"],"sourcesContent":["// GLTF EXTENSION: EXT_TEXTURE_WEBP\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {isImageFormatSupported} from '@loaders.gl/images';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst EXT_TEXTURE_WEBP = 'EXT_texture_webp';\n\n/** Extension name */\nexport const name = EXT_TEXTURE_WEBP;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scenegraph = new GLTFScenegraph(gltfData);\n\n if (!isImageFormatSupported('image/webp')) {\n if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {\n throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);\n }\n return;\n }\n\n const {json} = scenegraph;\n\n for (const texture of json.textures || []) {\n const extension = scenegraph.getObjectExtension<GLTF_EXT_texture_webp>(\n texture,\n EXT_TEXTURE_WEBP\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n }\n scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);\n }\n\n // Remove the top-level extension\n scenegraph.removeExtension(EXT_TEXTURE_WEBP);\n}\n"],"mappings":"AAOA,SAAQA,sBAAsB,QAAO,oBAAoB;AACzD,OAAOC,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,gBAAgB,GAAG,kBAAkB;AAG3C,OAAO,MAAMC,IAAI,GAAGD,gBAAgB;AAMpC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,UAAU,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAE/C,IAAI,CAACL,sBAAsB,CAAC,YAAY,CAAC,EAAE;IACzC,IAAIO,UAAU,CAACC,qBAAqB,CAAC,CAAC,CAACC,QAAQ,CAACP,gBAAgB,CAAC,EAAE;MACjE,MAAM,IAAIQ,KAAK,6BAAAC,MAAA,CAA6BT,gBAAgB,8BAA2B,CAAC;IAC1F;IACA;EACF;EAEA,MAAM;IAACU;EAAI,CAAC,GAAGL,UAAU;EAEzB,KAAK,MAAMM,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGR,UAAU,CAACS,kBAAkB,CAC7CH,OAAO,EACPX,gBACF,CAAC;IACD,IAAIa,SAAS,EAAE;MAEbF,OAAO,CAACI,MAAM,GAAGF,SAAS,CAACE,MAAM;IACnC;IACAV,UAAU,CAACW,qBAAqB,CAACL,OAAO,EAAEX,gBAAgB,CAAC;EAC7D;EAGAK,UAAU,CAACY,eAAe,CAACjB,gBAAgB,CAAC;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_binary_gltf.js","names":["GLTFScenegraph","KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","json","image","images","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_BINARY_GLTF = 'KHR_binary_glTF';\n\n/** Extension name */\nexport const name = KHR_BINARY_GLTF;\n\nexport function preprocess(gltfData: {json: GLTF}): void {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Note: json.buffers.binary_glTF also needs to be replaced\n // This is currently done during gltf normalization\n\n // Image and shader nodes can have the extension\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json\n for (const image of json.images || []) {\n const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(\n image,\n KHR_BINARY_GLTF\n );\n // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in\n if (extension) {\n Object.assign(image, extension);\n }\n gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);\n }\n\n // TODO shaders - At least traverse and throw error if used?\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json\n\n // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0\n if (json.buffers && json.buffers[0]) {\n delete json.buffers[0].uri;\n }\n\n // Remove the top-level extension as it has now been processed\n gltfScenegraph.removeExtension(KHR_BINARY_GLTF);\n}\n\n// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0\n// export function encode() {\n// throw new Error(KHR_BINARY_GLTF);\n// }\n"],"mappings":"AAMA,OAAOA,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,eAAe,GAAG,iBAAiB;AAGzC,OAAO,MAAMC,IAAI,GAAGD,eAAe;AAEnC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAQ;EACvD,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAO7B,KAAK,MAAME,KAAK,IAAID,IAAI,CAACE,MAAM,IAAI,EAAE,EAAE;IACrC,MAAMC,SAAS,GAAGJ,cAAc,CAACK,kBAAkB,CACjDH,KAAK,EACLN,
|
|
1
|
+
{"version":3,"file":"KHR_binary_gltf.js","names":["GLTFScenegraph","KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","json","image","images","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_BINARY_GLTF = 'KHR_binary_glTF';\n\n/** Extension name */\nexport const name = KHR_BINARY_GLTF;\n\nexport function preprocess(gltfData: {json: GLTF}): void {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Note: json.buffers.binary_glTF also needs to be replaced\n // This is currently done during gltf normalization\n\n // Image and shader nodes can have the extension\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json\n for (const image of json.images || []) {\n const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(\n image,\n KHR_BINARY_GLTF\n );\n // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in\n if (extension) {\n Object.assign(image, extension);\n }\n gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);\n }\n\n // TODO shaders - At least traverse and throw error if used?\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json\n\n // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0\n if (json.buffers && json.buffers[0]) {\n delete json.buffers[0].uri;\n }\n\n // Remove the top-level extension as it has now been processed\n gltfScenegraph.removeExtension(KHR_BINARY_GLTF);\n}\n\n// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0\n// export function encode() {\n// throw new Error(KHR_BINARY_GLTF);\n// }\n"],"mappings":"AAMA,OAAOA,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,eAAe,GAAG,iBAAiB;AAGzC,OAAO,MAAMC,IAAI,GAAGD,eAAe;AAEnC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAQ;EACvD,MAAMC,cAAc,GAAG,IAAIL,cAAc,CAACI,QAAQ,CAAC;EACnD,MAAM;IAACE;EAAI,CAAC,GAAGD,cAAc;EAO7B,KAAK,MAAME,KAAK,IAAID,IAAI,CAACE,MAAM,IAAI,EAAE,EAAE;IACrC,MAAMC,SAAS,GAAGJ,cAAc,CAACK,kBAAkB,CACjDH,KAAK,EACLN,eACF,CAAC;IAED,IAAIQ,SAAS,EAAE;MACbE,MAAM,CAACC,MAAM,CAACL,KAAK,EAAEE,SAAS,CAAC;IACjC;IACAJ,cAAc,CAACQ,qBAAqB,CAACN,KAAK,EAAEN,eAAe,CAAC;EAC9D;EAMA,IAAIK,IAAI,CAACQ,OAAO,IAAIR,IAAI,CAACQ,OAAO,CAAC,CAAC,CAAC,EAAE;IACnC,OAAOR,IAAI,CAACQ,OAAO,CAAC,CAAC,CAAC,CAACC,GAAG;EAC5B;EAGAV,cAAc,CAACW,eAAe,CAACf,eAAe,CAAC;AACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_draco_mesh_compression.js","names":["DracoLoader","sliceArrayBuffer","default","Scenegraph","getGLTFAccessors","getGLTFAccessor","KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","primitive","makeMeshPrimitiveIterator","getObjectExtension","decode","_options$gltf","gltf","decompressMeshes","promises","push","decompressPrimitive","Promise","all","removeExtension","encode","arguments","length","undefined","mesh","json","meshes","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","decodedData","decodedAttributes","attributes","attributeName","decodedAttribute","Object","entries","accessorIndex","accessor","getAccessor","min","max","indices","checkPrimitive","_context$parseSync","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","call","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys"],"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new Scenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new Scenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new Scenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: Scenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"mappings":"AAcA,SAAQA,WAAW,QAAO,mBAAmB;AAE7C,SAAQC,gBAAgB,QAAO,0BAA0B;AACzD,SAAQC,OAAO,IAAIC,UAAU,QAAO,wBAAwB;AAC5D,SAAQC,gBAAgB,EAAEC,eAAe,QAAO,oCAAoC;AAEpF,MAAMC,0BAA0B,GAAG,4BAA4B;AAG/D,OAAO,MAAMC,IAAI,GAAGD,0BAA0B;AAE9C,OAAO,SAASE,UAAUA,CACxBC,QAAsB,EACtBC,OAA0B,EAC1BC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I;MACJa,UAAU,EAAE;QACV,CAACjE,0BAA0B,GAAG;UAC5BgC,UAAU,EAAE6B,eAAe;UAC3BtB,UAAU,EAAEoB;QACd;MACF;IACF,CAAC;EAEL,CAAC;EAED,OAAOI,QAAQ;AACjB;AAIA,SAASb,cAAcA,CAAC3C,SAA4B,EAAE;EACpD,IAAI,CAACA,SAAS,CAACgC,UAAU,IAAIG,MAAM,CAACwB,IAAI,CAAC3D,SAAS,CAACgC,UAAU,CAAC,CAACjB,MAAM,GAAG,CAAC,EAAE;IACzE,MAAM,IAAIgC,KAAK,CAAC,8DAA8D,CAAC;EACjF;AACF;AAEA,UAAU9C,yBAAyBA,CAACF,UAAU,EAAE;EAC9C,KAAK,MAAMkB,IAAI,IAAIlB,UAAU,CAACmB,IAAI,CAACC,MAAM,IAAI,EAAE,EAAE;IAC/C,KAAK,MAAMnB,SAAS,IAAIiB,IAAI,CAACwC,UAAU,EAAE;MACvC,MAAMzD,SAAS;IACjB;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"KHR_draco_mesh_compression.js","names":["DracoLoader","sliceArrayBuffer","default","Scenegraph","getGLTFAccessors","getGLTFAccessor","KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","primitive","makeMeshPrimitiveIterator","getObjectExtension","decode","_options$gltf","gltf","decompressMeshes","promises","push","decompressPrimitive","Promise","all","removeExtension","encode","arguments","length","undefined","mesh","json","meshes","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","decodedData","decodedAttributes","attributes","attributeName","decodedAttribute","Object","entries","accessorIndex","accessor","getAccessor","min","max","indices","checkPrimitive","_context$parseSync","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","call","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys"],"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new Scenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new Scenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extension\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new Scenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: Scenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"mappings":"AAcA,SAAQA,WAAW,QAAO,mBAAmB;AAE7C,SAAQC,gBAAgB,QAAO,0BAA0B;AACzD,SAAQC,OAAO,IAAI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,OAAO,CAACwD,kBAAkB,CAACvB,WAAW,CAACE,UAAU,CAAC;EAExE,MAAMsB,eAAe,GAAGzD,OAAO,CAAC0D,aAAa,CAACP,cAAc,CAAC;EAE7D,MAAMQ,QAAQ,GAAG;IACfC,UAAU,EAAE,CACV;MACEzB,UAAU,EAAEoB,aAAa;MACzBP,IAAI;MACJa,UAAU,EAAE;QACV,CAACjE,0BAA0B,GAAG;UAC5BgC,UAAU,EAAE6B,eAAe;UAC3BtB,UAAU,EAAEoB;QACd;MACF;IACF,CAAC;EAEL,CAAC;EAED,OAAOI,QAAQ;AACjB;AAIA,SAASb,cAAcA,CAAC3C,SAA4B,EAAE;EACpD,IAAI,CAACA,SAAS,CAACgC,UAAU,IAAIG,MAAM,CAACwB,IAAI,CAAC3D,SAAS,CAACgC,UAAU,CAAC,CAACjB,MAAM,GAAG,CAAC,EAAE;IACzE,MAAM,IAAIgC,KAAK,CAAC,8DAA8D,CAAC;EACjF;AACF;AAEA,UAAU9C,yBAAyBA,CAACF,UAAU,EAAE;EAC9C,KAAK,MAAMkB,IAAI,IAAIlB,UAAU,CAACmB,IAAI,CAACC,MAAM,IAAI,EAAE,EAAE;IAC/C,KAAK,MAAMnB,SAAS,IAAIiB,IAAI,CAACwC,UAAU,EAAE;MACvC,MAAMzD,SAAS;IACjB;EACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KHR_texture_basisu.js","names":["GLTFScenegraph","KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n }\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"mappings":"AAOA,OAAOA,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,kBAAkB,GAAG,oBAAoB;AAG/C,OAAO,MAAMC,IAAI,GAAGD,kBAAkB;AAMtC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,KAAK,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAC1C,MAAM;IAACG;EAAI,CAAC,GAAGD,KAAK;EAEpB,KAAK,MAAME,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGJ,KAAK,CAACK,kBAAkB,CACxCH,OAAO,EACPP,
|
|
1
|
+
{"version":3,"file":"KHR_texture_basisu.js","names":["GLTFScenegraph","KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n // TODO - if multiple texture extensions are present which one wins?\n texture.source = extension.source;\n }\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"mappings":"AAOA,OAAOA,cAAc,MAAM,wBAAwB;AAEnD,MAAMC,kBAAkB,GAAG,oBAAoB;AAG/C,OAAO,MAAMC,IAAI,GAAGD,kBAAkB;AAMtC,OAAO,SAASE,UAAUA,CAACC,QAAsB,EAAEC,OAA0B,EAAQ;EACnF,MAAMC,KAAK,GAAG,IAAIN,cAAc,CAACI,QAAQ,CAAC;EAC1C,MAAM;IAACG;EAAI,CAAC,GAAGD,KAAK;EAEpB,KAAK,MAAME,OAAO,IAAID,IAAI,CAACE,QAAQ,IAAI,EAAE,EAAE;IACzC,MAAMC,SAAS,GAAGJ,KAAK,CAACK,kBAAkB,CACxCH,OAAO,EACPP,kBACF,CAAC;IACD,IAAIS,SAAS,EAAE;MAEbF,OAAO,CAACI,MAAM,GAAGF,SAAS,CAACE,MAAM;IACnC;IACAN,KAAK,CAACO,qBAAqB,CAACL,OAAO,EAAEP,kBAAkB,CAAC;EAC1D;EAGAK,KAAK,CAACQ,eAAe,CAACb,kBAAkB,CAAC;AAC3C"}
|