Files
fad_oa/ruoyi-ui/public/file-viewer/assets/PLYLoader-DwTzA-Dg.js

2 lines
6.4 KiB
JavaScript

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;e<o.length;e++){let t=o[e];if(t=t.trim(),t===``)continue;let n=t.split(/\s+/),r=n.shift();switch(t=n.join(` `),r){case`format`:a.format=n[0],a.version=n[1];break;case`comment`:a.comments.push(t);break;case`element`:s!==void 0&&a.elements.push(s),s={},s.name=n[0],s.count=parseInt(n[1]),s.properties=[];break;case`property`:s.properties.push(c(n,y.propertyNameMapping));break;case`obj_info`:a.objInfo=t;break;default:console.log(`unhandled`,r,n)}}return s!==void 0&&a.elements.push(s),a}function n(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 s(e,t){let r={};for(let i=0;i<e.length;i++){if(t.empty())return null;if(e[i].type===`list`){let a=[],o=n(t.next(),e[i].countType);for(let r=0;r<o;r++){if(t.empty())return null;a.push(n(t.next(),e[i].itemType))}r[e[i].name]=a}else r[e[i].name]=n(t.next(),e[i].type)}return r}function l(){let e={indices:[],vertices:[],normals:[],uvs:[],faceVertexUvs:[],colors:[],faceVertexColors:[]};for(let t of Object.keys(y.customPropertyMapping))e[t]=[];return e}function u(e){let t=e.map(e=>e.name);function n(e){for(let n=0,r=e.length;n<r;n++){let r=e[n];if(t.includes(r))return r}return null}return{attrX:n([`x`,`px`,`posx`])||`x`,attrY:n([`y`,`py`,`posy`])||`y`,attrZ:n([`z`,`pz`,`posz`])||`z`,attrNX:n([`nx`,`normalx`]),attrNY:n([`ny`,`normaly`]),attrNZ:n([`nz`,`normalz`]),attrS:n([`s`,`u`,`texture_u`,`tx`]),attrT:n([`t`,`v`,`texture_v`,`ty`]),attrR:n([`red`,`diffuse_red`,`r`,`diffuse_r`]),attrG:n([`green`,`diffuse_green`,`g`,`diffuse_g`]),attrB:n([`blue`,`diffuse_blue`,`b`,`diffuse_b`])}}function d(e,t){let n=l(),r=/end_header\s+(\S[\s\S]*\S|\S)\s*$/,i,a;i=(a=r.exec(e))===null?[]:a[1].split(/\s+/);let o=new c(i);loop:for(let e=0;e<t.elements.length;e++){let r=t.elements[e],i=u(r.properties);for(let e=0;e<r.count;e++){let e=s(r.properties,o);if(!e)break loop;p(n,r.name,e,i)}}return f(n)}function f(e){let t=new r;e.indices.length>0&&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;i<t.length;i++){let a=t[i],o=a.valueReader;if(a.type===`list`){let t=[],i=a.countReader.read(e+r);r+=a.countReader.size;for(let n=0;n<i;n++)t.push(o.read(e+r)),r+=o.size;n[a.name]=t}else n[a.name]=o.read(e+r),r+=o.size}return[n,r]}function h(e,t,n){function r(e,t,n){switch(t){case`int8`:case`char`:return{read:t=>e.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<a;i++){let a=e[i];a.type===`list`?(a.countReader=r(t,a.countType,n),a.valueReader=r(t,a.itemType,n)):a.valueReader=r(t,a.type,n)}}function g(e,t){let n=l(),r=t.format===`binary_little_endian`,i=new DataView(e,t.headerLength),a,o=0;for(let e=0;e<t.elements.length;e++){let s=t.elements[e],c=s.properties,l=u(c);h(c,i,r);for(let e=0;e<s.count;e++){a=m(o,c),o+=a[1];let e=a[0];p(n,s.name,e,l)}}return f(n)}function _(e){let t=0,n=!0,r=``,i=[],a=new TextDecoder().decode(e.subarray(0,5)),o=/^ply\r\n/.test(a);do{let a=String.fromCharCode(e[t++]);a!==`
`&&a!==`\r`?r+=a:(r===`end_header`&&(n=!1),r!==``&&(i.push(r),r=``))}while(n&&t<e.length);return o===!0&&t++,{headerText:i.join(`\r`)+`\r`,headerLength:t}}let v,y=this;if(e instanceof ArrayBuffer){let n=new Uint8Array(e),{headerText:r,headerLength:i}=_(n),a=t(r,i);v=a.format===`ascii`?d(new TextDecoder().decode(n),a):g(e,a)}else v=d(e,t(e));return v}},c=class{constructor(e){this.arr=e,this.i=0}empty(){return this.i>=this.arr.length}next(){return this.arr[this.i++]}};export{s as PLYLoader};