Files
fad_oa/ruoyi-ui/public/file-viewer/assets/VTKLoader-BfnzBXsa.js

3 lines
9.8 KiB
JavaScript
Raw Normal View History

import{C as e,K as t,l as n,p as r,u as i,w as a,wt as o}from"./three.module-BFsVh7r1.js";import{n as s}from"./fflate.module-BIQmJeC9.js";var c=class extends t{constructor(e){super(e),console.warn(`THREE.VTKLoader: The loader has been deprecated and will be removed with r194. Export your VTK files to glTF before using them on the web.`)}load(t,n,r,i){let a=this,o=new e(a.manager);o.setPath(a.path),o.setResponseType(`arraybuffer`),o.setRequestHeader(a.requestHeader),o.setWithCredentials(a.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)}parse(e){function t(e){let t=[],n=[],s=[],c=[],l,u=/^[^\d.\s-]+/;function d(e){let t=[],n=e.split(/\s+/);for(let e=0;e<n.length;e++)n[e]!==``&&t.push(parseFloat(n[e]));return t}let f=/^(\d+)\s+([\s\d]*)/,p=/^POINTS /,m=/^POLYGONS /,h=/^TRIANGLE_STRIPS /,g=/^POINT_DATA[ ]+(\d+)/,_=/^CELL_DATA[ ]+(\d+)/,v=/^COLOR_SCALARS[ ]+(\w+)[ ]+3/,y=/^NORMALS[ ]+(\w+)[ ]+(\w+)/,b=!1,x=!1,S=!1,C=!1,w=!1,T=!1,E=!1,D=new r,O=e.split(`
`);for(let e in O){let r=O[e].trim();if(r.indexOf(`DATASET`)===0){let e=r.split(` `)[1];if(e!==`POLYDATA`)throw Error(`Unsupported DATASET type: `+e)}else if(b){if(u.exec(r)===null){let e=d(r);for(let t=0;t+2<e.length;t+=3)n.push(e[t],e[t+1],e[t+2])}}else if(x){if((l=f.exec(r))!==null){let e=parseInt(l[1]),n=l[2].split(/\s+/);if(e>=3){let r=parseInt(n[0]),i=1;for(let a=0;a<e-2;++a){let e=parseInt(n[i]),a=parseInt(n[i+1]);t.push(r,e,a),i++}}}}else if(S){if((l=f.exec(r))!==null){let e=parseInt(l[1]),n=l[2].split(/\s+/);if(e>=3)for(let r=0;r<e-2;r++)if(r%2==1){let e=parseInt(n[r]),i=parseInt(n[r+2]),a=parseInt(n[r+1]);t.push(e,i,a)}else{let e=parseInt(n[r]),i=parseInt(n[r+1]),a=parseInt(n[r+2]);t.push(e,i,a)}}}else if(C||w){if(T){if(u.exec(r)===null){let e=d(r);for(let t=0;t+2<e.length;t+=3)D.setRGB(e[t],e[t+1],e[t+2],o),s.push(D.r,D.g,D.b)}}else if(E&&u.exec(r)===null){let e=d(r);for(let t=0;t+2<e.length;t+=3)c.push(e[t],e[t+1],e[t+2])}}m.exec(r)===null?p.exec(r)===null?h.exec(r)===null?g.exec(r)===null?_.exec(r)===null?v.exec(r)===null?y.exec(r)!==null&&(E=!0,T=!1,b=!1,x=!1,S=!1):(T=!0,E=!1,b=!1,x=!1,S=!1):(w=!0,b=!1,x=!1,S=!1):(C=!0,b=!1,x=!1,S=!1):(x=!1,b=!1,S=!0):(x=!1,b=!0,S=!1):(x=!0,b=!1,S=!1)}let k=new i;if(k.setIndex(t),k.setAttribute(`position`,new a(n,3)),c.length===n.length&&k.setAttribute(`normal`,new a(c,3)),s.length!==t.length)s.length===n.length&&k.setAttribute(`color`,new a(s,3));else{k=k.toNonIndexed();let e=k.attributes.position.count/3;if(s.length===e*3){let t=[];for(let n=0;n<e;n++){let e=s[3*n+0],r=s[3*n+1],i=s[3*n+2];D.setRGB(e,r,i,o),t.push(D.r,D.g,D.b),t.push(D.r,D.g,D.b),t.push(D.r,D.g,D.b)}k.setAttribute(`color`,new a(t,3))}}return k}function c(e){let t=new Uint8Array(e),r=new DataView(e),a=[],o=[],s=[],c=0;function l(e,t){let n=t,r=e[n],i=[];for(;r!==10&&n<e.length;)i.push(String.fromCharCode(r)),n++,r=e[n];return{start:t,end:n,next:n+1,parsedString:i.join(``)}}let u,d;for(;;){if(u=l(t,c),d=u.parsedString,d.indexOf(`DATASET`)===0){let e=d.split(` `)[1];if(e!==`POLYDATA`)throw Error(`Unsupported DATASET type: `+e)}else if(d.indexOf(`POINTS`)===0){let e=parseInt(d.split(` `)[1],10),t=e*4*3;a=new Float32Array(e*3);let n=u.next;for(let t=0;t<e;t++)a[3*t]=r.getFloat32(n,!1),a[3*t+1]=r.getFloat32(n+4,!1),a[3*t+2]=r.getFloat32(n+8,!1),n+=12;u.next=u.next+t+1}else if(d.indexOf(`TRIANGLE_STRIPS`)===0){let e=parseInt(d.split(` `)[1],10),t=parseInt(d.split(` `)[2],10),n=t*4;s=new Uint32Array(3*t-9*e);let i=0,a=u.next;for(let t=0;t<e;t++){let e=r.getInt32(a,!1),t=[];a+=4;for(let n=0;n<e;n++)t.push(r.getInt32(a,!1)),a+=4;for(let n=0;n<e-2;n++)n%2?(s[i++]=t[n],s[i++]=t[n+2],s[i++]=t[n+1]):(s[i++]=t[n],s[i++]=t[n+1],s[i++]=t[n+2])}u.next=u.next+n+1}else if(d.indexOf(`POLYGONS`)===0){let e=parseInt(d.split(` `)[1],10),t=parseInt(d.split(` `)[2],10),n=t*4;s=new Uint32Array(3*t-9*e);let i=0,a=u.next;for(let t=0;t<e;t++){let e=r.getInt32(a,!1),t=[];a+=4;for(let n=0;n<e;n++)t.push(r.getInt32(a,!1)),a+=4;for(let n=1;n<e-1;n++)s[i++]=t[0],s[i++]=t[n],s[i++]=t[n+1]}u.next=u.next+n+1}else if(d.indexOf(`POINT_DATA`)===0){let e=parseInt(d.split(` `)[1],10);u=l(t,u.next);let n=e*4*3;o=new Float32Array(e*3);let i=u.next;for(let t=0;t<e;t++)o[3*t]=r.getFloat32(i,!1),o[3*t+1]=r.getFloat32(i+4,!1),o[3*t+2]=r.getFloat32(i+8,!1),i+=12;u.next+=n}if(c=u.next,c>=t.byteLength)break}let f=new i;return f.setIndex(new n(s,1)),f.setAttribute(`position`,new n(a,3)),o.length===a.length&&f.setAttribute(`normal`,new n(o,3)),f}function l(e,t){let n=e.length,r=new Float32Array(n+t.length);return r.set(e),r.set(t,n),r}function u(e,t){let n=e.length,r=new Int32Array(n+t.length);return r.set(e),r.set(t,n),r}function d(e){function t(e){let n={};if(e.nodeType===1){if(e.attributes&&e.attributes.length>0){n.attributes={};for(let t=0;t<e.attributes.length;t++){let r=e.attributes.item(t);n.attributes[r.nodeName]=r.nodeValue.trim()}}}else e.nodeType===3&&(n=e.nodeValue.trim());if(e.hasChildNodes())for(let r=0;r<e.childNodes.length;r++){let i=e.childNodes.item(r),a=i.nodeName;if(n[a]===void 0){let e=t(i);e!==``&&(Array.isArray(e[`#text`])&&(e[`#text`]
`);return p[0].indexOf(`xml`)===-1?p[2].includes(`ASCII`)?t(f.decode(e)):c(e):d(f.decode(e))}};export{c as VTKLoader};