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

1 line
46 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"VTKLoader.cjs","sources":["../../src/loaders/VTKLoader.js"],"sourcesContent":["import { BufferAttribute, BufferGeometry, FileLoader, Float32BufferAttribute, Loader, LoaderUtils } from 'three'\nimport { unzlibSync } from 'fflate'\nimport { decodeText } from '../_polyfill/LoaderUtils'\n\nclass VTKLoader extends Loader {\n constructor(manager) {\n super(manager)\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n\n const loader = new FileLoader(scope.manager)\n loader.setPath(scope.path)\n loader.setResponseType('arraybuffer')\n loader.setRequestHeader(scope.requestHeader)\n loader.setWithCredentials(scope.withCredentials)\n loader.load(\n url,\n function (text) {\n try {\n onLoad(scope.parse(text))\n } catch (e) {\n if (onError) {\n onError(e)\n } else {\n console.error(e)\n }\n\n scope.manager.itemError(url)\n }\n },\n onProgress,\n onError,\n )\n }\n\n parse(data) {\n function parseASCII(data) {\n // connectivity of the triangles\n var indices = []\n\n // triangles vertices\n var positions = []\n\n // red, green, blue colors in the range 0 to 1\n var colors = []\n\n // normal vector, one per vertex\n var normals = []\n\n var result\n\n // pattern for detecting the end of a number sequence\n var patWord = /^[^\\d.\\s-]+/\n\n // pattern for reading vertices, 3 floats or integers\n var pat3Floats = /(\\-?\\d+\\.?[\\d\\-\\+e]*)\\s+(\\-?\\d+\\.?[\\d\\-\\+e]*)\\s+(\\-?\\d+\\.?[\\d\\-\\+e]*)/g\n\n // pattern for connectivity, an integer followed by any number of ints\n // the first integer is the number of polygon nodes\n var patConnectivity = /^(\\d+)\\s+([\\s\\d]*)/\n\n // indicates start of vertex data section\n var patPOINTS = /^POINTS /\n\n // indicates start of polygon connectivity section\n var patPOLYGONS = /^POLYGONS /\n\n // indicates start of triangle strips section\n var patTRIANGLE_STRIPS = /^TRIANGLE_STRIPS /\n\n // POINT_DATA number_of_values\n var patPOINT_DATA = /^POINT_DATA[ ]+(\\d+)/\n\n // CELL_DATA number_of_polys\n var patCELL_DATA = /^CELL_DATA[ ]+(\\d+)/\n\n // Start of color section\n var patCOLOR_SCALARS = /^COLOR_SCALARS[ ]+(\\w+)[ ]+3/\n\n // NORMALS Normals float\n var patNORMALS = /^NORMALS[ ]+(\\w+)[ ]+(\\w+)/\n\n var inPointsSection = false\n var inPolygonsSection = false\n var inTriangleStripSection = false\n var inPointDataSection = false\n var inCellDataSection = false\n var inColorSection = false\n var inNormalsSection = false\n\n var lines = data.split('\\n')\n\n for (var i in lines) {\n var line = lines[i].trim()\n\n if (line.indexOf('DATASET') === 0) {\n var dataset = line.split(' ')[1]\n\n if (dataset !== 'POLYDATA') throw new Error('Unsupported DATASET type: ' + dataset)\n } else if (inPointsSection) {\n // get the vertices\n while ((result = pat3Floats.exec(line)) !== null) {\n if (patWord.exec(line) !== null) break\n\n var x = parseFloat(result[1])\n var y = parseFloat(result[2])\n var z = parseFloat(result[3])\n positions.push(x, y, z)\n }\n } else if (inPolygonsSection) {\n if ((result = patConnectivity.exec(line)) !== null) {\n // numVertices i0 i1 i2 ...\n var numVertices = parseInt(result[1])\n var inds = result[2].split(/\\s+/)\n\n if (numVertices >= 3) {\n var i0 = parseInt(inds[0])\n var i1, i2\n var k = 1\n // split the polygon in numVertices - 2 triangles\n for (var j = 0; j < numVertices - 2; ++j) {\n i1 = parseInt(inds[k])\n i2 = parseInt(inds[k + 1])\n indices.push(i0, i1, i2)\n k++\n