three-stdlib
Version:
stand-alone library of threejs examples
1 lines • 178 kB
Source Map (JSON)
{"version":3,"file":"GLTFLoader.cjs","sources":["../../src/loaders/GLTFLoader.js"],"sourcesContent":["import {\n AnimationClip,\n Bone,\n Box3,\n BufferAttribute,\n BufferGeometry,\n ClampToEdgeWrapping,\n Color,\n DirectionalLight,\n DoubleSide,\n FileLoader,\n FrontSide,\n Group,\n ImageBitmapLoader,\n InstancedMesh,\n InterleavedBuffer,\n InterleavedBufferAttribute,\n Interpolant,\n InterpolateDiscrete,\n InterpolateLinear,\n Line,\n LineBasicMaterial,\n LineLoop,\n LineSegments,\n LinearFilter,\n LinearMipmapLinearFilter,\n LinearMipmapNearestFilter,\n Loader,\n LoaderUtils,\n Material,\n MathUtils,\n Matrix4,\n Mesh,\n MeshBasicMaterial,\n MeshPhysicalMaterial,\n MeshStandardMaterial,\n MirroredRepeatWrapping,\n NearestFilter,\n NearestMipmapLinearFilter,\n NearestMipmapNearestFilter,\n NumberKeyframeTrack,\n Object3D,\n OrthographicCamera,\n PerspectiveCamera,\n PointLight,\n Points,\n PointsMaterial,\n PropertyBinding,\n Quaternion,\n QuaternionKeyframeTrack,\n RepeatWrapping,\n Skeleton,\n SkinnedMesh,\n Sphere,\n SpotLight,\n Texture,\n TextureLoader,\n TriangleFanDrawMode,\n TriangleStripDrawMode,\n Vector2,\n Vector3,\n VectorKeyframeTrack,\n InstancedBufferAttribute,\n} from 'three'\nimport { toTrianglesDrawMode } from '../utils/BufferGeometryUtils'\nimport { version } from '../_polyfill/constants'\nimport { decodeText } from '../_polyfill/LoaderUtils'\n\nconst SRGBColorSpace = 'srgb'\nconst LinearSRGBColorSpace = 'srgb-linear'\nconst sRGBEncoding = 3001\nconst LinearEncoding = 3000\n\nclass GLTFLoader extends Loader {\n constructor(manager) {\n super(manager)\n\n this.dracoLoader = null\n this.ktx2Loader = null\n this.meshoptDecoder = null\n\n this.pluginCallbacks = []\n\n this.register(function (parser) {\n return new GLTFMaterialsClearcoatExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsDispersionExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFTextureBasisUExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFTextureWebPExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFTextureAVIFExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsSheenExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsTransmissionExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsVolumeExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsIorExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsEmissiveStrengthExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsSpecularExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsIridescenceExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsAnisotropyExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMaterialsBumpExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFLightsExtension(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMeshoptCompression(parser)\n })\n\n this.register(function (parser) {\n return new GLTFMeshGpuInstancing(parser)\n })\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n\n let resourcePath\n\n if (this.resourcePath !== '') {\n resourcePath = this.resourcePath\n } else if (this.path !== '') {\n // If a base path is set, resources will be relative paths from that plus the relative path of the gltf file\n // Example path = 'https://my-cnd-server.com/', url = 'assets/models/model.gltf'\n // resourcePath = 'https://my-cnd-server.com/assets/models/'\n // referenced resource 'model.bin' will be loaded from 'https://my-cnd-server.com/assets/models/model.bin'\n // referenced resource '../textures/texture.png' will be loaded from 'https://my-cnd-server.com/assets/textures/texture.png'\n const relativeUrl = LoaderUtils.extractUrlBase(url)\n resourcePath = LoaderUtils.resolveURL(relativeUrl, this.path)\n } else {\n resourcePath = LoaderUtils.extractUrlBase(url)\n }\n\n // Tells the LoadingManager to track an extra item, which resolves after\n // the model is fully loaded. This means the count of items loaded will\n // be incorrect, but ensures manager.onLoad() does not fire early.\n this.manager.itemStart(url)\n\n const _onError = function (e) {\n if (onError) {\n onError(e)\n } else {\n console.error(e)\n }\n\n scope.manager.itemError(url)\n scope.manager.itemEnd(url)\n }\n\n const loader = new FileLoader(this.manager)\n\n loader.setPath(this.path)\n loader.setResponseType('arraybuffer')\n loader.setRequestHeader(this.requestHeader)\n loader.setWithCredentials(this.withCredentials)\n\n loader.load(\n url,\n function (data) {\n try {\n scope.parse(\n data,\n resourcePath,\n function (gltf) {\n onLoad(gltf)\n\n scope.manager.itemEnd(url)\n },\n _onError,\n )\n } catch (e) {\n _onError(e)\n }\n },\n onProgress,\n _onError,\n )\n }\n\n setDRACOLoader(dracoLoader) {\n this.dracoLoader = dracoLoader\n return this\n }\n\n setDDSLoader() {\n throw new Error('THREE.GLTFLoader: \"MSFT_texture_dds\" no longer supported. Please update to \"KHR_texture_basisu\".')\n }\n\n setKTX2Loader(ktx2Loader) {\n this.ktx2Loader = ktx2Loader\n return this\n }\n\n setMeshoptDecoder(meshoptDecoder) {\n this.meshoptDecoder = meshoptDecoder\n return this\n }\n\n register(callback) {\n if (this.pluginCallbacks.indexOf(callback) === -1) {\n this.pluginCallbacks.push(callback)\n }\n\n return this\n }\n\n unregister(callback) {\n if (this.pluginCallbacks.indexOf(callback) !== -1) {\n this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(callback), 1)\n }\n\n return this\n }\n\n parse(data, path, onLoad, onError) {\n let json\n const extensions = {}\n const plugins = {}\n\n if (typeof data === 'string') {\n json = JSON.parse(data)\n } else if (data instanceof ArrayBuffer) {\n const magic = decodeText(new Uint8Array(data.slice(0, 4)))\n\n if (magic === BINARY_EXTENSION_HEADER_MAGIC) {\n try {\n extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data)\n } catch (error) {\n if (onError) onError(error)\n return\n }\n\n json = JSON.parse(extensions[EXTENSIONS.KHR_BINARY_GLTF].content)\n } else {\n json = JSON.parse(decodeText(new Uint8Array(data)))\n }\n } else {\n json = data\n }\n\n if (json.asset === undefined || json.asset.version[0] < 2) {\n if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.'))\n return\n }\n\n const parser = new GLTFParser(json, {\n path: path || this.resourcePath || '',\n crossOrigin: this.crossOrigin,\n requestHeader: this.requestHeader,\n manager: this.manager,\n ktx2Loader: this.ktx2Loader,\n meshoptDecoder: this.meshoptDecoder,\n })\n\n parser.fileLoader.setRequestHeader(this.requestHeader)\n\n for (let i = 0; i < this.pluginCallbacks.length; i++) {\n const plugin = this.pluginCallbacks[i](parser)\n\n if (!plugin.name) console.error('THREE.GLTFLoader: Invalid plugin found: missing name')\n\n plugins[plugin.name] = plugin\n\n // Workaround to avoid determining as unknown extension\n // in addUnknownExtensionsToUserData().\n // Remove this workaround if we move all the existing\n // extension handlers to plugin system\n extensions[plugin.name] = true\n }\n\n if (json.extensionsUsed) {\n for (let i = 0; i < json.extensionsUsed.length; ++i) {\n const extensionName = json.extensionsUsed[i]\n const extensionsRequired = json.extensionsRequired || []\n\n switch (extensionName) {\n case EXTENSIONS.KHR_MATERIALS_UNLIT:\n extensions[extensionName] = new GLTFMaterialsUnlitExtension()\n break\n\n case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:\n extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader)\n break\n\n case EXTENSIONS.KHR_TEXTURE_TRANSFORM:\n extensions[extensionName] = new GLTFTextureTransformExtension()\n break\n\n case EXTENSIONS.KHR_MESH_QUANTIZATION:\n extensions[extensionName] = new GLTFMeshQuantizationExtension()\n break\n\n default:\n if (extensionsRequired.indexOf(extensionName) >= 0 && plugins[extensionName] === undefined) {\n console.warn('THREE.GLTFLoader: Unknown extension \"' + extensionName + '\".')\n }\n }\n }\n }\n\n parser.setExtensions(extensions)\n parser.setPlugins(plugins)\n parser.parse(onLoad, onError)\n }\n\n parseAsync(data, path) {\n const scope = this\n\n return new Promise(function (resolve, reject) {\n scope.parse(data, path, resolve, reject)\n })\n }\n}\n\n/* GLTFREGISTRY */\n\nfunction GLTFRegistry() {\n let objects = {}\n\n return {\n get: function (key) {\n return objects[key]\n },\n\n add: function (key, object) {\n objects[key] = object\n },\n\n remove: function (key) {\n delete objects[key]\n },\n\n removeAll: function () {\n objects = {}\n },\n }\n}\n\n/*********************************/\n/********** EXTENSIONS ***********/\n/*********************************/\n\nconst EXTENSIONS = {\n KHR_BINARY_GLTF: 'KHR_binary_glTF',\n KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',\n KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',\n KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',\n KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',\n KHR_MATERIALS_IOR: 'KHR_materials_ior',\n KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',\n KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',\n KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',\n KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',\n KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',\n KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',\n KHR_MATERIALS_VOLUME: 'KHR_materials_volume',\n KHR_TEXTURE_BASISU: 'KHR_texture_basisu',\n KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',\n KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',\n KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',\n EXT_MATERIALS_BUMP: 'EXT_materials_bump',\n EXT_TEXTURE_WEBP: 'EXT_texture_webp',\n EXT_TEXTURE_AVIF: 'EXT_texture_avif',\n EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',\n EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing',\n}\n\n/**\n * Punctual Lights Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n */\nclass GLTFLightsExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL\n\n // Object3D instance caches\n this.cache = { refs: {}, uses: {} }\n }\n\n _markDefs() {\n const parser = this.parser\n const nodeDefs = this.parser.json.nodes || []\n\n for (let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {\n const nodeDef = nodeDefs[nodeIndex]\n\n if (nodeDef.extensions && nodeDef.extensions[this.name] && nodeDef.extensions[this.name].light !== undefined) {\n parser._addNodeRef(this.cache, nodeDef.extensions[this.name].light)\n }\n }\n }\n\n _loadLight(lightIndex) {\n const parser = this.parser\n const cacheKey = 'light:' + lightIndex\n let dependency = parser.cache.get(cacheKey)\n\n if (dependency) return dependency\n\n const json = parser.json\n const extensions = (json.extensions && json.extensions[this.name]) || {}\n const lightDefs = extensions.lights || []\n const lightDef = lightDefs[lightIndex]\n let lightNode\n\n const color = new Color(0xffffff)\n\n if (lightDef.color !== undefined)\n color.setRGB(lightDef.color[0], lightDef.color[1], lightDef.color[2], LinearSRGBColorSpace)\n\n const range = lightDef.range !== undefined ? lightDef.range : 0\n\n switch (lightDef.type) {\n case 'directional':\n lightNode = new DirectionalLight(color)\n lightNode.target.position.set(0, 0, -1)\n lightNode.add(lightNode.target)\n break\n\n case 'point':\n lightNode = new PointLight(color)\n lightNode.distance = range\n break\n\n case 'spot':\n lightNode = new SpotLight(color)\n lightNode.distance = range\n // Handle spotlight properties.\n lightDef.spot = lightDef.spot || {}\n lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0\n lightDef.spot.outerConeAngle =\n lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0\n lightNode.angle = lightDef.spot.outerConeAngle\n lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle\n lightNode.target.position.set(0, 0, -1)\n lightNode.add(lightNode.target)\n break\n\n default:\n throw new Error('THREE.GLTFLoader: Unexpected light type: ' + lightDef.type)\n }\n\n // Some lights (e.g. spot) default to a position other than the origin. Reset the position\n // here, because node-level parsing will only override position if explicitly specified.\n lightNode.position.set(0, 0, 0)\n\n lightNode.decay = 2\n\n assignExtrasToUserData(lightNode, lightDef)\n\n if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity\n\n lightNode.name = parser.createUniqueName(lightDef.name || 'light_' + lightIndex)\n\n dependency = Promise.resolve(lightNode)\n\n parser.cache.add(cacheKey, dependency)\n\n return dependency\n }\n\n getDependency(type, index) {\n if (type !== 'light') return\n\n return this._loadLight(index)\n }\n\n createNodeAttachment(nodeIndex) {\n const self = this\n const parser = this.parser\n const json = parser.json\n const nodeDef = json.nodes[nodeIndex]\n const lightDef = (nodeDef.extensions && nodeDef.extensions[this.name]) || {}\n const lightIndex = lightDef.light\n\n if (lightIndex === undefined) return null\n\n return this._loadLight(lightIndex).then(function (light) {\n return parser._getNodeRef(self.cache, lightIndex, light)\n })\n }\n}\n\n/**\n * Unlit Materials Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit\n */\nclass GLTFMaterialsUnlitExtension {\n constructor() {\n this.name = EXTENSIONS.KHR_MATERIALS_UNLIT\n }\n\n getMaterialType() {\n return MeshBasicMaterial\n }\n\n extendParams(materialParams, materialDef, parser) {\n const pending = []\n\n materialParams.color = new Color(1.0, 1.0, 1.0)\n materialParams.opacity = 1.0\n\n const metallicRoughness = materialDef.pbrMetallicRoughness\n\n if (metallicRoughness) {\n if (Array.isArray(metallicRoughness.baseColorFactor)) {\n const array = metallicRoughness.baseColorFactor\n\n materialParams.color.setRGB(array[0], array[1], array[2], LinearSRGBColorSpace)\n materialParams.opacity = array[3]\n }\n\n if (metallicRoughness.baseColorTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace))\n }\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials Emissive Strength Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md\n */\nclass GLTFMaterialsEmissiveStrengthExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const emissiveStrength = materialDef.extensions[this.name].emissiveStrength\n\n if (emissiveStrength !== undefined) {\n materialParams.emissiveIntensity = emissiveStrength\n }\n\n return Promise.resolve()\n }\n}\n\n/**\n * Clearcoat Materials Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat\n */\nclass GLTFMaterialsClearcoatExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n if (extension.clearcoatFactor !== undefined) {\n materialParams.clearcoat = extension.clearcoatFactor\n }\n\n if (extension.clearcoatTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'clearcoatMap', extension.clearcoatTexture))\n }\n\n if (extension.clearcoatRoughnessFactor !== undefined) {\n materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor\n }\n\n if (extension.clearcoatRoughnessTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture))\n }\n\n if (extension.clearcoatNormalTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture))\n\n if (extension.clearcoatNormalTexture.scale !== undefined) {\n const scale = extension.clearcoatNormalTexture.scale\n\n materialParams.clearcoatNormalScale = new Vector2(scale, scale)\n }\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials dispersion Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion\n */\nclass GLTFMaterialsDispersionExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const extension = materialDef.extensions[this.name]\n\n materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0\n\n return Promise.resolve()\n }\n}\n\n/**\n * Iridescence Materials Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence\n */\nclass GLTFMaterialsIridescenceExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n if (extension.iridescenceFactor !== undefined) {\n materialParams.iridescence = extension.iridescenceFactor\n }\n\n if (extension.iridescenceTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'iridescenceMap', extension.iridescenceTexture))\n }\n\n if (extension.iridescenceIor !== undefined) {\n materialParams.iridescenceIOR = extension.iridescenceIor\n }\n\n if (materialParams.iridescenceThicknessRange === undefined) {\n materialParams.iridescenceThicknessRange = [100, 400]\n }\n\n if (extension.iridescenceThicknessMinimum !== undefined) {\n materialParams.iridescenceThicknessRange[0] = extension.iridescenceThicknessMinimum\n }\n\n if (extension.iridescenceThicknessMaximum !== undefined) {\n materialParams.iridescenceThicknessRange[1] = extension.iridescenceThicknessMaximum\n }\n\n if (extension.iridescenceThicknessTexture !== undefined) {\n pending.push(\n parser.assignTexture(materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture),\n )\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Sheen Materials Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen\n */\nclass GLTFMaterialsSheenExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_SHEEN\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n materialParams.sheenColor = new Color(0, 0, 0)\n materialParams.sheenRoughness = 0\n materialParams.sheen = 1\n\n const extension = materialDef.extensions[this.name]\n\n if (extension.sheenColorFactor !== undefined) {\n const colorFactor = extension.sheenColorFactor\n materialParams.sheenColor.setRGB(colorFactor[0], colorFactor[1], colorFactor[2], LinearSRGBColorSpace)\n }\n\n if (extension.sheenRoughnessFactor !== undefined) {\n materialParams.sheenRoughness = extension.sheenRoughnessFactor\n }\n\n if (extension.sheenColorTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace))\n }\n\n if (extension.sheenRoughnessTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture))\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Transmission Materials Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission\n * Draft: https://github.com/KhronosGroup/glTF/pull/1698\n */\nclass GLTFMaterialsTransmissionExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n if (extension.transmissionFactor !== undefined) {\n materialParams.transmission = extension.transmissionFactor\n }\n\n if (extension.transmissionTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'transmissionMap', extension.transmissionTexture))\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials Volume Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume\n */\nclass GLTFMaterialsVolumeExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_VOLUME\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0\n\n if (extension.thicknessTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'thicknessMap', extension.thicknessTexture))\n }\n\n materialParams.attenuationDistance = extension.attenuationDistance || Infinity\n\n const colorArray = extension.attenuationColor || [1, 1, 1]\n materialParams.attenuationColor = new Color().setRGB(\n colorArray[0],\n colorArray[1],\n colorArray[2],\n LinearSRGBColorSpace,\n )\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials ior Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior\n */\nclass GLTFMaterialsIorExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_IOR\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const extension = materialDef.extensions[this.name]\n\n materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5\n\n return Promise.resolve()\n }\n}\n\n/**\n * Materials specular Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular\n */\nclass GLTFMaterialsSpecularExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0\n\n if (extension.specularTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'specularIntensityMap', extension.specularTexture))\n }\n\n const colorArray = extension.specularColorFactor || [1, 1, 1]\n materialParams.specularColor = new Color().setRGB(colorArray[0], colorArray[1], colorArray[2], LinearSRGBColorSpace)\n\n if (extension.specularColorTexture !== undefined) {\n pending.push(\n parser.assignTexture(materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace),\n )\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials bump Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_materials_bump\n */\nclass GLTFMaterialsBumpExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.EXT_MATERIALS_BUMP\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0\n\n if (extension.bumpTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'bumpMap', extension.bumpTexture))\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * Materials anisotropy Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_anisotropy\n */\nclass GLTFMaterialsAnisotropyExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY\n }\n\n getMaterialType(materialIndex) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) return null\n\n return MeshPhysicalMaterial\n }\n\n extendMaterialParams(materialIndex, materialParams) {\n const parser = this.parser\n const materialDef = parser.json.materials[materialIndex]\n\n if (!materialDef.extensions || !materialDef.extensions[this.name]) {\n return Promise.resolve()\n }\n\n const pending = []\n\n const extension = materialDef.extensions[this.name]\n\n if (extension.anisotropyStrength !== undefined) {\n materialParams.anisotropy = extension.anisotropyStrength\n }\n\n if (extension.anisotropyRotation !== undefined) {\n materialParams.anisotropyRotation = extension.anisotropyRotation\n }\n\n if (extension.anisotropyTexture !== undefined) {\n pending.push(parser.assignTexture(materialParams, 'anisotropyMap', extension.anisotropyTexture))\n }\n\n return Promise.all(pending)\n }\n}\n\n/**\n * BasisU Texture Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu\n */\nclass GLTFTextureBasisUExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.KHR_TEXTURE_BASISU\n }\n\n loadTexture(textureIndex) {\n const parser = this.parser\n const json = parser.json\n\n const textureDef = json.textures[textureIndex]\n\n if (!textureDef.extensions || !textureDef.extensions[this.name]) {\n return null\n }\n\n const extension = textureDef.extensions[this.name]\n const loader = parser.options.ktx2Loader\n\n if (!loader) {\n if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {\n throw new Error('THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures')\n } else {\n // Assumes that the extension is optional and that a fallback texture is present\n return null\n }\n }\n\n return parser.loadTextureImage(textureIndex, extension.source, loader)\n }\n}\n\n/**\n * WebP Texture Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp\n */\nclass GLTFTextureWebPExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.EXT_TEXTURE_WEBP\n this.isSupported = null\n }\n\n loadTexture(textureIndex) {\n const name = this.name\n const parser = this.parser\n const json = parser.json\n\n const textureDef = json.textures[textureIndex]\n\n if (!textureDef.extensions || !textureDef.extensions[name]) {\n return null\n }\n\n const extension = textureDef.extensions[name]\n const source = json.images[extension.source]\n\n let loader = parser.textureLoader\n if (source.uri) {\n const handler = parser.options.manager.getHandler(source.uri)\n if (handler !== null) loader = handler\n }\n\n return this.detectSupport().then(function (isSupported) {\n if (isSupported) return parser.loadTextureImage(textureIndex, extension.source, loader)\n\n if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {\n throw new Error('THREE.GLTFLoader: WebP required by asset but unsupported.')\n }\n\n // Fall back to PNG or JPEG.\n return parser.loadTexture(textureIndex)\n })\n }\n\n detectSupport() {\n if (!this.isSupported) {\n this.isSupported = new Promise(function (resolve) {\n const image = new Image()\n\n // Lossy test image. Support for lossy images doesn't guarantee support for all\n // WebP images, unfortunately.\n image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'\n\n image.onload = image.onerror = function () {\n resolve(image.height === 1)\n }\n })\n }\n\n return this.isSupported\n }\n}\n\n/**\n * AVIF Texture Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_avif\n */\nclass GLTFTextureAVIFExtension {\n constructor(parser) {\n this.parser = parser\n this.name = EXTENSIONS.EXT_TEXTURE_AVIF\n this.isSupported = null\n }\n\n loadTexture(textureIndex) {\n const name = this.name\n const parser = this.parser\n const json = parser.json\n\n const textureDef = json.textures[textureIndex]\n\n if (!textureDef.extensions || !textureDef.extensions[name]) {\n return null\n }\n\n const extension = textureDef.extensions[name]\n const source = json.images[extension.source]\n\n let loader = parser.textureLoader\n if (source.uri) {\n const handler = parser.options.manager.getHandler(source.uri)\n if (handler !== null) loader = handler\n }\n\n return this.detectSupport().then(function (isSupported) {\n if (isSupported) return parser.loadTextureImage(textureIndex, extension.source, loader)\n\n if (json.extensionsRequired && json.extensionsRequired.indexOf(name) >= 0) {\n throw new Error('THREE.GLTFLoader: AVIF required by asset but unsupported.')\n }\n\n // Fall back to PNG or JPEG.\n return parser.loadTexture(textureIndex)\n })\n }\n\n detectSupport() {\n if (!this.isSupported) {\n this.isSupported = new Promise(function (resolve) {\n const image = new Image()\n\n // Lossy test image.\n image.src =\n 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI='\n image.onload = image.onerror = function () {\n resolve(image.height === 1)\n }\n })\n }\n\n return this.isSupported\n }\n}\n\n/**\n * meshopt BufferView Compression Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression\n */\nclass GLTFMeshoptCompression {\n constructor(parser) {\n this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION\n this.parser = parser\n }\n\n loadBufferView(index) {\n const json = this.parser.json\n const bufferView = json.bufferViews[index]\n\n if (bufferView.extensions && bufferView.extensions[this.name]) {\n const extensionDef = bufferView.extensions[this.name]\n\n const buffer = this.parser.getDependency('buffer', extensionDef.buffer)\n const decoder = this.parser.options.meshoptDecoder\n\n if (!decoder || !decoder.supported) {\n if (json.extensionsRequired && json.extensionsRequired.indexOf(this.name) >= 0) {\n throw new Error('THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files')\n } else {\n // Assumes that the extension is optional and that fallback buffer data is present\n return null\n }\n }\n\n return buffer.then(function (res) {\n const byteOffset = extensionDef.byteOffset || 0\n const byteLength = extensionDef.byteLength || 0\n\n const count = extensionDef.count\n const stride = extensionDef.byteStride\n\n const source = new Uint8Array(res, byteOffset, byteLength)\n\n if (decoder.decodeGltfBufferAsync) {\n return decoder\n .decodeGltfBufferAsync(count, stride, source, extensionDef.mode, extensionDef.filter)\n .then(function (res) {\n return res.buffer\n })\n } else {\n // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync\n return decoder.ready.then(function () {\n const result = new ArrayBuffer(count * stride)\n decoder.decodeGltfBuffer(\n new Uint8Array(result),\n count,\n stride,\n source,\n extensionDef.mode,\n extensionDef.filter,\n )\n return result\n })\n }\n })\n } else {\n return null\n }\n }\n}\n\n/**\n * GPU Instancing Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing\n *\n */\nclass GLTFMeshGpuInstancing {\n constructor(parser) {\n this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING\n this.parser = parser\n }\n\n createNodeMesh(nodeIndex) {\n const json = this.parser.json\n const nodeDef = json.nodes[nodeIndex]\n\n if (!nodeDef.extensions || !nodeDef.extensions[this.name] || nodeDef.mesh === undefined) {\n return null\n }\n\n const meshDef = json.meshes[nodeDef.mesh]\n\n // No Points or Lines + Instancing support yet\n\n for (const primitive of meshDef.primitives) {\n if (\n primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&\n primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&\n primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&\n primitive.mode !== undefined\n ) {\n return null\n }\n }\n\n const extensionDef = nodeDef.extensions[this.name]\n const attributesDef = extensionDef.attributes\n\n // @TODO: Can we support InstancedMesh + SkinnedMesh?\n\n const pending = []\n const attributes = {}\n\n for (const key in attributesDef) {\n pending.push(\n this.parser.getDependency('accessor', attributesDef[key]).then((accessor) => {\n attributes[key] = accessor\n return attributes[key]\n }),\n )\n }\n\n if (pending.length < 1) {\n return null\n }\n\n pending.push(this.parser.createNodeMesh(nodeIndex))\n\n return Promise.all(pending).then((results) => {\n const nodeObject = results.pop()\n const meshes = nodeObject.isGroup ? nodeObject.children : [nodeObject]\n const count = results[0].count // All attribute counts should be same\n const instancedMeshes = []\n\n for (const mesh of meshes) {\n // Temporal variables\n const m = new Matrix4()\n const p = new Vector3()\n const q = new Quaternion()\n const s = new Vector3(1, 1, 1)\n\n const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, count)\n\n for (let i = 0; i < count; i++) {\n if (attributes.TRANSLATION) {\n p.fromBufferAttribute(attributes.TRANSLATION, i)\n }\n\n if (attributes.ROTATION) {\n q.fromBufferAttribute(attributes.ROTATION, i)\n }\n\n if (attributes.SCALE) {\n s.fromBufferAttribute(attributes.SCALE, i)\n }\n\n instancedMesh.setMatrixAt(i, m.compose(p, q, s))\n }\n\n // Add instance attributes to the geometry, excluding TRS.\n for (const attributeName in attributes) {\n if (attributeName === '_COLOR_0') {\n const attr = attributes[attributeName]\n instancedMesh.instanceColor = new InstancedBufferAttribute(attr.array, attr.itemSize, attr.normalized)\n } else if (attributeName !== 'TRANSLATION' && attributeName !== 'ROTATION' && attributeName !== 'SCALE') {\n mesh.geometry.setAttribute(attributeName, attributes[attributeName])\n }\n }\n\n // Just in case\n Object3D.prototype.copy.call(instancedMesh, mesh)\n\n this.parser.assignFinalMaterial(instancedMesh)\n\n instancedMeshes.push(instancedMesh)\n }\n\n if (nodeObject.isGroup) {\n nodeObject.clear()\n\n nodeObject.add(...instancedMeshes)\n\n return nodeObject\n }\n\n return instancedMeshes[0]\n })\n }\n}\n\n/* BINARY EXTENSION */\nconst BINARY_EXTENSION_HEADER_MAGIC = 'glTF'\nconst BINARY_EXTENSION_HEADER_LENGTH = 12\nconst BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4942 }\n\nclass GLTFBinaryExtension {\n constructor(data) {\n this.name = EXTENSIONS.KHR_BINARY_GLTF\n this.content = null\n this.body = null\n\n const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH)\n\n this.header = {\n magic: decodeText(new Uint8Array(data.slice(0, 4))),\n version: headerView.getUint32(4, true),\n length: headerView.getUint32(8, true),\n }\n\n if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {\n throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.')\n } else if (this.header.version < 2.0) {\n throw new Error('THREE.GLTFLoader: Legacy binary file detected.')\n }\n\n const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH\n const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH)\n let chunkIndex = 0\n\n while (chunkIndex < chunkContentsLength) {\n const chunkLength = chunkView.getUint32(chunkIndex, true)\n chunkIndex += 4\n\n const chunkType = chunkView.getUint32(chunkIndex, true)\n chunkIndex += 4\n\n if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {\n const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength)\n this.content = decodeText(contentArray)\n } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {\n const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex\n this.body = data.slice(byteOffset, byteOffset + chunkLength)\n }\n\n // Clients must ignore chunks with unknown types.\n\n chunkIndex += chunkLength\n }\n\n if (this.content === null) {\n throw new Error('THREE.GLTFLoader: JSON content not found.')\n }\n }\n}\n\n/**\n * DRACO Mesh Compression Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n */\nclass GLTFDracoMeshCompressionExtension {\n constructor(json, dracoLoader) {\n if (!dracoLoader) {\n throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.')\n }\n\n this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION\n this.json = json\n this.dracoLoader = dracoLoader\n this.dracoLoader.preload()\n }\n\n decodePrimitive(primitive, parser) {\n const json = this.json\n const dracoLoader = this.dracoLoader\n const bufferViewIndex = primitive.extensions[this.name].bufferView\n const gltfAttributeMap = primitive.extensions[this.name].attributes\n const threeAttributeMap = {}\n const attributeNormalizedMap = {}\n const attributeTypeMap = {}\n\n for (const attributeName in gltfAttributeMap) {\n const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase()\n\n threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName]\n }\n\n for (const attributeName in primitive.attributes) {\n const threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase()\n\n if (gltfAttributeMap[attributeName] !== undefined) {\n const accessorDef = json.accessors[primitive.attributes[attributeName]]\n const componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType]\n\n attributeTypeMap[threeAttributeName] = componentType.name\n attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true\n }\n }\n\n return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {\n return new Promise(function (resolve, reject) {\n dracoLoader.decodeDracoFile(\n bufferView,\n function (geometry) {\n for (const attributeName in geometry.attributes) {\n const attribute = geometry.attributes[attributeName]\n const normalized = attributeNormalizedMap[attributeName]\n\n if (normalized !== undefined) attribute.normalized = normalized\n }\n\n resolve(geometry)\n },\n threeAttributeMap,\n attributeTypeMap,\n LinearSRGBColorSpace,\n reject,\n )\n })\n })\n }\n}\n\n/**\n * Texture Transform Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform\n */\nclass GLTFTextureTransformExtension {\n constructor() {\n this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM\n }\n\n extendTexture(texture, transform) {\n if (\n (transform.texCoord === undefined || transform.texCoord === texture.channel) &&\n transform.offset === undefined &&\n transform.rotation === undefined &&\n transform.scale === undefined\n ) {\n // See https://github.com/mrdoob/three.js/issues/21819.\n return texture\n }\n\n texture = texture.clone()\n\n if (transform.texCoord !== undefined) {\n texture.channel = transform.texCoord\n }\n\n if (transform.offset !== undefined) {\n texture.offset.fromArray(transform.offset)\n }\n\n if (transform.rotation !== undefined) {\n texture.rotation = transform.rotation\n }\n\n if (transform.scale !== undefined) {\n texture.repeat.fromArray(transform.scale)\n }\n\n texture.needsUpdate = true\n\n return texture\n }\n}\n\n/**\n * Mesh Quantization Extension\n *\n * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization\n */\nclass GLTFMeshQuantizationExtension {\n constructor() {\n this.name = EXTENSIONS.KHR_MESH_QUANTIZATION\n }\n}\n\n/*********************************/\n/********** INTERPOLATION ********/\n/*********************************/\n\n// Spline Interpolation\n// Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation\nclass GLTFCubicSplineInterpolant extends Interpolant {\n constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) {\n super(parameterPositions, sampleValues, sampleSize, resultBuffer)\n }\n\n copySampleValue_(index) {\n // Copies a sample value to the result buffer. See description of glTF\n // CUBICSPLINE values layout in interpolate_() function below.\n\n const result = this.resultBuffer,\n values = this.sampleValues,\n valueSize = this.valueSize,\n offset = index * valueSize * 3 + valueSize\n\n for (let i = 0; i !== valueSize; i++) {\n result[i] = values[offset + i]\n }\n\n return result\n }\n\n interpolate_(i1, t0, t, t1) {\n const result = this.resultBuffer\n const values = this.sampleValues\n const stride = this.valueSize\n\n const stride2 = stride * 2\n const stride3 = stride * 3\n\n const td = t1 - t0\n\n const p = (t - t0) / td\n const pp = p * p\n const ppp = pp * p\n\n const offset1 = i1 * stride3\n const o