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

1 line
20 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"PLYLoader.cjs","sources":["../../src/loaders/PLYLoader.js"],"sourcesContent":["import { BufferGeometry, FileLoader, Float32BufferAttribute, Loader, LoaderUtils } from 'three'\nimport { decodeText } from '../_polyfill/LoaderUtils'\n\n/**\n * Description: A THREE loader for PLY ASCII files (known as the Polygon\n * File Format or the Stanford Triangle Format).\n *\n * Limitations: ASCII decoding assumes file is UTF-8.\n *\n * Usage:\n *\tconst loader = new PLYLoader();\n *\tloader.load('./models/ply/ascii/dolphins.ply', function (geometry) {\n *\n *\t\tscene.add( new THREE.Mesh( geometry ) );\n *\n *\t} );\n *\n * If the PLY file uses non standard property names, they can be mapped while\n * loading. For example, the following maps the properties\n * “diffuse_(red|green|blue)” in the file to standard color names.\n *\n * loader.setPropertyNameMapping( {\n *\tdiffuse_red: 'red',\n *\tdiffuse_green: 'green',\n *\tdiffuse_blue: 'blue'\n * } );\n *\n */\n\nclass PLYLoader extends Loader {\n constructor(manager) {\n super(manager)\n\n this.propertyNameMapping = {}\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n\n const loader = new FileLoader(this.manager)\n loader.setPath(this.path)\n loader.setResponseType('arraybuffer')\n loader.setRequestHeader(this.requestHeader)\n loader.setWithCredentials(this.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 setPropertyNameMapping(mapping) {\n this.propertyNameMapping = mapping\n }\n\n parse(data) {\n function parseHeader(data) {\n const patternHeader = /ply([\\s\\S]*)end_header\\r?\\n/\n let headerText = ''\n let headerLength = 0\n const result = patternHeader.exec(data)\n\n if (result !== null) {\n headerText = result[1]\n headerLength = new Blob([result[0]]).size\n }\n\n const header = {\n comments: [],\n elements: [],\n headerLength: headerLength,\n objInfo: '',\n }\n\n const lines = headerText.split('\\n')\n let currentElement\n\n function make_ply_element_property(propertValues, propertyNameMapping) {\n const property = { type: propertValues[0] }\n\n if (property.type === 'list') {\n property.name = propertValues[3]\n property.countType = propertValues[1]\n property.itemType = propertValues[2]\n } else {\n property.name = propertValues[1]\n }\n\n if (property.name in propertyNameMapping) {\n property.name = propertyNameMapping[property.name]\n }\n\n return property\n }\n\n for (let i = 0; i < lines.length; i++) {\n let line = lines[i]\n line = line.trim()\n\n if (line === '') continue\n\n const lineValues = line.split(/\\s+/)\n const lineType = lineValues.shift()\n line = lineValues.join(' ')\n\n switch (lineType) {\n case 'format':\n header.format = lineValues[0]\n header.version = lineValues[1]\n\n break\n\n case 'comment':\n header.comments.push(line)\n\n break\n\n case 'element':\n if (currentElement !== undefined) {\n header.elements.push(currentElement)\n }\n\n currentElement = {}\n currentElement.name = lineValues[0]\n currentElement.count = parseInt(lineValues[1])\n currentElement.properties = []\n\n break\n\n case 'property':\n currentElement.properties.push(make_ply_element_property(lineValues, scope.propertyNameMapping))\n\n break\n\n case 'obj_info':\n header.objInfo = line\n\n break\n\n