1 line
51 KiB
Plaintext
1 line
51 KiB
Plaintext
|
|
{"version":3,"file":"3DMLoader.cjs","sources":["../../src/loaders/3DMLoader.js"],"sourcesContent":["import {\n BufferGeometryLoader,\n FileLoader,\n Loader,\n Object3D,\n MeshStandardMaterial,\n Mesh,\n Color,\n Points,\n PointsMaterial,\n Line,\n LineBasicMaterial,\n Matrix4,\n DirectionalLight,\n PointLight,\n SpotLight,\n RectAreaLight,\n Vector3,\n Sprite,\n SpriteMaterial,\n CanvasTexture,\n LinearFilter,\n ClampToEdgeWrapping,\n TextureLoader,\n} from 'three'\n\nconst _taskCache = new WeakMap()\n\nclass Rhino3dmLoader extends Loader {\n constructor(manager) {\n super(manager)\n\n this.libraryPath = ''\n this.libraryPending = null\n this.libraryBinary = null\n this.libraryConfig = {}\n\n this.url = ''\n\n this.workerLimit = 4\n this.workerPool = []\n this.workerNextTaskID = 1\n this.workerSourceURL = ''\n this.workerConfig = {}\n\n this.materials = []\n }\n\n setLibraryPath(path) {\n this.libraryPath = path\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\n this.url = url\n\n loader.load(\n url,\n (buffer) => {\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 return cachedTask.promise.then(onLoad).catch(onError)\n }\n\n this.decodeObjects(buffer, url).then(onLoad).catch(onError)\n },\n onProgress,\n onError,\n )\n }\n\n debug() {\n console.log(\n 'Task load: ',\n this.workerPool.map((worker) => worker._taskLoad),\n )\n }\n\n decodeObjects(buffer, url) {\n let worker\n let taskID\n\n const taskCost = buffer.byteLength\n\n const objectPending = this._getWorker(taskCost)\n .then((_worker) => {\n worker = _worker\n taskID = this.workerNextTaskID++ //hmmm\n\n return new Promise((resolve, reject) => {\n worker._callbacks[taskID] = { resolve, reject }\n\n worker.postMessage({ type: 'decode', id: taskID, buffer }, [buffer])\n\n //this.debug();\n })\n })\n .then((message) => this._createGeometry(message.data))\n\n // Remove task from the task list.\n // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)\n objectPending\n .catch(() => true)\n .then(() => {\n if (worker && taskID) {\n this._releaseTask(worker, taskID)\n\n //this.debug();\n }\n })\n\n // Cache the task result.\n _taskCache.set(buffer, {\n url: url,\n promise: objectPending,\n })\n\n return objectPending\n }\n\n parse(data, onLoad, onError) {\n this.decodeObjects(data, '').then(onLoad).catch(onError)\n }\n\n _compareMaterials(material) {\n const mat = {}\n mat.name = material.name\n mat.color = {}\n mat.color.r = material.color.r\n mat.color.g = material.color.g\n mat.color.b = material.color.b\n mat.type = material.type\n\n for (let i = 0; i < this.materials.length; i++) {\n const m = this.materials[i]\n const _mat = {}\n _mat.name = m.name\n _mat.color = {}\n _mat.color.r = m.color.r\n _mat.color.g = m.color.g\n _mat.color.b = m.color.b\n _mat.type = m.type\n\n if (JSON.stringify(mat) === JSON.stringify(_mat)) {\n return m\n }\n }\n\n this.materials.push(material)\n\n return material\n }\n\n _createMaterial(material) {\n if (material === undefined) {\n return new MeshStandardMaterial({\n color: new Color(1, 1, 1),\n metalness: 0.8,\n name: 'default',\n side: 2,\n })\n }\n\n const _diffuseColor = material.diffuseColor\n\n
|