diff --git a/dist/style.css b/dist/style.css index 446a66b..a7ffb43 100644 --- a/dist/style.css +++ b/dist/style.css @@ -1 +1 @@ -.viewer-container[data-v-4f87bc73]{position:relative;width:100%;height:100%;margin:0;border:0;padding:0}.viewer-container div[data-v-4f87bc73]{position:absolute!important;left:0px!important;opacity:1!important}.viewer-canvas[data-v-4f87bc73]{width:100%;height:100%} +.viewer-container[data-v-29f70b62]{position:relative;width:100%;height:100%;margin:0;border:0;padding:0}.viewer-container div[data-v-29f70b62]{position:absolute!important;left:0px!important;opacity:1!important}.viewer-canvas[data-v-29f70b62]{width:100%;height:100%} diff --git a/dist/vue-3d-loader.cjs.js b/dist/vue-3d-loader.cjs.js index b53a483..234c556 100644 --- a/dist/vue-3d-loader.cjs.js +++ b/dist/vue-3d-loader.cjs.js @@ -3155,4 +3155,4 @@ version 0.6.9 `)),e.indexOf(`\\ `)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(` `);let i=[];for(let o=0,c=n.length;o=7?(Ba.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6])).convertSRGBToLinear(),t.colors.push(Ba.r,Ba.g,Ba.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3]));break;case"vt":t.uvs.push(parseFloat(h[1]),parseFloat(h[2]));break}}else if(u==="f"){const f=l.slice(1).trim().split($f),d=[];for(let p=0,g=f.length;p0){const x=y.split("/");d.push(x)}}const m=d[0];for(let p=1,g=d.length-1;p1){const f=i[1].trim().toLowerCase();t.object.smooth=f!=="0"&&f!=="off"}else t.object.smooth=!0;const h=t.object.currentMaterial();h&&(h.smooth=t.object.smooth)}else{if(l==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+l+'"')}}t.finalize();const s=new dn;if(s.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0)===!0)for(let o=0,c=t.objects.length;o0&&p.setAttribute("normal",new Te(u.normals,3)),u.colors.length>0&&(m=!0,p.setAttribute("color",new Te(u.colors,3))),u.hasUVIndices===!0&&p.setAttribute("uv",new Te(u.uvs,2));const g=[];for(let x=0,b=h.length;x1){for(let x=0,b=h.length;x0){const o=new Ui({size:1,sizeAttenuation:!1}),c=new Ye;c.setAttribute("position",new Te(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(c.setAttribute("color",new Te(t.colors,3)),o.vertexColors=!0);const l=new mr(c,o);s.add(l)}return s}}class $M extends zp{constructor(e){super(e)}parse(e,t){const n={mipmaps:[],width:0,height:0,format:null,mipmapCount:1},i=542327876,s=131072,r=512,o=1024,c=2048,l=4096,u=8192,h=16384,f=32768;function d(te){return te.charCodeAt(0)+(te.charCodeAt(1)<<8)+(te.charCodeAt(2)<<16)+(te.charCodeAt(3)<<24)}function m(te){return String.fromCharCode(te&255,te>>8&255,te>>16&255,te>>24&255)}function p(te,V,ge,Ae){const Pe=ge*Ae*4,pe=new Uint8Array(te,V,Pe),Ue=new Uint8Array(Pe);let ce=0,ae=0;for(let ye=0;ye>1,1),ge=Math.max(ge>>1,1)}}return n}}class Gm{constructor(e,t,n){const i=this;let s=!1,r=0,o=0,c;const l=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this.itemStart=function(u){o++,s===!1&&i.onStart!==void 0&&i.onStart(u,r,o),s=!0},this.itemEnd=function(u){r++,i.onProgress!==void 0&&i.onProgress(u,r,o),r===o&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return c?c(u):u},this.setURLModifier=function(u){return c=u,this},this.addHandler=function(u,h){return l.push(u,h),this},this.removeHandler=function(u){const h=l.indexOf(u);return h!==-1&&l.splice(h,2),this},this.getHandler=function(u){for(let h=0,f=l.length;h=m.elements[v].count&&(v++,T=0);const _=i(m.elements[v].properties,L);o(p,m.elements[v].name,_),T++}return r(p)}function r(d){let m=new Ye;return d.indices.length>0&&m.setIndex(d.indices),m.setAttribute("position",new Te(d.vertices,3)),d.normals.length>0&&m.setAttribute("normal",new Te(d.normals,3)),d.uvs.length>0&&m.setAttribute("uv",new Te(d.uvs,2)),d.colors.length>0&&m.setAttribute("color",new Te(d.colors,3)),d.faceVertexUvs.length>0&&(m=m.toNonIndexed(),m.setAttribute("uv",new Te(d.faceVertexUvs,2))),m.computeBoundingSphere(),m}function o(d,m,p){function g(W){for(let K=0,U=W.length;K>5&31)/31,m=(X>>10&31)/31):(f=y,d=x,m=b)}for(let X=1;X<=3;X++){const k=z+X*12,q=O*3*3+(X-1)*3;_[q]=u.getFloat32(k,!0),_[q+1]=u.getFloat32(k+4,!0),_[q+2]=u.getFloat32(k+8,!0),R[q]=W,R[q+1]=K,R[q+2]=U,p&&(g[q]=f,g[q+1]=d,g[q+2]=m)}}return L.setAttribute("position",new gt(_,3)),L.setAttribute("normal",new gt(R,3)),p&&(L.setAttribute("color",new gt(g,3)),L.hasColors=!0,L.alpha=v),L}function s(l){const u=new Ye,h=/solid([\s\S]*?)endsolid/g,f=/facet([\s\S]*?)endfacet/g;let d=0;const m=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,p=new RegExp("vertex"+m+m+m,"g"),g=new RegExp("normal"+m+m+m,"g"),y=[],x=[],b=new D;let v,T=0,A=0,L=0;for(;(v=h.exec(l))!==null;){A=L;const _=v[0];for(;(v=f.exec(_))!==null;){let z=0,W=0;const K=v[0];for(;(v=g.exec(K))!==null;)b.x=parseFloat(v[1]),b.y=parseFloat(v[2]),b.z=parseFloat(v[3]),W++;for(;(v=p.exec(K))!==null;)y.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),x.push(b.x,b.y,b.z),z++,L++;W!==1&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+d),z!==3&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+d),d++}const R=A,O=L-A;u.addGroup(R,O,T),T++}return u.setAttribute("position",new Te(y,3)),u.setAttribute("normal",new Te(x,3)),u}function r(l){return typeof l!="string"?Qt.decodeText(new Uint8Array(l)):l}function o(l){if(typeof l=="string"){const u=new Uint8Array(l.length);for(let h=0;h=0?l.substring(0,u):l;h=h.toLowerCase();let f=u>=0?l.substring(u+1):"";if(f=f.trim(),h==="newmtl")i={name:f},r[f]=i;else if(h==="ka"||h==="kd"||h==="ks"||h==="ke"){const d=f.split(s,3);i[h]=[parseFloat(d[0]),parseFloat(d[1]),parseFloat(d[2])]}else i[h]=f}const o=new n1(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class n1{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=this.options.side!==void 0?this.options.side:Kn,this.wrap=this.options.wrap!==void 0?this.options.wrap:on}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const i=e[n],s={};t[n]=s;for(const r in i){let o=!0,c=i[r];const l=r.toLowerCase();switch(l){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(c=[c[0]/255,c[1]/255,c[2]/255]),this.options&&this.options.ignoreZeroRGBs&&c[0]===0&&c[1]===0&&c[2]===0&&(o=!1);break}o&&(s[l]=c)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return this.materials[e]===void 0&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],i={name:e,side:this.side};function s(o,c){return typeof c!="string"||c===""?"":/^https?:\/\//i.test(c)?c:o+c}function r(o,c){if(i[o])return;const l=t.getTextureParams(c,i),u=t.loadTexture(s(t.baseUrl,l.url));u.repeat.copy(l.scale),u.offset.copy(l.offset),u.wrapS=t.wrap,u.wrapT=t.wrap,(o==="map"||o==="emissiveMap")&&(u.encoding=et),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new ve().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new ve().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new ve().fromArray(c).convertSRGBToLinear();break;case"map_kd":r("map",c);break;case"map_ks":r("specularMap",c);break;case"map_ke":r("emissiveMap",c);break;case"norm":r("normalMap",c);break;case"map_bump":case"bump":r("bumpMap",c);break;case"map_d":r("alphaMap",c),i.transparent=!0;break;case"ns":i.shininess=parseFloat(c);break;case"d":l=parseFloat(c),l<1&&(i.opacity=l,i.transparent=!0);break;case"tr":l=parseFloat(c),this.options&&this.options.invertTrProperty&&(l=1-l),l>0&&(i.opacity=1-l,i.transparent=!0);break}}return this.materials[e]=new Zn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new ue(1,1),offset:new ue(0,0)},i=e.split(/\s+/);let s;return s=i.indexOf("-bm"),s>=0&&(t.bumpScale=parseFloat(i[s+1]),i.splice(s,2)),s=i.indexOf("-s"),s>=0&&(n.scale.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),s=i.indexOf("-o"),s>=0&&(n.offset.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),n.url=i.join(" ").trim(),n}loadTexture(e,t,n,i,s){const r=this.manager!==void 0?this.manager:ku;let o=r.getHandler(e);o===null&&(o=new Ps(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const rc=new Mi,Xn=new Gm;Xn.addHandler(/\.dds$/i,new $M);Xn.addHandler(/\.tga$/i,new cu);function i1(a){return rc.setFromObject(a),rc.getSize(new D)}function s1(a){return rc.setFromObject(a),rc.getCenter(new D)}function r1(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function o1(a){let e=r1(a);e==="glb"&&(e="gltf");let t={loader:null,getObject:null};switch(e){case"dae":t={loader:new mM(Xn),getObject:n=>n.scene};break;case"fbx":t={loader:new iM(Xn)};break;case"gltf":t={loader:new gM(Xn),getObject:n=>n.scene};break;case"obj":t={loader:new JM(Xn)};break;case"ply":t={loader:new QM(Xn),getObject:n=>(n.computeVertexNormals(),new St(n,new Os))};break;case"stl":t={loader:new e1(Xn),getObject:n=>new St(n,new Zn)};break;case"json":t={loader:new qp(Xn)};break}return t}function a1(){return new t1(Xn)}var c1=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const l1=Et.defineComponent({name:"vue3dLoader"}),u1=Et.defineComponent({...l1,props:{filePath:null,width:null,height:null,position:null,rotation:null,scale:null,lights:{default:()=>[{type:"AmbientLight",color:11184810},{type:"DirectionalLight",position:{x:1,y:1,z:1},color:16777215,intensity:.8}]},cameraPosition:{default:()=>({x:0,y:0,z:0})},cameraRotation:null,cameraUp:null,cameraLookAt:null,backgroundColor:{default:()=>16777215},backgroundAlpha:{default:()=>1},controlsOptions:null,crossOrigin:{default:"anonymous"},requestHeader:null,outputEncoding:{default:()=>"linear"},webGLRendererOptions:{default:()=>({})},mtlPath:{default:""},showFps:{type:Boolean,default:!1},textureImage:{default:""},clearScene:{type:Boolean,default:!1},parallelLoad:{type:Boolean,default:!1},labels:{default:()=>[]}},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new Kp,s=new ue,r=new Pt(45,1,1,1e5),o=new vc,c=new ct;let l=null,u={},h=[];const f=new Gu;let d=null,m=0,p=null,g=null,y=null;const x=Et.ref({width:t.width||0,height:t.height||0}),b=Et.ref(0),v=Et.ref(),T=Et.ref(!1),A=Et.ref(null),L=Et.ref(!1),_=Et.ref(null),R=Et.ref(null);Et.watch([()=>t.filePath,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],E=>{E[0]&&re(),E[1]&&De(),(E[2]||E[3])&&Y()}),Et.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],E=>{E[0]&&Ee("rotation",E[0]),E[1]&&Ee("position",E[1]),E[2]&&Ee("scale",E[2]),E[3]&&J()},{deep:!0}),Et.watch([()=>x],()=>{ee(!0),Y()},{deep:!0}),Et.watch([()=>t.controlsOptions],()=>{ie()},{deep:!0}),Et.watch([()=>t.cameraRotation],()=>{ee()},{deep:!0}),Et.watch([()=>t.cameraPosition],()=>{ee()},{deep:!0}),Et.onMounted(()=>{const{filePath:E,outputEncoding:w,webGLRendererOptions:G,showFps:Z}=t;E&&typeof E=="object"&&(L.value=!0);const $=_.value;O($),z();const Re=Object.assign({},{antialias:!0,alpha:!0},G,{canvas:R.value});l=new Tu(Re),l.shadowMap.enabled=!0;const F=w==="linear"?gi:et;l.outputEncoding=F,u=new Lw(r,$),o.add(c),re(),j(),$.addEventListener("mousedown",W,!1),$.addEventListener("mousemove",K,!1),$.addEventListener("mouseup",U,!1),$.addEventListener("click",X,!1),$.addEventListener("dblclick",k,!1),window.addEventListener("resize",z,!1),Z&&(p=fo(),$.appendChild(p.dom)),pe()}),Et.onBeforeUnmount(()=>{cancelAnimationFrame(m),l.dispose(),u&&u.dispose();const E=_.value;E.removeEventListener("mousedown",W,!1),E.removeEventListener("mousemove",K,!1),E.removeEventListener("mouseup",U,!1),E.removeEventListener("click",X,!1),E.removeEventListener("dblclick",k,!1),window.removeEventListener("resize",z,!1)});function O(E){const{width:w,height:G}=t;w&&(E.style.width=`${w}px`),G&&(E.style.height=`${G}px`)}function z(){const{width:E,height:w}=t;(!E||!w)&&Et.nextTick(()=>{const G=_.value;x.value={width:E||G.offsetWidth,height:w||G.offsetHeight}})}function W(E){const w=q(E.clientX,E.clientY);e("mousedown",E,w)}function K(E){const w=()=>{const G=q(E.clientX,E.clientY);e("mousemove",E,G)};L.value?(clearTimeout(A.value),A.value=setTimeout(()=>{w()},200)):w()}function U(E){const w=q(E.clientX,E.clientY);e("mouseup",E,w)}function X(E){const w=q(E.clientX,E.clientY);e("click",E,w)}function k(E){const w=q(E.clientX,E.clientY);e("dblclick",E,w)}function q(E,w){const G=Xe();if(!G)return null;if(!_.value)return;const Z=_.value.getBoundingClientRect();E-=Z.left,w-=Z.top,s.x=E/x.value.width*2-1,s.y=-(w/x.value.height)*2+1,i.setFromCamera(s,r);const $=i.intersectObject(G,!0);return($&&$.length)>0?$[0]:null}function j(E=!1){Y(),ee(E),J(),ie()}function H(){const{position:E,rotation:w,scale:G}=t;if(!n)return;const Z=L.value?ot(n):null;E&&(E instanceof Array?Z!=null?n.position.set(E[Z].x,E[Z].y,E[Z].z):n.position.set(0,0,0):n.position.set(E.x,E.y,E.z)),w&&(w instanceof Array?Z!=null?n.rotation.set(w[Z].x,w[Z].y,w[Z].z):n.rotation.set(0,0,0):n.rotation.set(w.x,w.y,w.z)),G&&(G instanceof Array?Z!=null?n.scale.set(G[Z].x,G[Z].y,G[Z].z):n.scale.set(0,0,0):n.scale.set(G.x,G.y,G.z))}function Y(){const{backgroundColor:E,backgroundAlpha:w}=t;l.setSize(x.value.width,x.value.height),l.setPixelRatio(window.devicePixelRatio||1),l.setClearColor(new ve(E).getHex()),l.setClearAlpha(w)}function ee(E){const{cameraPosition:w,cameraRotation:G,cameraUp:Z,cameraLookAt:$}=t;if(r.aspect=x.value.width/x.value.height,r.updateProjectionMatrix(),!E)if(!$||!Z){if(!n)return;const he=i1(n).length();r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),w.x===0&&w.y===0&&w.z===0&&(r.position.z=he),r.lookAt(new D)}else r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),r.up.set(Z.x,Z.y,Z.z),r.lookAt(new D($.x,$.y,$.z))}function J(){const{lights:E}=t;o.remove(...h),h=[],E.forEach(w=>{if(!w.type)return;const G=w.type.toLowerCase();let Z=null;if(G==="ambient"||G==="ambientlight"){const $=w.color===0?w.color:w.color||4210752,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Bo($,he)}else if(G==="point"||G==="pointlight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1,Re=w.distance||0,F=w.decay===0?w.decay:w.decay||1;Z=new Ds($,he,Re,F),w.position&&Z.position.copy(w.position)}else if(G==="directional"||G==="directionallight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1;Z=new zr($,he),w.position&&Z.position.copy(w.position),w.target&&Z.target.copy(w.target)}else if(G==="hemisphere"||G==="hemispherelight"){const $=w.skyColor===0?w.skyColor:w.skyColor||16777215,he=w.groundColor===0?w.groundColor:w.groundColor||16777215,Re=w.intensity===0?w.intensity:w.intensity||1;Z=new Bu($,he,Re),w.position&&Z.position.copy(w.position)}Z&&(h.push(Z),o.add(Z))})}function ie(){const{controlsOptions:E}=t;E&&Object.assign(u,E)}function re(){const{filePath:E,parallelLoad:w}=t;w&&L?E.forEach((G,Z)=>{te(Z)}):te()}function te(E){const{filePath:w,crossOrigin:G,requestHeader:Z,mtlPath:$}=t;if(!w)return;const he=E||b.value,Re=L.value?w[he]:w,F=o1(Re);d=F.loader;const fe=F.getObject?F.getObject:Ae;if(n&&he===0&&c.remove(n),Z&&d.setRequestHeader(Z),G&&d.setCrossOrigin(G),$)if(typeof $=="string")ge(Re,fe,he);else{if(!$[he]){V(Re,fe,he);return}ge(Re,fe,he)}else V(Re,fe,he)}function V(E,w,G){const{textureImage:Z,parallelLoad:$}=t;d.load(E,(...he)=>{if(n=w(...he),Pe(n,E),g=new Zp(n),n.animations&&n.animations.forEach(F=>{g.clipAction(F).play()}),Z){const F=typeof Z=="string"?Z:Z[G];F&&ye(n,F)}He(),e("load",c)},he=>{$||ae(he);const Re=b.value+1;e("process",he,Re)},he=>{e("error",he)})}function ge(E,w,G){const{crossOrigin:Z,requestHeader:$,mtlPath:he}=t,Re=a1();Z&&Re.setCrossOrigin(Z),$&&Re.setRequestHeader($);const F=typeof he=="string"?he:he[G],fe=/^(.*\/)([^/]*)$/.exec(F),we=fe[1],Me=fe[2];Re.setPath(we).load(Me,B=>{B.preload(),d.setMaterials(B),V(E,w,G)})}function Ae(E){return E}function Pe(E,w){const G=s1(n);T.value||(c.position.copy(G.negate()),T.value=!0),n=E;let Z=w.split("/");Z=Z[Z.length-1],n.fileName=Z,c.add(n),ee(),H()}function pe(){m=requestAnimationFrame(pe),ce();const E=f.getDelta();g&&g.update(E),Ue()}function Ue(){l.render(o,r)}function ce(){const{showFps:E}=t;E&&p.update()}function ae(E){const{filePath:w}=t;let G=Math.floor(E.loaded/E.total*100);const Z=()=>{G===100&&(L.value&&w.length>b.value?Et.nextTick(()=>{if(b.value++,b.value===w.length){b.value=0;return}te()}):b.value=0)};G===1/0&&(clearTimeout(v.value),v.value=setTimeout(()=>{G=100,Z()},200)),Z()}function ye(E,w){y||(y=new Ps),E.traverse(G=>{G.isMesh&&y.load(w,Z=>{G.material.map=Z,G.material.needsUpdate=!0},()=>{},Z=>{e("error",Z)})})}function De(){c.clear()}function Ee(E,w){const G=Xe();if(!!G){if(L.value){G.children.forEach(Z=>{const $=ot(Z),he=E==="scale"?1:0;w[$]?Z[E].set(w[$].x,w[$].y,w[$].z):Z[E].set(he,he,he)});return}G[E].set(w.x,w.y,w.z)}}function Xe(){return L.value?c:n}function He(){const{filePath:E}=t;L.value?b.value===E.length&&ze():ze()}function ze(){const{labels:E}=t;if(!E)return;const w=L.value?c:n,G=$=>(y||(y=new Ps),y.load($)),Z=($,he)=>{const Re=ft($,he),F=new Tt(Re);return F.needsUpdate=!0,F};E.forEach($=>{const he=$.image?G($.image):Z($.text,$.textStyle||{}),Re=new _c({map:he,color:$.spriteMaterialColor||16777215}),F=new Au(Re);$.scale?F.scale.set($.scale.x||1,$.scale.y||1,$.scale.z||0):F.scale.set(1,1,0),$.position&&F.position.set($.position.x,$.position.y,$.position.z),$.sid&&(F.sid=$.sid),w.add(F)})}function ft(E,w){w===void 0&&(w={});const G=(me,Fe,Se,ke,be,Ge)=>{me.beginPath(),me.moveTo(Fe+Ge,Se),me.lineTo(Fe+ke-Ge,Se),me.quadraticCurveTo(Fe+ke,Se,Fe+ke,Se+Ge),me.lineTo(Fe+ke,Se+be-Ge),me.quadraticCurveTo(Fe+ke,Se+be,Fe+ke-Ge,Se+be),me.lineTo(Fe+Ge,Se+be),me.quadraticCurveTo(Fe,Se+be,Fe,Se+be-Ge),me.lineTo(Fe,Se+Ge),me.quadraticCurveTo(Fe,Se,Fe+Ge,Se),me.closePath(),me.fill(),me.stroke()},Z=w.fontFamily||"Arial",$=w.fontSize===0||w.fontSize?w.fontSize:18,he=w.color||"#ffffff",Re=w.fontWeight||"normal",F=w.borderWidth===0||w.borderWidth?w.borderWidth:4,fe=w.borderColor||"rgba(0,0,0,1)",we=w.borderRadius===0||w.borderRadius?w.borderRadius:4,Me=w.backgroundColor||"rgba(255, 255, 255, 1)",B=document.createElement("canvas"),xe=B.getContext("2d");if(xe){xe.font=`${Re} ${$}px ${Z}`;const Fe=xe.measureText(E).width;xe.fillStyle=Me,xe.strokeStyle=fe,xe.lineWidth=F,G(xe,F/2,F/2,Fe+F,$*1.4+F,we),xe.fillStyle=he,xe.fillText(E,F,$+F)}return B}function ot(E){const{filePath:w}=t;let G;return w instanceof Array&&(G=w.map((Z,$)=>{if(Z.indexOf(E.fileName)>-1)return $}).filter(Z=>Z!=null)[0]),G}return(E,w)=>(Et.openBlock(),Et.createElementBlock("div",{ref_key:"containerElement",ref:_,class:"viewer-container"},[Et.createElementVNode("canvas",{ref_key:"canvasElement",ref:R,class:"viewer-canvas"},null,512)],512))}});var oc=c1(u1,[["__scopeId","data-v-4f87bc73"]]);const h1=a=>{a.component(oc.name,oc)};var f1={install:h1,vue3dLoader:oc};exports.Three=Cw;exports.default=f1;exports.vue3dLoader=oc; +`);let i={};const s=/\s+/,r={};for(let c=0;c=0?l.substring(0,u):l;h=h.toLowerCase();let f=u>=0?l.substring(u+1):"";if(f=f.trim(),h==="newmtl")i={name:f},r[f]=i;else if(h==="ka"||h==="kd"||h==="ks"||h==="ke"){const d=f.split(s,3);i[h]=[parseFloat(d[0]),parseFloat(d[1]),parseFloat(d[2])]}else i[h]=f}const o=new n1(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class n1{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=this.options.side!==void 0?this.options.side:Kn,this.wrap=this.options.wrap!==void 0?this.options.wrap:on}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const i=e[n],s={};t[n]=s;for(const r in i){let o=!0,c=i[r];const l=r.toLowerCase();switch(l){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(c=[c[0]/255,c[1]/255,c[2]/255]),this.options&&this.options.ignoreZeroRGBs&&c[0]===0&&c[1]===0&&c[2]===0&&(o=!1);break}o&&(s[l]=c)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return this.materials[e]===void 0&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],i={name:e,side:this.side};function s(o,c){return typeof c!="string"||c===""?"":/^https?:\/\//i.test(c)?c:o+c}function r(o,c){if(i[o])return;const l=t.getTextureParams(c,i),u=t.loadTexture(s(t.baseUrl,l.url));u.repeat.copy(l.scale),u.offset.copy(l.offset),u.wrapS=t.wrap,u.wrapT=t.wrap,(o==="map"||o==="emissiveMap")&&(u.encoding=et),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new ve().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new ve().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new ve().fromArray(c).convertSRGBToLinear();break;case"map_kd":r("map",c);break;case"map_ks":r("specularMap",c);break;case"map_ke":r("emissiveMap",c);break;case"norm":r("normalMap",c);break;case"map_bump":case"bump":r("bumpMap",c);break;case"map_d":r("alphaMap",c),i.transparent=!0;break;case"ns":i.shininess=parseFloat(c);break;case"d":l=parseFloat(c),l<1&&(i.opacity=l,i.transparent=!0);break;case"tr":l=parseFloat(c),this.options&&this.options.invertTrProperty&&(l=1-l),l>0&&(i.opacity=1-l,i.transparent=!0);break}}return this.materials[e]=new Zn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new ue(1,1),offset:new ue(0,0)},i=e.split(/\s+/);let s;return s=i.indexOf("-bm"),s>=0&&(t.bumpScale=parseFloat(i[s+1]),i.splice(s,2)),s=i.indexOf("-s"),s>=0&&(n.scale.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),s=i.indexOf("-o"),s>=0&&(n.offset.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),n.url=i.join(" ").trim(),n}loadTexture(e,t,n,i,s){const r=this.manager!==void 0?this.manager:ku;let o=r.getHandler(e);o===null&&(o=new Ps(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const rc=new Mi,Xn=new Gm;Xn.addHandler(/\.dds$/i,new $M);Xn.addHandler(/\.tga$/i,new cu);function i1(a){return rc.setFromObject(a),rc.getSize(new D)}function s1(a){return rc.setFromObject(a),rc.getCenter(new D)}function r1(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function o1(a){let e=r1(a);e==="glb"&&(e="gltf");let t={loader:null,getObject:null};switch(e){case"dae":t={loader:new mM(Xn),getObject:n=>n.scene};break;case"fbx":t={loader:new iM(Xn)};break;case"gltf":t={loader:new gM(Xn),getObject:n=>n.scene};break;case"obj":t={loader:new JM(Xn)};break;case"ply":t={loader:new QM(Xn),getObject:n=>(n.computeVertexNormals(),new St(n,new Os))};break;case"stl":t={loader:new e1(Xn),getObject:n=>new St(n,new Zn)};break;case"json":t={loader:new qp(Xn)};break}return t}function a1(){return new t1(Xn)}var c1=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const l1=Et.defineComponent({name:"vue3dLoader"}),u1=Et.defineComponent({...l1,props:{filePath:null,width:null,height:null,position:null,rotation:null,scale:null,lights:{default:()=>[{type:"AmbientLight",color:11184810},{type:"DirectionalLight",position:{x:1,y:1,z:1},color:16777215,intensity:.8}]},cameraPosition:{default:()=>({x:0,y:0,z:0})},cameraRotation:null,cameraUp:null,cameraLookAt:null,backgroundColor:{default:()=>16777215},backgroundAlpha:{default:()=>1},controlsOptions:null,crossOrigin:{default:"anonymous"},requestHeader:null,outputEncoding:{default:()=>"linear"},webGLRendererOptions:{default:()=>({})},mtlPath:{default:""},showFps:{type:Boolean,default:!1},textureImage:{default:""},clearScene:{type:Boolean,default:!1},parallelLoad:{type:Boolean,default:!1},labels:{default:()=>[]}},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new Kp,s=new ue,r=new Pt(45,1,1,1e5),o=new vc,c=new ct;let l=null,u={},h=[];const f=new Gu;let d=null,m=0,p=null,g=null,y=null;const x=Et.ref({width:t.width||0,height:t.height||0}),b=Et.ref(0),v=Et.ref(),T=Et.ref(!1),A=Et.ref(null),L=Et.ref(!1),_=Et.ref(null),R=Et.ref(null);Et.watch([()=>t.filePath,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],E=>{E[0]&&re(),E[1]&&De(),(E[2]||E[3])&&Y()}),Et.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],E=>{E[0]&&Ee("rotation",E[0]),E[1]&&Ee("position",E[1]),E[2]&&Ee("scale",E[2]),E[3]&&J()},{deep:!0}),Et.watch([()=>x],()=>{ee(!0),Y()},{deep:!0}),Et.watch([()=>t.controlsOptions],()=>{ie()},{deep:!0}),Et.watch([()=>t.cameraRotation],()=>{ee()},{deep:!0}),Et.watch([()=>t.cameraPosition],()=>{ee()},{deep:!0}),Et.onMounted(()=>{const{filePath:E,outputEncoding:w,webGLRendererOptions:G,showFps:Z}=t;E&&typeof E=="object"&&(L.value=!0);const $=_.value;O($),z();const Re=Object.assign({},{antialias:!0,alpha:!0},G,{canvas:R.value});l=new Tu(Re),l.shadowMap.enabled=!0;const F=w==="linear"?gi:et;l.outputEncoding=F,u=new Lw(r,$),o.add(c),re(),j(),$.addEventListener("mousedown",W,!1),$.addEventListener("mousemove",K,!1),$.addEventListener("mouseup",U,!1),$.addEventListener("click",X,!1),$.addEventListener("dblclick",k,!1),window.addEventListener("resize",z,!1),Z&&(p=fo(),$.appendChild(p.dom)),pe()}),Et.onBeforeUnmount(()=>{cancelAnimationFrame(m),l.dispose(),u&&u.dispose();const E=_.value;E.removeEventListener("mousedown",W,!1),E.removeEventListener("mousemove",K,!1),E.removeEventListener("mouseup",U,!1),E.removeEventListener("click",X,!1),E.removeEventListener("dblclick",k,!1),window.removeEventListener("resize",z,!1)});function O(E){const{width:w,height:G}=t;w&&(E.style.width=`${w}px`),G&&(E.style.height=`${G}px`)}function z(){const{width:E,height:w}=t;(!E||!w)&&Et.nextTick(()=>{const G=_.value;x.value={width:E||G.offsetWidth,height:w||G.offsetHeight}})}function W(E){const w=q(E.clientX,E.clientY);e("mousedown",E,w)}function K(E){const w=()=>{const G=q(E.clientX,E.clientY);e("mousemove",E,G)};L.value?(clearTimeout(A.value),A.value=setTimeout(()=>{w()},200)):w()}function U(E){const w=q(E.clientX,E.clientY);e("mouseup",E,w)}function X(E){const w=q(E.clientX,E.clientY);e("click",E,w)}function k(E){const w=q(E.clientX,E.clientY);e("dblclick",E,w)}function q(E,w){const G=Xe();if(!G)return null;if(!_.value)return;const Z=_.value.getBoundingClientRect();E-=Z.left,w-=Z.top,s.x=E/x.value.width*2-1,s.y=-(w/x.value.height)*2+1,i.setFromCamera(s,r);const $=i.intersectObject(G,!0);return($&&$.length)>0?$[0]:null}function j(E=!1){Y(),ee(E),J(),ie()}function H(){const{position:E,rotation:w,scale:G}=t;if(!n)return;const Z=L.value?ot(n):null;E&&(E instanceof Array?Z!=null?n.position.set(E[Z].x,E[Z].y,E[Z].z):n.position.set(0,0,0):n.position.set(E.x,E.y,E.z)),w&&(w instanceof Array?Z!=null?n.rotation.set(w[Z].x,w[Z].y,w[Z].z):n.rotation.set(0,0,0):n.rotation.set(w.x,w.y,w.z)),G&&(G instanceof Array?Z!=null?n.scale.set(G[Z].x,G[Z].y,G[Z].z):n.scale.set(0,0,0):n.scale.set(G.x,G.y,G.z))}function Y(){const{backgroundColor:E,backgroundAlpha:w}=t;l.setSize(x.value.width,x.value.height),l.setPixelRatio(window.devicePixelRatio||1),l.setClearColor(new ve(E).getHex()),l.setClearAlpha(w)}function ee(E){const{cameraPosition:w,cameraRotation:G,cameraUp:Z,cameraLookAt:$}=t;if(r.aspect=x.value.width/x.value.height,r.updateProjectionMatrix(),!E)if(!$||!Z){if(!n)return;const he=i1(n).length();r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),w.x===0&&w.y===0&&w.z===0&&(r.position.z=he),r.lookAt(new D)}else r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),r.up.set(Z.x,Z.y,Z.z),r.lookAt(new D($.x,$.y,$.z))}function J(){const{lights:E}=t;o.remove(...h),h=[],E.forEach(w=>{if(!w.type)return;const G=w.type.toLowerCase();let Z=null;if(G==="ambient"||G==="ambientlight"){const $=w.color===0?w.color:w.color||4210752,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Bo($,he)}else if(G==="point"||G==="pointlight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1,Re=w.distance||0,F=w.decay===0?w.decay:w.decay||1;Z=new Ds($,he,Re,F),w.position&&Z.position.copy(w.position)}else if(G==="directional"||G==="directionallight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1;Z=new zr($,he),w.position&&Z.position.copy(w.position),w.target&&Z.target.copy(w.target)}else if(G==="hemisphere"||G==="hemispherelight"){const $=w.skyColor===0?w.skyColor:w.skyColor||16777215,he=w.groundColor===0?w.groundColor:w.groundColor||16777215,Re=w.intensity===0?w.intensity:w.intensity||1;Z=new Bu($,he,Re),w.position&&Z.position.copy(w.position)}Z&&(h.push(Z),o.add(Z))})}function ie(){const{controlsOptions:E}=t;E&&Object.assign(u,E)}function re(){const{filePath:E,parallelLoad:w}=t;w&&L?E.forEach((G,Z)=>{te(Z)}):te()}function te(E){const{filePath:w,crossOrigin:G,requestHeader:Z,mtlPath:$}=t;if(!w)return;const he=E||b.value,Re=L.value?w[he]:w,F=o1(Re);d=F.loader;const fe=F.getObject?F.getObject:Ae;if(n&&he===0&&c.remove(n),Z&&d.setRequestHeader(Z),G&&d.setCrossOrigin(G),$)if(typeof $=="string")ge(Re,fe,he);else{if(!$[he]){V(Re,fe,he);return}ge(Re,fe,he)}else V(Re,fe,he)}function V(E,w,G){const{textureImage:Z,parallelLoad:$}=t;d.load(E,(...he)=>{if(n=w(...he),Pe(n,E),g=new Zp(n),n.animations&&n.animations.forEach(F=>{g.clipAction(F).play()}),Z){const F=typeof Z=="string"?Z:Z[G];F&&ye(n,F)}He(),e("load",c)},he=>{$||ae(he);const Re=b.value+1;e("process",he,Re)},he=>{e("error",he)})}function ge(E,w,G){const{crossOrigin:Z,requestHeader:$,mtlPath:he}=t,Re=a1();Z&&Re.setCrossOrigin(Z),$&&Re.setRequestHeader($);const F=typeof he=="string"?he:he[G],fe=/^(.*\/)([^/]*)$/.exec(F),we=fe[1],Me=fe[2];Re.setPath(we).load(Me,B=>{B.preload(),d.setMaterials(B),V(E,w,G)})}function Ae(E){return E}function Pe(E,w){const G=s1(n);T.value||(c.position.copy(G.negate()),T.value=!0),n=E;let Z=w.split("/");Z=Z[Z.length-1],n.fileName=Z,c.add(n),ee(),H()}function pe(){m=requestAnimationFrame(pe),ce();const E=f.getDelta();g&&g.update(E),Ue()}function Ue(){l.render(o,r)}function ce(){const{showFps:E}=t;E&&p.update()}function ae(E){const{filePath:w}=t;let G=Math.floor(E.loaded/E.total*100);const Z=()=>{G===100&&(L.value&&w.length>b.value?Et.nextTick(()=>{if(b.value++,b.value===w.length){b.value=0;return}te()}):b.value=0)};G===1/0&&(clearTimeout(v.value),v.value=setTimeout(()=>{G=100,Z()},200)),Z()}function ye(E,w){y||(y=new Ps),E.traverse(G=>{G.isMesh&&y.load(w,Z=>{G.material.map=Z,G.material.needsUpdate=!0},()=>{},Z=>{e("error",Z)})})}function De(){c.clear()}function Ee(E,w){const G=Xe();if(!!G){if(L.value){G.children.forEach(Z=>{const $=ot(Z),he=E==="scale"?1:0;w[$]?Z[E].set(w[$].x,w[$].y,w[$].z):Z[E].set(he,he,he)});return}G[E].set(w.x,w.y,w.z)}}function Xe(){return L.value?c:n}function He(){const{filePath:E}=t;L.value?b.value===E.length&&ze():ze()}function ze(){const{labels:E}=t;if(!E)return;const w=L.value?c:n,G=$=>(y||(y=new Ps),y.load($)),Z=($,he)=>{const Re=ft($,he),F=new Tt(Re);return F.needsUpdate=!0,F};E.forEach($=>{const he=$.image?G($.image):Z($.text,$.textStyle||{}),Re=new _c({map:he,color:$.spriteMaterialColor||16777215}),F=new Au(Re);$.scale?F.scale.set($.scale.x||1,$.scale.y||1,$.scale.z||0):F.scale.set(1,1,0),$.position&&F.position.set($.position.x,$.position.y,$.position.z),$.sid&&(F.sid=$.sid),w.add(F)})}function ft(E,w){w===void 0&&(w={});const G=(me,Fe,Se,ke,be,Ge)=>{me.beginPath(),me.moveTo(Fe+Ge,Se),me.lineTo(Fe+ke-Ge,Se),me.quadraticCurveTo(Fe+ke,Se,Fe+ke,Se+Ge),me.lineTo(Fe+ke,Se+be-Ge),me.quadraticCurveTo(Fe+ke,Se+be,Fe+ke-Ge,Se+be),me.lineTo(Fe+Ge,Se+be),me.quadraticCurveTo(Fe,Se+be,Fe,Se+be-Ge),me.lineTo(Fe,Se+Ge),me.quadraticCurveTo(Fe,Se,Fe+Ge,Se),me.closePath(),me.fill(),me.stroke()},Z=w.fontFamily||"Arial",$=w.fontSize===0||w.fontSize?w.fontSize:18,he=w.color||"#ffffff",Re=w.fontWeight||"normal",F=w.borderWidth===0||w.borderWidth?w.borderWidth:4,fe=w.borderColor||"rgba(0,0,0,1)",we=w.borderRadius===0||w.borderRadius?w.borderRadius:4,Me=w.backgroundColor||"rgba(255, 255, 255, 1)",B=document.createElement("canvas"),xe=B.getContext("2d");if(xe){xe.font=`${Re} ${$}px ${Z}`;const Fe=xe.measureText(E).width;xe.fillStyle=Me,xe.strokeStyle=fe,xe.lineWidth=F,G(xe,F/2,F/2,Fe+F,$*1.4+F,we),xe.fillStyle=he,xe.fillText(E,F,$+F)}return B}function ot(E){const{filePath:w}=t;let G;return w instanceof Array&&(G=w.map((Z,$)=>{if(Z.indexOf(E.fileName)>-1)return $}).filter(Z=>Z!=null)[0]),G}return(E,w)=>(Et.openBlock(),Et.createElementBlock("div",{ref_key:"containerElement",ref:_,class:"viewer-container"},[Et.createElementVNode("canvas",{ref_key:"canvasElement",ref:R,class:"viewer-canvas"},null,512)],512))}});var oc=c1(u1,[["__scopeId","data-v-29f70b62"]]);const h1=a=>{a.component(oc.name,oc)};var f1={install:h1,vue3dLoader:oc};exports.Three=Cw;exports.default=f1;exports.vue3dLoader=oc; diff --git a/dist/vue-3d-loader.esm.js b/dist/vue-3d-loader.esm.js index a63b87a..16b1848 100644 --- a/dist/vue-3d-loader.esm.js +++ b/dist/vue-3d-loader.esm.js @@ -40861,7 +40861,7 @@ const _sfc_main = defineComponent({ }; } }); -var vue3dLoader = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4f87bc73"]]); +var vue3dLoader = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-29f70b62"]]); const install = (app) => { app.component(vue3dLoader.name, vue3dLoader); }; diff --git a/dist/vue-3d-loader.global.js b/dist/vue-3d-loader.global.js index 642cc45..0025c2d 100644 --- a/dist/vue-3d-loader.global.js +++ b/dist/vue-3d-loader.global.js @@ -3155,4 +3155,4 @@ version 0.6.9 `)),e.indexOf(`\\ `)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(` `);let i=[];for(let o=0,c=n.length;o=7?(xc.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6])).convertSRGBToLinear(),t.colors.push(xc.r,xc.g,xc.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(h[1]),parseFloat(h[2]),parseFloat(h[3]));break;case"vt":t.uvs.push(parseFloat(h[1]),parseFloat(h[2]));break}}else if(u==="f"){const f=l.slice(1).trim().split(Im),d=[];for(let p=0,g=f.length;p0){const x=y.split("/");d.push(x)}}const m=d[0];for(let p=1,g=d.length-1;p1){const f=i[1].trim().toLowerCase();t.object.smooth=f!=="0"&&f!=="off"}else t.object.smooth=!0;const h=t.object.currentMaterial();h&&(h.smooth=t.object.smooth)}else{if(l==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+l+'"')}}t.finalize();const s=new hn;if(s.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0)===!0)for(let o=0,c=t.objects.length;o0&&p.setAttribute("normal",new Te(u.normals,3)),u.colors.length>0&&(m=!0,p.setAttribute("color",new Te(u.colors,3))),u.hasUVIndices===!0&&p.setAttribute("uv",new Te(u.uvs,2));const g=[];for(let x=0,b=h.length;x1){for(let x=0,b=h.length;x0){const o=new Vi({size:1,sizeAttenuation:!1}),c=new qe;c.setAttribute("position",new Te(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(c.setAttribute("color",new Te(t.colors,3)),o.vertexColors=!0);const l=new gr(c,o);s.add(l)}return s}}class pM extends Xd{constructor(e){super(e)}parse(e,t){const n={mipmaps:[],width:0,height:0,format:null,mipmapCount:1},i=542327876,s=131072,r=512,o=1024,c=2048,l=4096,u=8192,h=16384,f=32768;function d(te){return te.charCodeAt(0)+(te.charCodeAt(1)<<8)+(te.charCodeAt(2)<<16)+(te.charCodeAt(3)<<24)}function m(te){return String.fromCharCode(te&255,te>>8&255,te>>16&255,te>>24&255)}function p(te,V,ge,Ae){const Pe=ge*Ae*4,pe=new Uint8Array(te,V,Pe),Ue=new Uint8Array(Pe);let ce=0,ae=0;for(let xe=0;xe>1,1),ge=Math.max(ge>>1,1)}}return n}}class Nm{constructor(e,t,n){const i=this;let s=!1,r=0,o=0,c;const l=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this.itemStart=function(u){o++,s===!1&&i.onStart!==void 0&&i.onStart(u,r,o),s=!0},this.itemEnd=function(u){r++,i.onProgress!==void 0&&i.onProgress(u,r,o),r===o&&(s=!1,i.onLoad!==void 0&&i.onLoad())},this.itemError=function(u){i.onError!==void 0&&i.onError(u)},this.resolveURL=function(u){return c?c(u):u},this.setURLModifier=function(u){return c=u,this},this.addHandler=function(u,h){return l.push(u,h),this},this.removeHandler=function(u){const h=l.indexOf(u);return h!==-1&&l.splice(h,2),this},this.getHandler=function(u){for(let h=0,f=l.length;h=m.elements[v].count&&(v++,T=0);const _=i(m.elements[v].properties,L);o(p,m.elements[v].name,_),T++}return r(p)}function r(d){let m=new qe;return d.indices.length>0&&m.setIndex(d.indices),m.setAttribute("position",new Te(d.vertices,3)),d.normals.length>0&&m.setAttribute("normal",new Te(d.normals,3)),d.uvs.length>0&&m.setAttribute("uv",new Te(d.uvs,2)),d.colors.length>0&&m.setAttribute("color",new Te(d.colors,3)),d.faceVertexUvs.length>0&&(m=m.toNonIndexed(),m.setAttribute("uv",new Te(d.faceVertexUvs,2))),m.computeBoundingSphere(),m}function o(d,m,p){function g(W){for(let K=0,U=W.length;K>5&31)/31,m=(q>>10&31)/31):(f=y,d=x,m=b)}for(let q=1;q<=3;q++){const k=z+q*12,X=O*3*3+(q-1)*3;_[X]=u.getFloat32(k,!0),_[X+1]=u.getFloat32(k+4,!0),_[X+2]=u.getFloat32(k+8,!0),R[X]=W,R[X+1]=K,R[X+2]=U,p&&(g[X]=f,g[X+1]=d,g[X+2]=m)}}return L.setAttribute("position",new pt(_,3)),L.setAttribute("normal",new pt(R,3)),p&&(L.setAttribute("color",new pt(g,3)),L.hasColors=!0,L.alpha=v),L}function s(l){const u=new qe,h=/solid([\s\S]*?)endsolid/g,f=/facet([\s\S]*?)endfacet/g;let d=0;const m=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,p=new RegExp("vertex"+m+m+m,"g"),g=new RegExp("normal"+m+m+m,"g"),y=[],x=[],b=new D;let v,T=0,A=0,L=0;for(;(v=h.exec(l))!==null;){A=L;const _=v[0];for(;(v=f.exec(_))!==null;){let z=0,W=0;const K=v[0];for(;(v=g.exec(K))!==null;)b.x=parseFloat(v[1]),b.y=parseFloat(v[2]),b.z=parseFloat(v[3]),W++;for(;(v=p.exec(K))!==null;)y.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),x.push(b.x,b.y,b.z),z++,L++;W!==1&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+d),z!==3&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+d),d++}const R=A,O=L-A;u.addGroup(R,O,T),T++}return u.setAttribute("position",new Te(y,3)),u.setAttribute("normal",new Te(x,3)),u}function r(l){return typeof l!="string"?$t.decodeText(new Uint8Array(l)):l}function o(l){if(typeof l=="string"){const u=new Uint8Array(l.length);for(let h=0;h=0?l.substring(0,u):l;h=h.toLowerCase();let f=u>=0?l.substring(u+1):"";if(f=f.trim(),h==="newmtl")i={name:f},r[f]=i;else if(h==="ka"||h==="kd"||h==="ks"||h==="ke"){const d=f.split(s,3);i[h]=[parseFloat(d[0]),parseFloat(d[1]),parseFloat(d[2])]}else i[h]=f}const o=new xM(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class xM{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=this.options.side!==void 0?this.options.side:Vn,this.wrap=this.options.wrap!==void 0?this.options.wrap:sn}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const i=e[n],s={};t[n]=s;for(const r in i){let o=!0,c=i[r];const l=r.toLowerCase();switch(l){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(c=[c[0]/255,c[1]/255,c[2]/255]),this.options&&this.options.ignoreZeroRGBs&&c[0]===0&&c[1]===0&&c[2]===0&&(o=!1);break}o&&(s[l]=c)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return this.materials[e]===void 0&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],i={name:e,side:this.side};function s(o,c){return typeof c!="string"||c===""?"":/^https?:\/\//i.test(c)?c:o+c}function r(o,c){if(i[o])return;const l=t.getTextureParams(c,i),u=t.loadTexture(s(t.baseUrl,l.url));u.repeat.copy(l.scale),u.offset.copy(l.offset),u.wrapS=t.wrap,u.wrapT=t.wrap,(o==="map"||o==="emissiveMap")&&(u.encoding=et),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new ye().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new ye().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new ye().fromArray(c).convertSRGBToLinear();break;case"map_kd":r("map",c);break;case"map_ks":r("specularMap",c);break;case"map_ke":r("emissiveMap",c);break;case"norm":r("normalMap",c);break;case"map_bump":case"bump":r("bumpMap",c);break;case"map_d":r("alphaMap",c),i.transparent=!0;break;case"ns":i.shininess=parseFloat(c);break;case"d":l=parseFloat(c),l<1&&(i.opacity=l,i.transparent=!0);break;case"tr":l=parseFloat(c),this.options&&this.options.invertTrProperty&&(l=1-l),l>0&&(i.opacity=1-l,i.transparent=!0);break}}return this.materials[e]=new Zn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new le(1,1),offset:new le(0,0)},i=e.split(/\s+/);let s;return s=i.indexOf("-bm"),s>=0&&(t.bumpScale=parseFloat(i[s+1]),i.splice(s,2)),s=i.indexOf("-s"),s>=0&&(n.scale.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),s=i.indexOf("-o"),s>=0&&(n.offset.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),n.url=i.join(" ").trim(),n}loadTexture(e,t,n,i,s){const r=this.manager!==void 0?this.manager:hu;let o=r.getHandler(e);o===null&&(o=new Rs(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const _c=new ai,Qn=new Nm;Qn.addHandler(/\.dds$/i,new pM),Qn.addHandler(/\.tga$/i,new Yu);function vM(a){return _c.setFromObject(a),_c.getSize(new D)}function _M(a){return _c.setFromObject(a),_c.getCenter(new D)}function bM(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function wM(a){let e=bM(a);e==="glb"&&(e="gltf");let t={loader:null,getObject:null};switch(e){case"dae":t={loader:new Iw(Qn),getObject:n=>n.scene};break;case"fbx":t={loader:new vw(Qn)};break;case"gltf":t={loader:new Pw(Qn),getObject:n=>n.scene};break;case"obj":t={loader:new dM(Qn)};break;case"ply":t={loader:new mM(Qn),getObject:n=>(n.computeVertexNormals(),new St(n,new Ts))};break;case"stl":t={loader:new gM(Qn),getObject:n=>new St(n,new Zn)};break;case"json":t={loader:new tp(Qn)};break}return t}function MM(){return new yM(Qn)}var d1="",SM=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const TM=At.defineComponent({name:"vue3dLoader"}),AM=At.defineComponent({...TM,props:{filePath:null,width:null,height:null,position:null,rotation:null,scale:null,lights:{default:()=>[{type:"AmbientLight",color:11184810},{type:"DirectionalLight",position:{x:1,y:1,z:1},color:16777215,intensity:.8}]},cameraPosition:{default:()=>({x:0,y:0,z:0})},cameraRotation:null,cameraUp:null,cameraLookAt:null,backgroundColor:{default:()=>16777215},backgroundAlpha:{default:()=>1},controlsOptions:null,crossOrigin:{default:"anonymous"},requestHeader:null,outputEncoding:{default:()=>"linear"},webGLRendererOptions:{default:()=>({})},mtlPath:{default:""},showFps:{type:Boolean,default:!1},textureImage:{default:""},clearScene:{type:Boolean,default:!1},parallelLoad:{type:Boolean,default:!1},labels:{default:()=>[]}},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new dp,s=new le,r=new It(45,1,1,1e5),o=new Ia,c=new ot;let l=null,u={},h=[];const f=new gu;let d=null,m=0,p=null,g=null,y=null;const x=At.ref({width:t.width||0,height:t.height||0}),b=At.ref(0),v=At.ref(),T=At.ref(!1),A=At.ref(null),L=At.ref(!1),_=At.ref(null),R=At.ref(null);At.watch([()=>t.filePath,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],E=>{E[0]&&re(),E[1]&&De(),(E[2]||E[3])&&Y()}),At.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],E=>{E[0]&&Ee("rotation",E[0]),E[1]&&Ee("position",E[1]),E[2]&&Ee("scale",E[2]),E[3]&&J()},{deep:!0}),At.watch([()=>x],()=>{ee(!0),Y()},{deep:!0}),At.watch([()=>t.controlsOptions],()=>{ie()},{deep:!0}),At.watch([()=>t.cameraRotation],()=>{ee()},{deep:!0}),At.watch([()=>t.cameraPosition],()=>{ee()},{deep:!0}),At.onMounted(()=>{const{filePath:E,outputEncoding:w,webGLRendererOptions:G,showFps:Z}=t;E&&typeof E=="object"&&(L.value=!0);const $=_.value;O($),z();const Re=Object.assign({},{antialias:!0,alpha:!0},G,{canvas:R.value});l=new Wl(Re),l.shadowMap.enabled=!0;const F=w==="linear"?ri:et;l.outputEncoding=F,u=new Xb(r,$),o.add(c),re(),j(),$.addEventListener("mousedown",W,!1),$.addEventListener("mousemove",K,!1),$.addEventListener("mouseup",U,!1),$.addEventListener("click",q,!1),$.addEventListener("dblclick",k,!1),window.addEventListener("resize",z,!1),Z&&(p=Ro(),$.appendChild(p.dom)),pe()}),At.onBeforeUnmount(()=>{cancelAnimationFrame(m),l.dispose(),u&&u.dispose();const E=_.value;E.removeEventListener("mousedown",W,!1),E.removeEventListener("mousemove",K,!1),E.removeEventListener("mouseup",U,!1),E.removeEventListener("click",q,!1),E.removeEventListener("dblclick",k,!1),window.removeEventListener("resize",z,!1)});function O(E){const{width:w,height:G}=t;w&&(E.style.width=`${w}px`),G&&(E.style.height=`${G}px`)}function z(){const{width:E,height:w}=t;(!E||!w)&&At.nextTick(()=>{const G=_.value;x.value={width:E||G.offsetWidth,height:w||G.offsetHeight}})}function W(E){const w=X(E.clientX,E.clientY);e("mousedown",E,w)}function K(E){const w=()=>{const G=X(E.clientX,E.clientY);e("mousemove",E,G)};L.value?(clearTimeout(A.value),A.value=setTimeout(()=>{w()},200)):w()}function U(E){const w=X(E.clientX,E.clientY);e("mouseup",E,w)}function q(E){const w=X(E.clientX,E.clientY);e("click",E,w)}function k(E){const w=X(E.clientX,E.clientY);e("dblclick",E,w)}function X(E,w){const G=je();if(!G)return null;if(!_.value)return;const Z=_.value.getBoundingClientRect();E-=Z.left,w-=Z.top,s.x=E/x.value.width*2-1,s.y=-(w/x.value.height)*2+1,i.setFromCamera(s,r);const $=i.intersectObject(G,!0);return($&&$.length)>0?$[0]:null}function j(E=!1){Y(),ee(E),J(),ie()}function H(){const{position:E,rotation:w,scale:G}=t;if(!n)return;const Z=L.value?at(n):null;E&&(E instanceof Array?Z!=null?n.position.set(E[Z].x,E[Z].y,E[Z].z):n.position.set(0,0,0):n.position.set(E.x,E.y,E.z)),w&&(w instanceof Array?Z!=null?n.rotation.set(w[Z].x,w[Z].y,w[Z].z):n.rotation.set(0,0,0):n.rotation.set(w.x,w.y,w.z)),G&&(G instanceof Array?Z!=null?n.scale.set(G[Z].x,G[Z].y,G[Z].z):n.scale.set(0,0,0):n.scale.set(G.x,G.y,G.z))}function Y(){const{backgroundColor:E,backgroundAlpha:w}=t;l.setSize(x.value.width,x.value.height),l.setPixelRatio(window.devicePixelRatio||1),l.setClearColor(new ye(E).getHex()),l.setClearAlpha(w)}function ee(E){const{cameraPosition:w,cameraRotation:G,cameraUp:Z,cameraLookAt:$}=t;if(r.aspect=x.value.width/x.value.height,r.updateProjectionMatrix(),!E)if(!$||!Z){if(!n)return;const he=vM(n).length();r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),w.x===0&&w.y===0&&w.z===0&&(r.position.z=he),r.lookAt(new D)}else r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),r.up.set(Z.x,Z.y,Z.z),r.lookAt(new D($.x,$.y,$.z))}function J(){const{lights:E}=t;o.remove(...h),h=[],E.forEach(w=>{if(!w.type)return;const G=w.type.toLowerCase();let Z=null;if(G==="ambient"||G==="ambientlight"){const $=w.color===0?w.color:w.color||4210752,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Lo($,he)}else if(G==="point"||G==="pointlight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1,Re=w.distance||0,F=w.decay===0?w.decay:w.decay||1;Z=new Is($,he,Re,F),w.position&&Z.position.copy(w.position)}else if(G==="directional"||G==="directionallight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Ir($,he),w.position&&Z.position.copy(w.position),w.target&&Z.target.copy(w.target)}else if(G==="hemisphere"||G==="hemispherelight"){const $=w.skyColor===0?w.skyColor:w.skyColor||16777215,he=w.groundColor===0?w.groundColor:w.groundColor||16777215,Re=w.intensity===0?w.intensity:w.intensity||1;Z=new fu($,he,Re),w.position&&Z.position.copy(w.position)}Z&&(h.push(Z),o.add(Z))})}function ie(){const{controlsOptions:E}=t;E&&Object.assign(u,E)}function re(){const{filePath:E,parallelLoad:w}=t;w&&L?E.forEach((G,Z)=>{te(Z)}):te()}function te(E){const{filePath:w,crossOrigin:G,requestHeader:Z,mtlPath:$}=t;if(!w)return;const he=E||b.value,Re=L.value?w[he]:w,F=wM(Re);d=F.loader;const fe=F.getObject?F.getObject:Ae;if(n&&he===0&&c.remove(n),Z&&d.setRequestHeader(Z),G&&d.setCrossOrigin(G),$)if(typeof $=="string")ge(Re,fe,he);else{if(!$[he]){V(Re,fe,he);return}ge(Re,fe,he)}else V(Re,fe,he)}function V(E,w,G){const{textureImage:Z,parallelLoad:$}=t;d.load(E,(...he)=>{if(n=w(...he),Pe(n,E),g=new fp(n),n.animations&&n.animations.forEach(F=>{g.clipAction(F).play()}),Z){const F=typeof Z=="string"?Z:Z[G];F&&xe(n,F)}He(),e("load",c)},he=>{$||ae(he);const Re=b.value+1;e("process",he,Re)},he=>{e("error",he)})}function ge(E,w,G){const{crossOrigin:Z,requestHeader:$,mtlPath:he}=t,Re=MM();Z&&Re.setCrossOrigin(Z),$&&Re.setRequestHeader($);const F=typeof he=="string"?he:he[G],fe=/^(.*\/)([^/]*)$/.exec(F),we=fe[1],Me=fe[2];Re.setPath(we).load(Me,B=>{B.preload(),d.setMaterials(B),V(E,w,G)})}function Ae(E){return E}function Pe(E,w){const G=_M(n);T.value||(c.position.copy(G.negate()),T.value=!0),n=E;let Z=w.split("/");Z=Z[Z.length-1],n.fileName=Z,c.add(n),ee(),H()}function pe(){m=requestAnimationFrame(pe),ce();const E=f.getDelta();g&&g.update(E),Ue()}function Ue(){l.render(o,r)}function ce(){const{showFps:E}=t;E&&p.update()}function ae(E){const{filePath:w}=t;let G=Math.floor(E.loaded/E.total*100);const Z=()=>{G===100&&(L.value&&w.length>b.value?At.nextTick(()=>{if(b.value++,b.value===w.length){b.value=0;return}te()}):b.value=0)};G===1/0&&(clearTimeout(v.value),v.value=setTimeout(()=>{G=100,Z()},200)),Z()}function xe(E,w){y||(y=new Rs),E.traverse(G=>{G.isMesh&&y.load(w,Z=>{G.material.map=Z,G.material.needsUpdate=!0},()=>{},Z=>{e("error",Z)})})}function De(){c.clear()}function Ee(E,w){const G=je();if(!!G){if(L.value){G.children.forEach(Z=>{const $=at(Z),he=E==="scale"?1:0;w[$]?Z[E].set(w[$].x,w[$].y,w[$].z):Z[E].set(he,he,he)});return}G[E].set(w.x,w.y,w.z)}}function je(){return L.value?c:n}function He(){const{filePath:E}=t;L.value?b.value===E.length&&ze():ze()}function ze(){const{labels:E}=t;if(!E)return;const w=L.value?c:n,G=$=>(y||(y=new Rs),y.load($)),Z=($,he)=>{const Re=ft($,he),F=new Mt(Re);return F.needsUpdate=!0,F};E.forEach($=>{const he=$.image?G($.image):Z($.text,$.textStyle||{}),Re=new Pa({map:he,color:$.spriteMaterialColor||16777215}),F=new ql(Re);$.scale?F.scale.set($.scale.x||1,$.scale.y||1,$.scale.z||0):F.scale.set(1,1,0),$.position&&F.position.set($.position.x,$.position.y,$.position.z),$.sid&&(F.sid=$.sid),w.add(F)})}function ft(E,w){w===void 0&&(w={});const G=(me,Fe,Se,ke,be,Ge)=>{me.beginPath(),me.moveTo(Fe+Ge,Se),me.lineTo(Fe+ke-Ge,Se),me.quadraticCurveTo(Fe+ke,Se,Fe+ke,Se+Ge),me.lineTo(Fe+ke,Se+be-Ge),me.quadraticCurveTo(Fe+ke,Se+be,Fe+ke-Ge,Se+be),me.lineTo(Fe+Ge,Se+be),me.quadraticCurveTo(Fe,Se+be,Fe,Se+be-Ge),me.lineTo(Fe,Se+Ge),me.quadraticCurveTo(Fe,Se,Fe+Ge,Se),me.closePath(),me.fill(),me.stroke()},Z=w.fontFamily||"Arial",$=w.fontSize===0||w.fontSize?w.fontSize:18,he=w.color||"#ffffff",Re=w.fontWeight||"normal",F=w.borderWidth===0||w.borderWidth?w.borderWidth:4,fe=w.borderColor||"rgba(0,0,0,1)",we=w.borderRadius===0||w.borderRadius?w.borderRadius:4,Me=w.backgroundColor||"rgba(255, 255, 255, 1)",B=document.createElement("canvas"),ve=B.getContext("2d");if(ve){ve.font=`${Re} ${$}px ${Z}`;const Fe=ve.measureText(E).width;ve.fillStyle=Me,ve.strokeStyle=fe,ve.lineWidth=F,G(ve,F/2,F/2,Fe+F,$*1.4+F,we),ve.fillStyle=he,ve.fillText(E,F,$+F)}return B}function at(E){const{filePath:w}=t;let G;return w instanceof Array&&(G=w.map((Z,$)=>{if(Z.indexOf(E.fileName)>-1)return $}).filter(Z=>Z!=null)[0]),G}return(E,w)=>(At.openBlock(),At.createElementBlock("div",{ref_key:"containerElement",ref:_,class:"viewer-container"},[At.createElementVNode("canvas",{ref_key:"canvasElement",ref:R,class:"viewer-canvas"},null,512)],512))}});var bc=SM(AM,[["__scopeId","data-v-4f87bc73"]]),EM={install:a=>{a.component(bc.name,bc)},vue3dLoader:bc};return Yr.Three=Wb,Yr.default=EM,Yr.vue3dLoader=bc,Object.defineProperties(Yr,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Yr}({},Vue); +`);let i={};const s=/\s+/,r={};for(let c=0;c=0?l.substring(0,u):l;h=h.toLowerCase();let f=u>=0?l.substring(u+1):"";if(f=f.trim(),h==="newmtl")i={name:f},r[f]=i;else if(h==="ka"||h==="kd"||h==="ks"||h==="ke"){const d=f.split(s,3);i[h]=[parseFloat(d[0]),parseFloat(d[1]),parseFloat(d[2])]}else i[h]=f}const o=new xM(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class xM{constructor(e="",t={}){this.baseUrl=e,this.options=t,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.crossOrigin="anonymous",this.side=this.options.side!==void 0?this.options.side:Vn,this.wrap=this.options.wrap!==void 0?this.options.wrap:sn}setCrossOrigin(e){return this.crossOrigin=e,this}setManager(e){this.manager=e}setMaterials(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}convert(e){if(!this.options)return e;const t={};for(const n in e){const i=e[n],s={};t[n]=s;for(const r in i){let o=!0,c=i[r];const l=r.toLowerCase();switch(l){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(c=[c[0]/255,c[1]/255,c[2]/255]),this.options&&this.options.ignoreZeroRGBs&&c[0]===0&&c[1]===0&&c[2]===0&&(o=!1);break}o&&(s[l]=c)}}return t}preload(){for(const e in this.materialsInfo)this.create(e)}getIndex(e){return this.nameLookup[e]}getAsArray(){let e=0;for(const t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}create(e){return this.materials[e]===void 0&&this.createMaterial_(e),this.materials[e]}createMaterial_(e){const t=this,n=this.materialsInfo[e],i={name:e,side:this.side};function s(o,c){return typeof c!="string"||c===""?"":/^https?:\/\//i.test(c)?c:o+c}function r(o,c){if(i[o])return;const l=t.getTextureParams(c,i),u=t.loadTexture(s(t.baseUrl,l.url));u.repeat.copy(l.scale),u.offset.copy(l.offset),u.wrapS=t.wrap,u.wrapT=t.wrap,(o==="map"||o==="emissiveMap")&&(u.encoding=et),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new ye().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new ye().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new ye().fromArray(c).convertSRGBToLinear();break;case"map_kd":r("map",c);break;case"map_ks":r("specularMap",c);break;case"map_ke":r("emissiveMap",c);break;case"norm":r("normalMap",c);break;case"map_bump":case"bump":r("bumpMap",c);break;case"map_d":r("alphaMap",c),i.transparent=!0;break;case"ns":i.shininess=parseFloat(c);break;case"d":l=parseFloat(c),l<1&&(i.opacity=l,i.transparent=!0);break;case"tr":l=parseFloat(c),this.options&&this.options.invertTrProperty&&(l=1-l),l>0&&(i.opacity=1-l,i.transparent=!0);break}}return this.materials[e]=new Zn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new le(1,1),offset:new le(0,0)},i=e.split(/\s+/);let s;return s=i.indexOf("-bm"),s>=0&&(t.bumpScale=parseFloat(i[s+1]),i.splice(s,2)),s=i.indexOf("-s"),s>=0&&(n.scale.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),s=i.indexOf("-o"),s>=0&&(n.offset.set(parseFloat(i[s+1]),parseFloat(i[s+2])),i.splice(s,4)),n.url=i.join(" ").trim(),n}loadTexture(e,t,n,i,s){const r=this.manager!==void 0?this.manager:hu;let o=r.getHandler(e);o===null&&(o=new Rs(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const _c=new ai,Qn=new Nm;Qn.addHandler(/\.dds$/i,new pM),Qn.addHandler(/\.tga$/i,new Yu);function vM(a){return _c.setFromObject(a),_c.getSize(new D)}function _M(a){return _c.setFromObject(a),_c.getCenter(new D)}function bM(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function wM(a){let e=bM(a);e==="glb"&&(e="gltf");let t={loader:null,getObject:null};switch(e){case"dae":t={loader:new Iw(Qn),getObject:n=>n.scene};break;case"fbx":t={loader:new vw(Qn)};break;case"gltf":t={loader:new Pw(Qn),getObject:n=>n.scene};break;case"obj":t={loader:new dM(Qn)};break;case"ply":t={loader:new mM(Qn),getObject:n=>(n.computeVertexNormals(),new St(n,new Ts))};break;case"stl":t={loader:new gM(Qn),getObject:n=>new St(n,new Zn)};break;case"json":t={loader:new tp(Qn)};break}return t}function MM(){return new yM(Qn)}var d1="",SM=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const TM=At.defineComponent({name:"vue3dLoader"}),AM=At.defineComponent({...TM,props:{filePath:null,width:null,height:null,position:null,rotation:null,scale:null,lights:{default:()=>[{type:"AmbientLight",color:11184810},{type:"DirectionalLight",position:{x:1,y:1,z:1},color:16777215,intensity:.8}]},cameraPosition:{default:()=>({x:0,y:0,z:0})},cameraRotation:null,cameraUp:null,cameraLookAt:null,backgroundColor:{default:()=>16777215},backgroundAlpha:{default:()=>1},controlsOptions:null,crossOrigin:{default:"anonymous"},requestHeader:null,outputEncoding:{default:()=>"linear"},webGLRendererOptions:{default:()=>({})},mtlPath:{default:""},showFps:{type:Boolean,default:!1},textureImage:{default:""},clearScene:{type:Boolean,default:!1},parallelLoad:{type:Boolean,default:!1},labels:{default:()=>[]}},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new dp,s=new le,r=new It(45,1,1,1e5),o=new Ia,c=new ot;let l=null,u={},h=[];const f=new gu;let d=null,m=0,p=null,g=null,y=null;const x=At.ref({width:t.width||0,height:t.height||0}),b=At.ref(0),v=At.ref(),T=At.ref(!1),A=At.ref(null),L=At.ref(!1),_=At.ref(null),R=At.ref(null);At.watch([()=>t.filePath,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],E=>{E[0]&&re(),E[1]&&De(),(E[2]||E[3])&&Y()}),At.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],E=>{E[0]&&Ee("rotation",E[0]),E[1]&&Ee("position",E[1]),E[2]&&Ee("scale",E[2]),E[3]&&J()},{deep:!0}),At.watch([()=>x],()=>{ee(!0),Y()},{deep:!0}),At.watch([()=>t.controlsOptions],()=>{ie()},{deep:!0}),At.watch([()=>t.cameraRotation],()=>{ee()},{deep:!0}),At.watch([()=>t.cameraPosition],()=>{ee()},{deep:!0}),At.onMounted(()=>{const{filePath:E,outputEncoding:w,webGLRendererOptions:G,showFps:Z}=t;E&&typeof E=="object"&&(L.value=!0);const $=_.value;O($),z();const Re=Object.assign({},{antialias:!0,alpha:!0},G,{canvas:R.value});l=new Wl(Re),l.shadowMap.enabled=!0;const F=w==="linear"?ri:et;l.outputEncoding=F,u=new Xb(r,$),o.add(c),re(),j(),$.addEventListener("mousedown",W,!1),$.addEventListener("mousemove",K,!1),$.addEventListener("mouseup",U,!1),$.addEventListener("click",q,!1),$.addEventListener("dblclick",k,!1),window.addEventListener("resize",z,!1),Z&&(p=Ro(),$.appendChild(p.dom)),pe()}),At.onBeforeUnmount(()=>{cancelAnimationFrame(m),l.dispose(),u&&u.dispose();const E=_.value;E.removeEventListener("mousedown",W,!1),E.removeEventListener("mousemove",K,!1),E.removeEventListener("mouseup",U,!1),E.removeEventListener("click",q,!1),E.removeEventListener("dblclick",k,!1),window.removeEventListener("resize",z,!1)});function O(E){const{width:w,height:G}=t;w&&(E.style.width=`${w}px`),G&&(E.style.height=`${G}px`)}function z(){const{width:E,height:w}=t;(!E||!w)&&At.nextTick(()=>{const G=_.value;x.value={width:E||G.offsetWidth,height:w||G.offsetHeight}})}function W(E){const w=X(E.clientX,E.clientY);e("mousedown",E,w)}function K(E){const w=()=>{const G=X(E.clientX,E.clientY);e("mousemove",E,G)};L.value?(clearTimeout(A.value),A.value=setTimeout(()=>{w()},200)):w()}function U(E){const w=X(E.clientX,E.clientY);e("mouseup",E,w)}function q(E){const w=X(E.clientX,E.clientY);e("click",E,w)}function k(E){const w=X(E.clientX,E.clientY);e("dblclick",E,w)}function X(E,w){const G=je();if(!G)return null;if(!_.value)return;const Z=_.value.getBoundingClientRect();E-=Z.left,w-=Z.top,s.x=E/x.value.width*2-1,s.y=-(w/x.value.height)*2+1,i.setFromCamera(s,r);const $=i.intersectObject(G,!0);return($&&$.length)>0?$[0]:null}function j(E=!1){Y(),ee(E),J(),ie()}function H(){const{position:E,rotation:w,scale:G}=t;if(!n)return;const Z=L.value?at(n):null;E&&(E instanceof Array?Z!=null?n.position.set(E[Z].x,E[Z].y,E[Z].z):n.position.set(0,0,0):n.position.set(E.x,E.y,E.z)),w&&(w instanceof Array?Z!=null?n.rotation.set(w[Z].x,w[Z].y,w[Z].z):n.rotation.set(0,0,0):n.rotation.set(w.x,w.y,w.z)),G&&(G instanceof Array?Z!=null?n.scale.set(G[Z].x,G[Z].y,G[Z].z):n.scale.set(0,0,0):n.scale.set(G.x,G.y,G.z))}function Y(){const{backgroundColor:E,backgroundAlpha:w}=t;l.setSize(x.value.width,x.value.height),l.setPixelRatio(window.devicePixelRatio||1),l.setClearColor(new ye(E).getHex()),l.setClearAlpha(w)}function ee(E){const{cameraPosition:w,cameraRotation:G,cameraUp:Z,cameraLookAt:$}=t;if(r.aspect=x.value.width/x.value.height,r.updateProjectionMatrix(),!E)if(!$||!Z){if(!n)return;const he=vM(n).length();r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),w.x===0&&w.y===0&&w.z===0&&(r.position.z=he),r.lookAt(new D)}else r.position.set(w.x,w.y,w.z),G&&r.rotation.set(G.x,G.y,G.z),r.up.set(Z.x,Z.y,Z.z),r.lookAt(new D($.x,$.y,$.z))}function J(){const{lights:E}=t;o.remove(...h),h=[],E.forEach(w=>{if(!w.type)return;const G=w.type.toLowerCase();let Z=null;if(G==="ambient"||G==="ambientlight"){const $=w.color===0?w.color:w.color||4210752,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Lo($,he)}else if(G==="point"||G==="pointlight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1,Re=w.distance||0,F=w.decay===0?w.decay:w.decay||1;Z=new Is($,he,Re,F),w.position&&Z.position.copy(w.position)}else if(G==="directional"||G==="directionallight"){const $=w.color===0?w.color:w.color||16777215,he=w.intensity===0?w.intensity:w.intensity||1;Z=new Ir($,he),w.position&&Z.position.copy(w.position),w.target&&Z.target.copy(w.target)}else if(G==="hemisphere"||G==="hemispherelight"){const $=w.skyColor===0?w.skyColor:w.skyColor||16777215,he=w.groundColor===0?w.groundColor:w.groundColor||16777215,Re=w.intensity===0?w.intensity:w.intensity||1;Z=new fu($,he,Re),w.position&&Z.position.copy(w.position)}Z&&(h.push(Z),o.add(Z))})}function ie(){const{controlsOptions:E}=t;E&&Object.assign(u,E)}function re(){const{filePath:E,parallelLoad:w}=t;w&&L?E.forEach((G,Z)=>{te(Z)}):te()}function te(E){const{filePath:w,crossOrigin:G,requestHeader:Z,mtlPath:$}=t;if(!w)return;const he=E||b.value,Re=L.value?w[he]:w,F=wM(Re);d=F.loader;const fe=F.getObject?F.getObject:Ae;if(n&&he===0&&c.remove(n),Z&&d.setRequestHeader(Z),G&&d.setCrossOrigin(G),$)if(typeof $=="string")ge(Re,fe,he);else{if(!$[he]){V(Re,fe,he);return}ge(Re,fe,he)}else V(Re,fe,he)}function V(E,w,G){const{textureImage:Z,parallelLoad:$}=t;d.load(E,(...he)=>{if(n=w(...he),Pe(n,E),g=new fp(n),n.animations&&n.animations.forEach(F=>{g.clipAction(F).play()}),Z){const F=typeof Z=="string"?Z:Z[G];F&&xe(n,F)}He(),e("load",c)},he=>{$||ae(he);const Re=b.value+1;e("process",he,Re)},he=>{e("error",he)})}function ge(E,w,G){const{crossOrigin:Z,requestHeader:$,mtlPath:he}=t,Re=MM();Z&&Re.setCrossOrigin(Z),$&&Re.setRequestHeader($);const F=typeof he=="string"?he:he[G],fe=/^(.*\/)([^/]*)$/.exec(F),we=fe[1],Me=fe[2];Re.setPath(we).load(Me,B=>{B.preload(),d.setMaterials(B),V(E,w,G)})}function Ae(E){return E}function Pe(E,w){const G=_M(n);T.value||(c.position.copy(G.negate()),T.value=!0),n=E;let Z=w.split("/");Z=Z[Z.length-1],n.fileName=Z,c.add(n),ee(),H()}function pe(){m=requestAnimationFrame(pe),ce();const E=f.getDelta();g&&g.update(E),Ue()}function Ue(){l.render(o,r)}function ce(){const{showFps:E}=t;E&&p.update()}function ae(E){const{filePath:w}=t;let G=Math.floor(E.loaded/E.total*100);const Z=()=>{G===100&&(L.value&&w.length>b.value?At.nextTick(()=>{if(b.value++,b.value===w.length){b.value=0;return}te()}):b.value=0)};G===1/0&&(clearTimeout(v.value),v.value=setTimeout(()=>{G=100,Z()},200)),Z()}function xe(E,w){y||(y=new Rs),E.traverse(G=>{G.isMesh&&y.load(w,Z=>{G.material.map=Z,G.material.needsUpdate=!0},()=>{},Z=>{e("error",Z)})})}function De(){c.clear()}function Ee(E,w){const G=je();if(!!G){if(L.value){G.children.forEach(Z=>{const $=at(Z),he=E==="scale"?1:0;w[$]?Z[E].set(w[$].x,w[$].y,w[$].z):Z[E].set(he,he,he)});return}G[E].set(w.x,w.y,w.z)}}function je(){return L.value?c:n}function He(){const{filePath:E}=t;L.value?b.value===E.length&&ze():ze()}function ze(){const{labels:E}=t;if(!E)return;const w=L.value?c:n,G=$=>(y||(y=new Rs),y.load($)),Z=($,he)=>{const Re=ft($,he),F=new Mt(Re);return F.needsUpdate=!0,F};E.forEach($=>{const he=$.image?G($.image):Z($.text,$.textStyle||{}),Re=new Pa({map:he,color:$.spriteMaterialColor||16777215}),F=new ql(Re);$.scale?F.scale.set($.scale.x||1,$.scale.y||1,$.scale.z||0):F.scale.set(1,1,0),$.position&&F.position.set($.position.x,$.position.y,$.position.z),$.sid&&(F.sid=$.sid),w.add(F)})}function ft(E,w){w===void 0&&(w={});const G=(me,Fe,Se,ke,be,Ge)=>{me.beginPath(),me.moveTo(Fe+Ge,Se),me.lineTo(Fe+ke-Ge,Se),me.quadraticCurveTo(Fe+ke,Se,Fe+ke,Se+Ge),me.lineTo(Fe+ke,Se+be-Ge),me.quadraticCurveTo(Fe+ke,Se+be,Fe+ke-Ge,Se+be),me.lineTo(Fe+Ge,Se+be),me.quadraticCurveTo(Fe,Se+be,Fe,Se+be-Ge),me.lineTo(Fe,Se+Ge),me.quadraticCurveTo(Fe,Se,Fe+Ge,Se),me.closePath(),me.fill(),me.stroke()},Z=w.fontFamily||"Arial",$=w.fontSize===0||w.fontSize?w.fontSize:18,he=w.color||"#ffffff",Re=w.fontWeight||"normal",F=w.borderWidth===0||w.borderWidth?w.borderWidth:4,fe=w.borderColor||"rgba(0,0,0,1)",we=w.borderRadius===0||w.borderRadius?w.borderRadius:4,Me=w.backgroundColor||"rgba(255, 255, 255, 1)",B=document.createElement("canvas"),ve=B.getContext("2d");if(ve){ve.font=`${Re} ${$}px ${Z}`;const Fe=ve.measureText(E).width;ve.fillStyle=Me,ve.strokeStyle=fe,ve.lineWidth=F,G(ve,F/2,F/2,Fe+F,$*1.4+F,we),ve.fillStyle=he,ve.fillText(E,F,$+F)}return B}function at(E){const{filePath:w}=t;let G;return w instanceof Array&&(G=w.map((Z,$)=>{if(Z.indexOf(E.fileName)>-1)return $}).filter(Z=>Z!=null)[0]),G}return(E,w)=>(At.openBlock(),At.createElementBlock("div",{ref_key:"containerElement",ref:_,class:"viewer-container"},[At.createElementVNode("canvas",{ref_key:"canvasElement",ref:R,class:"viewer-canvas"},null,512)],512))}});var bc=SM(AM,[["__scopeId","data-v-29f70b62"]]),EM={install:a=>{a.component(bc.name,bc)},vue3dLoader:bc};return Yr.Three=Wb,Yr.default=EM,Yr.vue3dLoader=bc,Object.defineProperties(Yr,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Yr}({},Vue);