summit/frontend/node_modules/three-stdlib/loaders/DRACOLoader.cjs.map

1 line
21 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"DRACOLoader.cjs","sources":["../../src/loaders/DRACOLoader.js"],"sourcesContent":["import { BufferAttribute, BufferGeometry, FileLoader, Loader } from 'three'\n\nconst _taskCache = new WeakMap()\n\nclass DRACOLoader extends Loader {\n constructor(manager) {\n super(manager)\n\n this.decoderPath = ''\n this.decoderConfig = {}\n this.decoderBinary = null\n this.decoderPending = null\n\n this.workerLimit = 4\n this.workerPool = []\n this.workerNextTaskID = 1\n this.workerSourceURL = ''\n\n this.defaultAttributeIDs = {\n position: 'POSITION',\n normal: 'NORMAL',\n color: 'COLOR',\n uv: 'TEX_COORD',\n }\n this.defaultAttributeTypes = {\n position: 'Float32Array',\n normal: 'Float32Array',\n color: 'Float32Array',\n uv: 'Float32Array',\n }\n }\n\n setDecoderPath(path) {\n this.decoderPath = path\n\n return this\n }\n\n setDecoderConfig(config) {\n this.decoderConfig = config\n\n return this\n }\n\n setWorkerLimit(workerLimit) {\n this.workerLimit = workerLimit\n\n return this\n }\n\n load(url, onLoad, onProgress, onError) {\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 (buffer) => {\n const taskConfig = {\n attributeIDs: this.defaultAttributeIDs,\n attributeTypes: this.defaultAttributeTypes,\n useUniqueIDs: false,\n }\n\n this.decodeGeometry(buffer, taskConfig).then(onLoad).catch(onError)\n },\n onProgress,\n onError,\n )\n }\n\n /** @deprecated Kept for backward-compatibility with previous DRACOLoader versions. */\n decodeDracoFile(buffer, callback, attributeIDs, attributeTypes) {\n const taskConfig = {\n attributeIDs: attributeIDs || this.defaultAttributeIDs,\n attributeTypes: attributeTypes || this.defaultAttributeTypes,\n useUniqueIDs: !!attributeIDs,\n }\n\n this.decodeGeometry(buffer, taskConfig).then(callback)\n }\n\n decodeGeometry(buffer, taskConfig) {\n // TODO: For backward-compatibility, support 'attributeTypes' objects containing\n // references (rather than names) to typed array constructors. These must be\n // serialized before sending them to the worker.\n for (const attribute in taskConfig.attributeTypes) {\n const type = taskConfig.attributeTypes[attribute]\n\n if (type.BYTES_PER_ELEMENT !== undefined) {\n taskConfig.attributeTypes[attribute] = type.name\n }\n }\n\n //\n\n const taskKey = JSON.stringify(taskConfig)\n\n // Check for an existing task using this buffer. A transferred buffer cannot be transferred\n // again from this thread.\n if (_taskCache.has(buffer)) {\n const cachedTask = _taskCache.get(buffer)\n\n if (cachedTask.key === taskKey) {\n return cachedTask.promise\n } else if (buffer.byteLength === 0) {\n // Technically, it would be possible to wait for the previous task to complete,\n // transfer the buffer back, and decode again with the second configuration. That\n // is complex, and I don't know of any reason to decode a Draco buffer twice in\n // different ways, so this is left unimplemented.\n throw new Error(\n 'THREE.DRACOLoader: Unable to re-decode a buffer with different ' +\n 'settings. Buffer has already been transferred.',\n )\n }\n }\n\n //\n\n let worker\n const taskID = this.workerNextTaskID++\n const taskCost = buffer.byteLength\n\n // Obtain a worker and assign a task, and construct a geometry instance\n // when the task completes.\n const geometryPending = this._getWorker(taskID, taskCost)\n .then((_worker) => {\n worker = _worker\n\n return new Promise((resolve, reject) => {\n worker._callbacks[taskID] = { resolve, reject }\n\n worker.postMessa