/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/threejs-ply-loader@2.0.2/src/index.mjs
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import Blob from"cross-blob";import{bufferToArrayBuffer}from"./helpers/index.mjs";export const PLYLoaderFactory=e=>{class t extends e.Loader{constructor(e){super(e),this.propertyNameMapping={}}load(t,n,s,r){const o=this,a=new e.FileLoader(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(t,(function(e){try{n(o.parse(e))}catch(e){r?r(e):console.error(e),o.manager.itemError(t)}}),s,r)}setPropertyNameMapping(e){this.propertyNameMapping=e}parse(t){function n(e){let t="",n=0;const s=/^ply([\s\S]*)end_header\r?\n/.exec(e);null!==s&&(t=s[1],n=new Blob([s[0]]).size);const r={comments:[],elements:[],headerLength:n,objInfo:""},o=t.split("\n");let a;function i(e,t){const n={type:e[0]};return"list"===n.type?(n.name=e[3],n.countType=e[1],n.itemType=e[2]):n.name=e[1],n.name in t&&(n.name=t[n.name]),n}for(let e=0;e<o.length;e++){let t=o[e];if(t=t.trim(),""===t)continue;const n=t.split(/\s+/),s=n.shift();switch(t=n.join(" "),s){case"format":r.format=n[0],r.version=n[1];break;case"comment":r.comments.push(t);break;case"element":void 0!==a&&r.elements.push(a),a={},a.name=n[0],a.count=parseInt(n[1]),a.properties=[];break;case"property":a.properties.push(i(n,f.propertyNameMapping));break;case"obj_info":r.objInfo=t;break;default:console.log("unhandled",s,n)}}return void 0!==a&&r.elements.push(a),r}function s(e,t){switch(t){case"char":case"uchar":case"short":case"ushort":case"int":case"uint":case"int8":case"uint8":case"int16":case"uint16":case"int32":case"uint32":return parseInt(e);case"float":case"double":case"float32":case"float64":return parseFloat(e)}}function r(e,t){const n=t.split(/\s+/),r={};for(let t=0;t<e.length;t++)if("list"===e[t].type){const o=[],a=s(n.shift(),e[t].countType);for(let r=0;r<a;r++)o.push(s(n.shift(),e[t].itemType));r[e[t].name]=o}else r[e[t].name]=s(n.shift(),e[t].type);return r}function o(e,t){const n={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[]};let s;let o="";null!==(s=/end_header\s([\s\S]*)$/.exec(e))&&(o=s[1]);const u=o.split("\n");let c=0,l=0;for(let e=0;e<u.length;e++){let s=u[e];if(s=s.trim(),""===s)continue;l>=t.elements[c].count&&(c++,l=0);const o=r(t.elements[c].properties,s);i(n,t.elements[c].name,o),l++}return a(n)}function a(t){let n=new e.BufferGeometry;return t.indices.length>0&&n.setIndex(t.indices),n.setAttribute("position",new e.Float32BufferAttribute(t.vertices,3)),t.normals.length>0&&n.setAttribute("normal",new e.Float32BufferAttribute(t.normals,3)),t.uvs.length>0&&n.setAttribute("uv",new e.Float32BufferAttribute(t.uvs,2)),t.colors.length>0&&n.setAttribute("color",new e.Float32BufferAttribute(t.colors,3)),t.faceVertexUvs.length>0&&(n=n.toNonIndexed(),n.setAttribute("uv",new e.Float32BufferAttribute(t.faceVertexUvs,2))),n.computeBoundingSphere(),n}function i(e,t,n){function s(e){for(let t=0,s=e.length;t<s;t++){const s=e[t];if(s in n)return s}return null}const r=s(["x","px","posx"])||"x",o=s(["y","py","posy"])||"y",a=s(["z","pz","posz"])||"z",i=s(["nx","normalx"]),u=s(["ny","normaly"]),c=s(["nz","normalz"]),l=s(["s","u","texture_u","tx"]),f=s(["t","v","texture_v","ty"]),p=s(["red","diffuse_red","r","diffuse_r"]),h=s(["green","diffuse_green","g","diffuse_g"]),m=s(["blue","diffuse_blue","b","diffuse_b"]);if("vertex"===t)e.vertices.push(n[r],n[o],n[a]),null!==i&&null!==u&&null!==c&&e.normals.push(n[i],n[u],n[c]),null!==l&&null!==f&&e.uvs.push(n[l],n[f]),null!==p&&null!==h&&null!==m&&e.colors.push(n[p]/255,n[h]/255,n[m]/255);else if("face"===t){const t=n.vertex_indices||n.vertex_index,s=n.texcoord;3===t.length?(e.indices.push(t[0],t[1],t[2]),s&&6===s.length&&(e.faceVertexUvs.push(s[0],s[1]),e.faceVertexUvs.push(s[2],s[3]),e.faceVertexUvs.push(s[4],s[5]))):4===t.length&&(e.indices.push(t[0],t[1],t[3]),e.indices.push(t[1],t[2],t[3]))}}function u(e,t,n,s){switch(n){case"int8":case"char":return[e.getInt8(t),1];case"uint8":case"uchar":return[e.getUint8(t),1];case"int16":case"short":return[e.getInt16(t,s),2];case"uint16":case"ushort":return[e.getUint16(t,s),2];case"int32":case"int":return[e.getInt32(t,s),4];case"uint32":case"uint":return[e.getUint32(t,s),4];case"float32":case"float":return[e.getFloat32(t,s),4];case"float64":case"double":return[e.getFloat64(t,s),8]}}function c(e,t,n,s){const r={};let o,a=0;for(let i=0;i<n.length;i++)if("list"===n[i].type){const c=[];o=u(e,t+a,n[i].countType,s);const l=o[0];a+=o[1];for(let r=0;r<l;r++)o=u(e,t+a,n[i].itemType,s),c.push(o[0]),a+=o[1];r[n[i].name]=c}else o=u(e,t+a,n[i].type,s),r[n[i].name]=o[0],a+=o[1];return[r,a]}let l;const f=this;if(t instanceof ArrayBuffer){const s=e.LoaderUtils.decodeText(new Uint8Array(t)),r=n(s);l="ascii"===r.format?o(s,r):function(e,t){const n={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[]},s="binary_little_endian"===t.format,r=new DataView(e,t.headerLength);let o,u=0;for(let e=0;e<t.elements.length;e++)for(let a=0;a<t.elements[e].count;a++){o=c(r,u,t.elements[e].properties,s),u+=o[1];const a=o[0];i(n,t.elements[e].name,a)}return a(n)}(t,r)}else l=o(t,n(t));return l}bufferToArrayBuffer(e){return bufferToArrayBuffer(e)}}return t};
//# sourceMappingURL=/sm/d5743560dc83358227a5bb816f9c45e89f200737649d917fbe32bee3432c6147.map