Files
fad_oa/ruoyi-ui/public/file-viewer/assets/3MFLoader--yjh7udp.js

1 line
13 KiB
JavaScript

import{$ as e,C as t,Ct as n,E as r,Ft as i,H as a,K as o,U as s,at as c,et as l,f as u,l as d,ot as f,p,rt as m,st as h,u as g,w as _,wt as v}from"./three.module-BFsVh7r1.js";import{t as y}from"./fflate.module-BIQmJeC9.js";var b=v,x=class extends o{constructor(e){super(e),this.availableExtensions=[]}load(e,n,r,i){let a=this,o=new t(a.manager);o.setPath(a.path),o.setResponseType(`arraybuffer`),o.setRequestHeader(a.requestHeader),o.setWithCredentials(a.withCredentials),o.load(e,function(t){try{n(a.parse(t))}catch(t){i?i(t):console.error(t),a.manager.itemError(e)}},r,i)}parse(t){let v=this,x=new i(this.manager);function S(e){let t=null,n=null,r,i,a=[],o=[],s,c={},l={},u={},d=new TextDecoder;try{t=y(new Uint8Array(e))}catch(e){if(e instanceof ReferenceError)return console.error(`THREE.3MFLoader: fflate missing and file is compressed.`),null}let f=null;for(n in t)n.match(/\_rels\/.rels$/)?r=n:n.match(/3D\/_rels\/.*\.model\.rels$/)?i=n:n.match(/^3D\/[^\/]*\.model$/)?f=n:n.match(/^3D\/.*\/.*\.model$/)?a.push(n):n.match(/^3D\/Textures?\/.*/)&&o.push(n);if(a.push(f),r===void 0)throw Error("THREE.ThreeMFLoader: Cannot find relationship file `rels` in 3MF archive.");let p=t[r],m=C(d.decode(p));if(i){let e=t[i];s=C(d.decode(e))}for(let e=0;e<a.length;e++){let n=a[e],r=t[n],i=d.decode(r),o=new DOMParser().parseFromString(i,`application/xml`);o.documentElement.nodeName.toLowerCase()!==`model`&&console.error(`THREE.3MFLoader: Error loading 3MF - no 3MF document found: `,n);let s=o.querySelector(`model`),l={};for(let e=0;e<s.attributes.length;e++){let t=s.attributes[e];t.name.match(/^xmlns:(.+)$/)&&(l[t.value]=RegExp.$1)}let u=R(s);u.xml=s,0<Object.keys(l).length&&(u.extensions=l),c[n]=u}for(let e=0;e<o.length;e++){let n=o[e];u[n]=t[n].buffer}return{rels:m,modelRels:s,model:c,printTicket:l,texture:u}}function C(e){let t=[],n=new DOMParser().parseFromString(e,`application/xml`).querySelectorAll(`Relationship`);for(let e=0;e<n.length;e++){let r=n[e],i={target:r.getAttribute(`Target`),id:r.getAttribute(`Id`),type:r.getAttribute(`Type`)};t.push(i)}return t}function w(e){let t={};for(let n=0;n<e.length;n++){let r=e[n],i=r.getAttribute(`name`);0<=[`Title`,`Designer`,`Description`,`Copyright`,`LicenseTerms`,`Rating`,`CreationDate`,`ModificationDate`].indexOf(i)&&(t[i]=r.textContent)}return t}function T(e){let t={id:e.getAttribute(`id`),basematerials:[]},n=e.querySelectorAll(`base`);for(let e=0;e<n.length;e++){let r=n[e],i=A(r);i.index=e,t.basematerials.push(i)}return t}function E(e){return{id:e.getAttribute(`id`),path:e.getAttribute(`path`),contenttype:e.getAttribute(`contenttype`),tilestyleu:e.getAttribute(`tilestyleu`),tilestylev:e.getAttribute(`tilestylev`),filter:e.getAttribute(`filter`)}}function ee(e){let t={id:e.getAttribute(`id`),texid:e.getAttribute(`texid`),displaypropertiesid:e.getAttribute(`displaypropertiesid`)},n=e.querySelectorAll(`tex2coord`),r=[];for(let e=0;e<n.length;e++){let t=n[e],i=t.getAttribute(`u`),a=t.getAttribute(`v`);r.push(parseFloat(i),parseFloat(a))}return t.uvs=new Float32Array(r),t}function te(e){let t={id:e.getAttribute(`id`),displaypropertiesid:e.getAttribute(`displaypropertiesid`)},n=e.querySelectorAll(`color`),r=[],i=new p;for(let e=0;e<n.length;e++){let t=n[e].getAttribute(`color`);i.setStyle(t.substring(0,7),b),r.push(i.r,i.g,i.b)}return t.colors=new Float32Array(r),t}function D(e){let t=e.children,n={};for(let e=0;e<t.length;e++){let r={type:t[e].nodeName.substring(2)};for(let n=0;n<t[e].attributes.length;n++){let i=t[e].attributes[n];i.specified&&(r[i.name]=i.value)}n[t[e].getAttribute(`identifier`)]=r}return n}function O(e){let t={id:e.getAttribute(`id`),displayname:e.getAttribute(`displayname`)},n=e.children,r={};for(let e=0;e<n.length;e++){let t=n[e];if(t.nodeName===`i:in`||t.nodeName===`i:out`)r[t.nodeName===`i:in`?`inputs`:`outputs`]=D(t);else{let e=t.children,n={op:t.nodeName.substring(2),identifier:t.getAttribute(`identifier`)};for(let t=0;t<e.length;t++)n[e[t].nodeName.substring(2)]=D(e[t]);r[n.identifier]=n}}return t.operations=r,t}function k(e){let t={id:e.getAttribute(`id`)},n=e.querySelectorAll(`pbmetallic`),r=[];for(let e=0;e<n.length;e++){let t=n[e];r.push({name:t.getAttribute(`name`),metallicness:parseFloat(t.getAttribute(`metallicness`)),roughness:parseFloat(t.getAttribute(`roughness`))})}return t.data=r,t}function A(e){let t={};return t.name=e.getAttribute(`name`),t.displaycolor=e.getAttribute(`displaycolor`),t.displaypropertiesid=e.getAttribute(`displaypropertiesid`),t}function j(e){let t={},n=[],r=e.querySelectorAll(`vertices vertex`);for(let e=0;e<r.length;e++){let t=r[e],i=t.getAttribute(`x`),a=t.getAttribute(`y`),o=t.getAttribute(`z`);n.push(parseFloat(i),parseFloat(a),parseFloat(o))}t.vertices=new Float32Array(n);let i=[],a=[],o=e.querySelectorAll(`triangles triangle`);for(let e=0;e<o.length;e++){let t=o[e],n=t.getAttribute(`v1`),r=t.getAttribute(`v2`),s=t.getAttribute(`v3`),c=t.getAttribute(`p1`),l=t.getAttribute(`p2`),u=t.getAttribute(`p3`),d=t.getAttribute(`pid`),f={};f.v1=parseInt(n,10),f.v2=parseInt(r,10),f.v3=parseInt(s,10),a.push(f.v1,f.v2,f.v3),c&&(f.p1=parseInt(c,10)),l&&(f.p2=parseInt(l,10)),u&&(f.p3=parseInt(u,10)),d&&(f.pid=d),0<Object.keys(f).length&&i.push(f)}return t.triangleProperties=i,t.triangles=new Uint32Array(a),t}function M(e){let t=[],n=e.querySelectorAll(`component`);for(let e=0;e<n.length;e++){let r=n[e],i=N(r);t.push(i)}return t}function N(e){let t={};t.objectId=e.getAttribute(`objectid`);let n=e.getAttribute(`transform`);return n&&(t.transform=P(n)),t}function P(t){let n=[];t.split(` `).forEach(function(e){n.push(parseFloat(e))});let r=new e;return r.set(n[0],n[3],n[6],n[9],n[1],n[4],n[7],n[10],n[2],n[5],n[8],n[11],0,0,0,1),r}function F(e){let t={type:e.getAttribute(`type`)},n=e.getAttribute(`id`);n&&(t.id=n);let r=e.getAttribute(`pid`);r&&(t.pid=r);let i=e.getAttribute(`pindex`);i&&(t.pindex=i);let a=e.getAttribute(`thumbnail`);a&&(t.thumbnail=a);let o=e.getAttribute(`partnumber`);o&&(t.partnumber=o);let s=e.getAttribute(`name`);s&&(t.name=s);let c=e.querySelector(`mesh`);c&&(t.mesh=j(c));let l=e.querySelector(`components`);return l&&(t.components=M(l)),t}function I(e){let t={};t.basematerials={};let n=e.querySelectorAll(`basematerials`);for(let e=0;e<n.length;e++){let r=n[e],i=T(r);t.basematerials[i.id]=i}t.texture2d={};let r=e.querySelectorAll(`texture2d`);for(let e=0;e<r.length;e++){let n=r[e],i=E(n);t.texture2d[i.id]=i}t.colorgroup={};let i=e.querySelectorAll(`colorgroup`);for(let e=0;e<i.length;e++){let n=i[e],r=te(n);t.colorgroup[r.id]=r}let a=e.querySelectorAll(`implicitfunction`);a.length>0&&(t.implicitfunction={});for(let e=0;e<a.length;e++){let n=a[e],r=O(n);t.implicitfunction[r.id]=r}t.pbmetallicdisplayproperties={};let o=e.querySelectorAll(`pbmetallicdisplayproperties`);for(let e=0;e<o.length;e++){let n=o[e],r=k(n);t.pbmetallicdisplayproperties[r.id]=r}t.texture2dgroup={};let s=e.querySelectorAll(`texture2dgroup`);for(let e=0;e<s.length;e++){let n=s[e],r=ee(n);t.texture2dgroup[r.id]=r}t.object={};let c=e.querySelectorAll(`object`);for(let e=0;e<c.length;e++){let n=c[e],r=F(n);t.object[r.id]=r}return t}function L(e){let t=[],n=e.querySelectorAll(`item`);for(let e=0;e<n.length;e++){let r=n[e],i={objectId:r.getAttribute(`objectid`)},a=r.getAttribute(`transform`);a&&(i.transform=P(a)),t.push(i)}return t}function R(e){let t={unit:e.getAttribute(`unit`)||`millimeter`},n=e.querySelectorAll(`metadata`);n&&(t.metadata=w(n));let r=e.querySelector(`resources`);r&&(t.resources=I(r));let i=e.querySelector(`build`);return i&&(t.build=L(i)),t}function z(e,t,r,i){let o=e.texid,c=r.resources.texture2d[o];if(c){let e=i[c.path],t=c.contenttype,r=new Blob([e],{type:t}),o=URL.createObjectURL(r),l=x.load(o,function(){URL.revokeObjectURL(o)});switch(l.colorSpace=b,c.tilestyleu){case`wrap`:l.wrapS=n;break;case`mirror`:l.wrapS=f;break;case`none`:case`clamp`:l.wrapS=u;break;default:l.wrapS=n}switch(c.tilestylev){case`wrap`:l.wrapT=n;break;case`mirror`:l.wrapT=f;break;case`none`:case`clamp`:l.wrapT=u;break;default:l.wrapT=n}switch(c.filter){case`auto`:l.magFilter=a,l.minFilter=s;break;case`linear`:l.magFilter=a,l.minFilter=a,l.generateMipmaps=!1;break;case`nearest`:l.magFilter=h,l.minFilter=h,l.generateMipmaps=!1;break;default:l.magFilter=a,l.minFilter=s}return l}else return null}function B(e,t,n,r,i,a,o){let s=o.pindex,c={};for(let e=0,n=t.length;e<n;e++){let n=t[e],r=n.p1===void 0?s:n.p1;c[r]===void 0&&(c[r]=[]),c[r].push(n)}let u=Object.keys(c),d=[];for(let t=0,s=u.length;t<s;t++){let s=u[t],f=c[s],p=e.basematerials[s],m=Y(p,r,i,a,o,X),h=new g,v=[],y=n.vertices;for(let e=0,t=f.length;e<t;e++){let t=f[e];v.push(y[t.v1*3+0]),v.push(y[t.v1*3+1]),v.push(y[t.v1*3+2]),v.push(y[t.v2*3+0]),v.push(y[t.v2*3+1]),v.push(y[t.v2*3+2]),v.push(y[t.v3*3+0]),v.push(y[t.v3*3+1]),v.push(y[t.v3*3+2])}h.setAttribute(`position`,new _(v,3));let b=new l(h,m);d.push(b)}return d}function V(e,t,n,r,i,a,o){let s=new g,c=[],u=[],d=n.vertices,f=e.uvs;for(let e=0,n=t.length;e<n;e++){let n=t[e];c.push(d[n.v1*3+0]),c.push(d[n.v1*3+1]),c.push(d[n.v1*3+2]),c.push(d[n.v2*3+0]),c.push(d[n.v2*3+1]),c.push(d[n.v2*3+2]),c.push(d[n.v3*3+0]),c.push(d[n.v3*3+1]),c.push(d[n.v3*3+2]),u.push(f[n.p1*2+0]),u.push(f[n.p1*2+1]),u.push(f[n.p2*2+0]),u.push(f[n.p2*2+1]),u.push(f[n.p3*2+0]),u.push(f[n.p3*2+1])}return s.setAttribute(`position`,new _(c,3)),s.setAttribute(`uv`,new _(u,2)),new l(s,new m({map:Y(e,r,i,a,o,z),flatShading:!0}))}function H(e,t,n,r){let i=new g,a=[],o=[],s=n.vertices,c=e.colors;for(let e=0,n=t.length;e<n;e++){let n=t[e],i=n.v1,l=n.v2,u=n.v3;a.push(s[i*3+0]),a.push(s[i*3+1]),a.push(s[i*3+2]),a.push(s[l*3+0]),a.push(s[l*3+1]),a.push(s[l*3+2]),a.push(s[u*3+0]),a.push(s[u*3+1]),a.push(s[u*3+2]);let d=n.p1===void 0?r.pindex:n.p1,f=n.p2===void 0?d:n.p2,p=n.p3===void 0?d:n.p3;o.push(c[d*3+0]),o.push(c[d*3+1]),o.push(c[d*3+2]),o.push(c[f*3+0]),o.push(c[f*3+1]),o.push(c[f*3+2]),o.push(c[p*3+0]),o.push(c[p*3+1]),o.push(c[p*3+2])}return i.setAttribute(`position`,new _(a,3)),i.setAttribute(`color`,new _(o,3)),new l(i,new m({vertexColors:!0,flatShading:!0}))}function U(e){let t=new g;return t.setIndex(new d(e.triangles,1)),t.setAttribute(`position`,new d(e.vertices,3)),new l(t,new m({name:o.DEFAULT_MATERIAL_NAME,color:16777215,flatShading:!0}))}function W(e,t,n,r,i,a){let o=Object.keys(e),s=[];for(let c=0,l=o.length;c<l;c++){let l=o[c],u=e[l];switch(G(l,r)){case`material`:let e=r.resources.basematerials[l],o=B(e,u,t,n,r,i,a);for(let e=0,t=o.length;e<t;e++)s.push(o[e]);break;case`texture`:let c=r.resources.texture2dgroup[l];s.push(V(c,u,t,n,r,i,a));break;case`vertexColors`:let d=r.resources.colorgroup[l];s.push(H(d,u,t,a));break;case`default`:s.push(U(t));break;default:console.error(`THREE.3MFLoader: Unsupported resource type.`)}}if(a.name)for(let e=0;e<s.length;e++)s[e].name=a.name;return s}function G(e,t){if(t.resources.texture2dgroup[e]!==void 0)return`texture`;if(t.resources.basematerials[e]!==void 0)return`material`;if(t.resources.colorgroup[e]!==void 0)return`vertexColors`;if(e==="default")return`default`}function K(e,t){let n={},r=e.triangleProperties,i=t.pid;for(let e=0,t=r.length;e<t;e++){let t=r[e],a=t.pid===void 0?i:t.pid;a===void 0&&(a=`default`),n[a]===void 0&&(n[a]=[]),n[a].push(t)}return n}function q(e,t,n,i,a){let o=new r,s=W(K(e,a),e,t,n,i,a);for(let e=0,t=s.length;e<t;e++)o.add(s[e]);return o}function J(e,t,n){if(!e)return;let r=[],i=Object.keys(e);for(let e=0;e<i.length;e++){let t=i[e];for(let e=0;e<v.availableExtensions.length;e++){let n=v.availableExtensions[e];n.ns===t&&r.push(n)}}for(let i=0;i<r.length;i++){let a=r[i];a.apply(n,e[a.ns],t)}}function Y(e,t,n,r,i,a){return e.build===void 0&&(e.build=a(e,t,n,r,i)),e.build}function X(e,t,n){let r,i=e.displaypropertiesid,a=n.resources.pbmetallicdisplayproperties;if(i!==null&&a[i]!==void 0){let t=a[i].data[e.index];r=new c({flatShading:!0,roughness:t.roughness,metalness:t.metallicness})}else r=new m({flatShading:!0});r.name=e.name;let o=e.displaycolor,s=o.substring(0,7);return r.color.setStyle(s,b),o.length===9&&(r.opacity=parseInt(o.charAt(7)+o.charAt(8),16)/255),r}function Z(e,t,n,i){let a=new r;for(let r=0;r<e.length;r++){let o=e[r],s=t[o.objectId];s===void 0&&(Q(o.objectId,t,n,i),s=t[o.objectId]);let c=s.clone(),l=o.transform;l&&c.applyMatrix4(l),a.add(c)}return a}function Q(e,t,n,r){let i=n.resources.object[e];if(i.mesh){let e=i.mesh,a=n.extensions,o=n.xml;J(a,e,o),t[i.id]=Y(e,t,n,r,i,q)}else{let e=i.components;t[i.id]=Y(e,t,n,r,i,Z)}i.name&&(t[i.id].name=i.name),n.resources.implicitfunction&&console.warn(`THREE.ThreeMFLoader: Implicit Functions are implemented in data-only.`,n.resources.implicitfunction)}function ne(e){let t=e.model,n=e.modelRels,r={},i=Object.keys(t),a={};if(n)for(let t=0,r=n.length;t<r;t++){let r=n[t],i=r.target.substring(1);e.texture[i]&&(a[r.target]=e.texture[i])}for(let e=0;e<i.length;e++){let n=t[i[e]],o=Object.keys(n.resources.object);for(let e=0;e<o.length;e++){let t=o[e];Q(t,r,n,a)}}return r}function re(e){for(let t=0;t<e.length;t++){let n=e[t];if(n.target.split(`.`).pop().toLowerCase()===`model`)return n}}function ie(e,t){let n=new r,i=re(t.rels),a=t.model[i.target.substring(1)].build;for(let t=0;t<a.length;t++){let r=a[t],i=e[r.objectId].clone(),o=r.transform;o&&i.applyMatrix4(o),n.add(i)}return n}let $=S(t);return ie(ne($),$)}addExtension(e){this.availableExtensions.push(e)}};export{x as ThreeMFLoader};