import{C as e,K as t,p as n,u as r,w as i,wt as a}from"./three.module-BFsVh7r1.js";var o=new n,s=class extends t{constructor(e){super(e),this.propertyNameMapping={},this.customPropertyMapping={}}load(t,n,r,i){let a=this,o=new e(this.manager);o.setPath(this.path),o.setResponseType(`arraybuffer`),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,function(e){try{n(a.parse(e))}catch(e){i?i(e):console.error(e),a.manager.itemError(t)}},r,i)}setPropertyNameMapping(e){this.propertyNameMapping=e}setCustomPropertyNameMapping(e){this.customPropertyMapping=e}parse(e){function t(e,t=0){let n=/^ply([\s\S]*)end_header(\r\n|\r|\n)/,r=``,i=n.exec(e);i!==null&&(r=i[1]);let a={comments:[],elements:[],headerLength:t,objInfo:``},o=r.split(/\r\n|\r|\n/),s;function c(e,t){let n={type:e[0]};return n.type===`list`?(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;ee.name);function n(e){for(let n=0,r=e.length;n0&&t.setIndex(e.indices),t.setAttribute(`position`,new i(e.vertices,3)),e.normals.length>0&&t.setAttribute(`normal`,new i(e.normals,3)),e.uvs.length>0&&t.setAttribute(`uv`,new i(e.uvs,2)),e.colors.length>0&&t.setAttribute(`color`,new i(e.colors,3)),(e.faceVertexUvs.length>0||e.faceVertexColors.length>0)&&(t=t.toNonIndexed(),e.faceVertexUvs.length>0&&t.setAttribute(`uv`,new i(e.faceVertexUvs,2)),e.faceVertexColors.length>0&&t.setAttribute(`color`,new i(e.faceVertexColors,3)));for(let n of Object.keys(y.customPropertyMapping))e[n].length>0&&t.setAttribute(n,new i(e[n],y.customPropertyMapping[n].length));return t.computeBoundingSphere(),t}function p(e,t,n,r){if(t===`vertex`){e.vertices.push(n[r.attrX],n[r.attrY],n[r.attrZ]),r.attrNX!==null&&r.attrNY!==null&&r.attrNZ!==null&&e.normals.push(n[r.attrNX],n[r.attrNY],n[r.attrNZ]),r.attrS!==null&&r.attrT!==null&&e.uvs.push(n[r.attrS],n[r.attrT]),r.attrR!==null&&r.attrG!==null&&r.attrB!==null&&(o.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255,a),e.colors.push(o.r,o.g,o.b));for(let t of Object.keys(y.customPropertyMapping))for(let r of y.customPropertyMapping[t])e[t].push(n[r])}else if(t===`face`){let t=n.vertex_indices||n.vertex_index,i=n.texcoord;t.length===3?(e.indices.push(t[0],t[1],t[2]),i&&i.length===6&&(e.faceVertexUvs.push(i[0],i[1]),e.faceVertexUvs.push(i[2],i[3]),e.faceVertexUvs.push(i[4],i[5]))):t.length===4&&(e.indices.push(t[0],t[1],t[3]),e.indices.push(t[1],t[2],t[3])),r.attrR!==null&&r.attrG!==null&&r.attrB!==null&&(o.setRGB(n[r.attrR]/255,n[r.attrG]/255,n[r.attrB]/255,a),e.faceVertexColors.push(o.r,o.g,o.b),e.faceVertexColors.push(o.r,o.g,o.b),e.faceVertexColors.push(o.r,o.g,o.b))}}function m(e,t){let n={},r=0;for(let i=0;ie.getInt8(t),size:1};case`uint8`:case`uchar`:return{read:t=>e.getUint8(t),size:1};case`int16`:case`short`:return{read:t=>e.getInt16(t,n),size:2};case`uint16`:case`ushort`:return{read:t=>e.getUint16(t,n),size:2};case`int32`:case`int`:return{read:t=>e.getInt32(t,n),size:4};case`uint32`:case`uint`:return{read:t=>e.getUint32(t,n),size:4};case`float32`:case`float`:return{read:t=>e.getFloat32(t,n),size:4};case`float64`:case`double`:return{read:t=>e.getFloat64(t,n),size:8}}}for(let i=0,a=e.length;i=this.arr.length}next(){return this.arr[this.i++]}};export{s as PLYLoader};