diff --git a/dist/vue-3d-loader.cjs.js b/dist/vue-3d-loader.cjs.js index 390c4c4..63f787a 100644 --- a/dist/vue-3d-loader.cjs.js +++ b/dist/vue-3d-loader.cjs.js @@ -3156,4 +3156,4 @@ version 0.6.9 `)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(` `);let i=[];for(let o=0,c=n.length;o=7?(qa.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6])).convertSRGBToLinear(),t.colors.push(qa.r,qa.g,qa.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(ad),d=[];for(let m=0,g=f.length;m0){const y=x.split("/");d.push(y)}}const p=d[0];for(let m=1,g=d.length-1;m1){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 yn;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&&m.setAttribute("normal",new Ae(u.normals,3)),u.colors.length>0&&(p=!0,m.setAttribute("color",new Ae(u.colors,3))),u.hasUVIndices===!0&&m.setAttribute("uv",new Ae(u.uvs,2));const g=[];for(let y=0,b=h.length;y1){for(let y=0,b=h.length;y0){const o=new Hi({size:1,sizeAttenuation:!1}),c=new qe;c.setAttribute("position",new Ae(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(c.setAttribute("color",new Ae(t.colors,3)),o.vertexColors=!0);const l=new xr(c,o);s.add(l)}return s}}class r1 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(oe){return oe.charCodeAt(0)+(oe.charCodeAt(1)<<8)+(oe.charCodeAt(2)<<16)+(oe.charCodeAt(3)<<24)}function p(oe){return String.fromCharCode(oe&255,oe>>8&255,oe>>16&255,oe>>24&255)}function m(oe,H,ye,we){const Pe=ye*we*4,xe=new Uint8Array(oe,H,Pe),Ve=new Uint8Array(Pe);let he=0,ue=0;for(let ve=0;ve>1,1),ye=Math.max(ye>>1,1)}}return n}}class o1{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=p.elements[v].count&&(v++,M=0);const _=i(p.elements[v].properties,C);o(m,p.elements[v].name,_),M++}return r(m)}function r(d){let p=new qe;return d.indices.length>0&&p.setIndex(d.indices),p.setAttribute("position",new Ae(d.vertices,3)),d.normals.length>0&&p.setAttribute("normal",new Ae(d.normals,3)),d.uvs.length>0&&p.setAttribute("uv",new Ae(d.uvs,2)),d.colors.length>0&&p.setAttribute("color",new Ae(d.colors,3)),d.faceVertexUvs.length>0&&(p=p.toNonIndexed(),p.setAttribute("uv",new Ae(d.faceVertexUvs,2))),p.computeBoundingSphere(),p}function o(d,p,m){function g(q){for(let J=0,G=q.length;J>5&31)/31,p=(X>>10&31)/31):(f=x,d=y,p=b)}for(let X=1;X<=3;X++){const B=U+X*12,Z=F*3*3+(X-1)*3;_[Z]=u.getFloat32(B,!0),_[Z+1]=u.getFloat32(B+4,!0),_[Z+2]=u.getFloat32(B+8,!0),E[Z]=q,E[Z+1]=J,E[Z+2]=G,m&&(g[Z]=f,g[Z+1]=d,g[Z+2]=p)}}return C.setAttribute("position",new pt(_,3)),C.setAttribute("normal",new pt(E,3)),m&&(C.setAttribute("color",new pt(g,3)),C.hasColors=!0,C.alpha=v),C}function s(l){const u=new qe,h=/solid([\s\S]*?)endsolid/g,f=/facet([\s\S]*?)endfacet/g;let d=0;const p=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,m=new RegExp("vertex"+p+p+p,"g"),g=new RegExp("normal"+p+p+p,"g"),x=[],y=[],b=new P;let v,M=0,T=0,C=0;for(;(v=h.exec(l))!==null;){T=C;const _=v[0];for(;(v=f.exec(_))!==null;){let U=0,q=0;const J=v[0];for(;(v=g.exec(J))!==null;)b.x=parseFloat(v[1]),b.y=parseFloat(v[2]),b.z=parseFloat(v[3]),q++;for(;(v=m.exec(J))!==null;)x.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),y.push(b.x,b.y,b.z),U++,C++;q!==1&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+d),U!==3&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+d),d++}const E=T,F=C-T;u.addGroup(E,F,M),M++}return u.setAttribute("position",new Ae(x,3)),u.setAttribute("normal",new Ae(y,3)),u}function r(l){return typeof l!="string"?tn.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 u1(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class u1{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:vi,this.wrap=this.options.wrap!==void 0?this.options.wrap:cn}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=nt),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new be().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new be().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new be().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 Qn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new de(1,1),offset:new de(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:Yu;let o=r.getHandler(e);o===null&&(o=new ks(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const Al=new WeakMap;class h1 extends Ht{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,i){const s=new Kt(this.manager);s.setPath(this.path),s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,r=>{const o={attributeIDs:this.defaultAttributeIDs,attributeTypes:this.defaultAttributeTypes,useUniqueIDs:!1};this.decodeGeometry(r,o).then(t).catch(i)},n,i)}decodeDracoFile(e,t,n,i){const s={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:i||this.defaultAttributeTypes,useUniqueIDs:!!n};this.decodeGeometry(e,s).then(t)}decodeGeometry(e,t){for(const c in t.attributeTypes){const l=t.attributeTypes[c];l.BYTES_PER_ELEMENT!==void 0&&(t.attributeTypes[c]=l.name)}const n=JSON.stringify(t);if(Al.has(e)){const c=Al.get(e);if(c.key===n)return c.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let i;const s=this.workerNextTaskID++,r=e.byteLength,o=this._getWorker(s,r).then(c=>(i=c,new Promise((l,u)=>{i._callbacks[s]={resolve:l,reject:u},i.postMessage({type:"decode",id:s,taskConfig:t,buffer:e},[e])}))).then(c=>this._createGeometry(c.geometry));return o.catch(()=>!0).then(()=>{i&&s&&this._releaseTask(i,s)}),Al.set(e,{key:n,promise:o}),o}_createGeometry(e){const t=new qe;e.index&&t.setIndex(new pt(e.index.array,1));for(let n=0;n{n.load(e,i,void 0,s)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(n=>{const i=n[0];e||(this.decoderConfig.wasmBinary=n[1]);const s=f1.toString(),r=["/* draco decoder */",i,"","/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join(` -`);this.workerSourceURL=URL.createObjectURL(new Blob([r]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.lengths._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e{const h=u.draco,f=new h.Decoder,d=new h.DecoderBuffer;d.Init(new Int8Array(c),c.byteLength);try{const p=t(h,f,d,l),m=p.attributes.map(g=>g.array.buffer);p.index&&m.push(p.index.array.buffer),self.postMessage({type:"decode",id:o.id,geometry:p},m)}catch(p){console.error(p),self.postMessage({type:"error",id:o.id,error:p.message})}finally{h.destroy(d),h.destroy(f)}});break}};function t(r,o,c,l){const u=l.attributeIDs,h=l.attributeTypes;let f,d;const p=o.GetEncodedGeometryType(c);if(p===r.TRIANGULAR_MESH)f=new r.Mesh,d=o.DecodeBufferToMesh(c,f);else if(p===r.POINT_CLOUD)f=new r.PointCloud,d=o.DecodeBufferToPointCloud(c,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!d.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+d.error_msg());const m={index:null,attributes:[]};for(const g in u){const x=self[h[g]];let y,b;if(l.useUniqueIDs)b=u[g],y=o.GetAttributeByUniqueId(f,b);else{if(b=o.GetAttributeId(f,r[u[g]]),b===-1)continue;y=o.GetAttribute(f,b)}m.attributes.push(i(r,o,f,g,x,y))}return p===r.TRIANGULAR_MESH&&(m.index=n(r,o,f)),r.destroy(f),m}function n(r,o,c){const u=c.num_faces()*3,h=u*4,f=r._malloc(h);o.GetTrianglesUInt32Array(c,h,f);const d=new Uint32Array(r.HEAPF32.buffer,f,u).slice();return r._free(f),{array:d,itemSize:1}}function i(r,o,c,l,u,h){const f=h.num_components(),p=c.num_points()*f,m=p*u.BYTES_PER_ELEMENT,g=s(r,u),x=r._malloc(m);o.GetAttributeDataArrayForAllPoints(c,h,g,m,x);const y=new u(r.HEAPF32.buffer,x,p).slice();return r._free(x),{name:l,array:y,itemSize:f}}function s(r,o){switch(o){case Float32Array:return r.DT_FLOAT32;case Int8Array:return r.DT_INT8;case Int16Array:return r.DT_INT16;case Int32Array:return r.DT_INT32;case Uint8Array:return r.DT_UINT8;case Uint16Array:return r.DT_UINT16;case Uint32Array:return r.DT_UINT32}}}const fc=new Ei,Kn=new o1;Kn.addHandler(/\.dds$/i,new r1);Kn.addHandler(/\.tga$/i,new yu);function d1(a){return fc.setFromObject(a),fc.getSize(new P)}function p1(a){return fc.setFromObject(a),fc.getCenter(new P)}function m1(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function g1(a,e,t,n){let i;e?i=e:i=m1(a),i==="glb"&&(i="gltf");let s={loader:null,getObject:null};switch(i){case"dae":s={loader:new wM(Kn),getObject:r=>r.scene};break;case"fbx":s={loader:new uM(Kn)};break;case"gltf":s={loader:new MM(Kn),getObject:r=>r.scene},x1(t,s,n);break;case"obj":s={loader:new s1(Kn)};break;case"ply":s={loader:new a1(Kn),getObject:r=>(r.computeVertexNormals(),new Tt(r,new Us))};break;case"stl":s={loader:new c1(Kn),getObject:r=>new Tt(r,new Qn)};break;case"json":s={loader:new tm(Kn)};break}return s}function y1(){return new l1(Kn)}function x1(a,e,t){if(a){const n=new h1;n.setDecoderPath(t||"assets/draco/gltf/"),n.setDecoderConfig({type:"js"}),e.loader.setDRACOLoader(n)}}var v1=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const _1=kt.defineComponent({name:"vue3dLoader"}),b1=kt.defineComponent({..._1,props:{filePath:null,fileType: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:()=>[]},autoPlay:{type:Boolean,default:!0},enableDraco:{type:Boolean,default:!1},dracoDir:null,intersectRecursive:{type:Boolean,default:!1},enableDamping:{type:Boolean},dampingFactor:null},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new rm,s=new de,r=new Dt(45,1,1,1e5),o=new Ac,c=new $u;let l=new ut,u=null,h={},f=[],d=null,p=0,m=null,g=null,x=null;const y=kt.ref({width:t.width||0,height:t.height||0}),b=kt.ref(0),v=kt.ref(!1),M=kt.ref(!1),T=kt.ref(null),C=kt.ref(null);kt.watch([()=>t.filePath,()=>t.fileType,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],k=>{(k[0]||k[1])&&ie(),k[2]&&ve(),(k[3]||k[4])&&W()}),kt.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],k=>{const z=["rotation","position","scale"];k.forEach((K,Q)=>{Q<3&&K?Fe(z[Q],K):ne()})},{deep:!0}),kt.watch([()=>y],()=>{j(!0),W()},{deep:!0}),kt.watch([()=>t.controlsOptions],()=>{$()},{deep:!0}),kt.watch([()=>t.cameraRotation,()=>t.cameraPosition],()=>{j()},{deep:!0}),kt.watch([()=>t.autoPlay],()=>{at()}),kt.onMounted(()=>{const{filePath:k,outputEncoding:z,webGLRendererOptions:K,showFps:Q,enableDamping:me,dampingFactor:R}=t;k&&typeof k=="object"&&(M.value=!0);const ae=T.value;_(ae),F();const Se=Object.assign({},{antialias:!0,alpha:!0},K,{canvas:C.value});u=new Fu(Se),u.shadowMap.enabled=!0;const Te=z==="linear"?bi:nt;u.outputEncoding=Te,h=new kw(r,ae),me&&(h.enableDamping=!0,R!=null&&(h.dampingFactor=R)),o.add(l),ie(),Z(),E(!0),ae.addEventListener("mousedown",U,!1),ae.addEventListener("mouseup",J,!1),ae.addEventListener("click",G,!1),ae.addEventListener("dblclick",X,!1),window.addEventListener("resize",F,!1),Q&&(m=xo(),ae.appendChild(m.dom)),Pe()}),kt.onBeforeUnmount(()=>{cancelAnimationFrame(p),u.dispose(),h&&h.dispose();const k=T.value;k.removeEventListener("mousedown",U,!1),k.removeEventListener("mousemove",q,!1),k.removeEventListener("mouseup",J,!1),k.removeEventListener("click",G,!1),k.removeEventListener("dblclick",X,!1),window.removeEventListener("resize",F,!1),n=null,l=null});function _(k){const{width:z,height:K}=t;z&&(k.style.width=`${z}px`),K&&(k.style.height=`${K}px`)}function E(k){const z=T.value;k?z.addEventListener("mousemove",q,!1):z.removeEventListener("mousemove",q,!1)}function F(){const{width:k,height:z}=t;(!k||!z)&&kt.nextTick(()=>{const K=T.value;y.value={width:k||K.offsetWidth,height:z||K.offsetHeight}})}function U(k){E(!1);const z=B(k.clientX,k.clientY);e("mousedown",k,z)}function q(k){const z=B(k.clientX,k.clientY);e("mousemove",k,z)}function J(k){const z=B(k.clientX,k.clientY);e("mouseup",k,z),E(!0)}function G(k){const z=B(k.clientX,k.clientY);e("click",k,z)}function X(k){const z=B(k.clientX,k.clientY);e("dblclick",k,z)}function B(k,z){const K=Ee();if(!K||!T.value)return null;const Q=T.value.getBoundingClientRect();k-=Q.left,z-=Q.top,s.x=k/y.value.width*2-1,s.y=-(z/y.value.height)*2+1,i.setFromCamera(s,r);const me=i.intersectObject(K,t.intersectRecursive);return(me&&me.length)>0?me[0]:null}function Z(){W(),j(),ne(),$()}function Y(){if(!n)return;const k=M.value?ht(n):null,{position:z,rotation:K,scale:Q}=t;z&&(z instanceof Array?k!=null?n.position.set(z[k].x,z[k].y,z[k].z):n.position.set(0,0,0):n.position.set(z.x,z.y,z.z)),K&&(K instanceof Array?k!=null?n.rotation.set(K[k].x,K[k].y,K[k].z):n.rotation.set(0,0,0):n.rotation.set(K.x,K.y,K.z)),Q&&(Q instanceof Array?k!=null?n.scale.set(Q[k].x,Q[k].y,Q[k].z):n.scale.set(0,0,0):n.scale.set(Q.x,Q.y,Q.z))}function W(){const{backgroundColor:k,backgroundAlpha:z}=t;u.setSize(y.value.width,y.value.height),u.setPixelRatio(window.devicePixelRatio||1),u.setClearColor(new be(k).getHex()),u.setClearAlpha(z)}function j(k){const{cameraPosition:z,cameraRotation:K,cameraUp:Q,cameraLookAt:me}=t;if(r.aspect=y.value.width/y.value.height,r.updateProjectionMatrix(),!k)if(!me||!Q){if(!n)return;const R=d1(n).length();r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),z.x===0&&z.y===0&&z.z===0&&(r.position.z=R),r.lookAt(new P)}else r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),r.up.set(Q.x,Q.y,Q.z),r.lookAt(new P(me.x,me.y,me.z))}function ne(){const{lights:k}=t;o.remove(...f),f=[],k.forEach(z=>{if(!z.type)return;const K=z.type.toLowerCase();let Q=null;if(K==="ambient"||K==="ambientlight"){const me=z.color===0?z.color:z.color||4210752,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Wo(me,R)}if(K==="point"||K==="pointlight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1,ae=z.distance||0,pe=z.decay===0?z.decay:z.decay||1;Q=new Os(me,R,ae,pe),z.position&&Q.position.copy(z.position)}if(K==="directional"||K==="directionallight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Vr(me,R),z.position&&Q.position.copy(z.position),z.target&&Q.target.copy(z.target)}if(K==="hemisphere"||K==="hemispherelight"){const me=z.skyColor===0?z.skyColor:z.skyColor||16777215,R=z.groundColor===0?z.groundColor:z.groundColor||16777215,ae=z.intensity===0?z.intensity:z.intensity||1;Q=new Zu(me,R,ae),z.position&&Q.position.copy(z.position)}Q&&(f.push(Q),o.add(Q))})}function $(){const{controlsOptions:k}=t;k&&Object.assign(h,k)}function ie(){const{filePath:k,parallelLoad:z}=t;z&&M?k.forEach((K,Q)=>{ce(Q)}):ce()}function ce(k){const{filePath:z,fileType:K,crossOrigin:Q,requestHeader:me,mtlPath:R,enableDraco:ae,dracoDir:pe}=t;if(!z)return;const Se=k||b.value,Te=M.value?z[Se]:z,He=typeof K=="string"?K:K?K[Se]:"",Ze=g1(Te,He,ae,pe);d=Ze.loader;const Qe=Ze.getObject?Ze.getObject:ye;if(n&&Se===0&&l.remove(n),me&&d.setRequestHeader(me),Q&&d.setCrossOrigin(Q),R)if(!(typeof R=="object"))H(Te,Qe,Se);else{if(!R[Se]){oe(Te,Qe,Se);return}H(Te,Qe,Se)}else oe(Te,Qe,Se)}function oe(k,z,K){const{textureImage:Q,parallelLoad:me}=t;d.load(k,(...R)=>{if(n=z(...R),we(n,k),Q){const pe=typeof Q=="string"?Q:Q[K];pe&&ue(n,pe)}je(),e("load",l)},R=>{me||he(R);const ae=b.value+1;e("process",R,ae)},R=>{e("error",R)})}function H(k,z,K){const{crossOrigin:Q,requestHeader:me,mtlPath:R}=t,ae=y1();Q&&ae.setCrossOrigin(Q),me&&ae.setRequestHeader(me);const pe=typeof R=="string"?R:R[K],Se=/^(.*\/)([^/]*)$/.exec(pe),Te=Se[1],He=Se[2];ae.setPath(Te).load(He,Ze=>{Ze.preload(),d.setMaterials(Ze),oe(k,z,K)})}function ye(k){return k}function we(k,z){const K=p1(n);v.value||(l.position.copy(K.negate()),v.value=!0),n=k;let Q=z.split("/");Q=Q[Q.length-1],n.fileName=Q,l.add(n),j(),Y(),at()}function Pe(){p=requestAnimationFrame(Pe),Ve();const k=c.getDelta();g&&g instanceof $a&&g.update(k),g&&g instanceof Array&&g.forEach(z=>{z.update(k)}),xe()}function xe(){u.render(o,r)}function Ve(){const{showFps:k}=t;k&&m.update()}function he(k){const{filePath:z}=t;Math.floor(k.loaded/k.total*100)===100&&(M.value&&z.length>b.value?kt.nextTick(()=>{if(b.value++,b.value===z.length){b.value=0;return}ce()}):b.value=0)}function ue(k,z){x||(x=new ks),k.traverse(K=>{K.isMesh&&x.load(z,Q=>{K.material.map=Q,K.material.needsUpdate=!0},()=>{},Q=>{e("error",Q)})})}function ve(){l.clear()}function Fe(k,z){const K=Ee();if(!!K){if(M.value){K.children.forEach(Q=>{const me=ht(Q),R=k==="scale"?1:0;z[me]?Q[k].set(z[me].x,z[me].y,z[me].z):Q[k].set(R,R,R)});return}K[k].set(z.x,z.y,z.z)}}function Ee(){return M.value?l:n}function je(){const{filePath:k}=t;M.value?b.value===k.length&&ze():ze()}function ze(){const{labels:k}=t;if(!k)return;const z=M.value?l:n,K=me=>(x||(x=new ks),x.load(me)),Q=(me,R)=>{const ae=Be(me,R),pe=new At(ae);return pe.needsUpdate=!0,pe};k.forEach(me=>{const R=me.image?K(me.image):Q(me.text,me.textStyle||{}),ae=new Ec({map:R,color:me.spriteMaterialColor||16777215}),pe=new Nu(ae);me.scale?pe.scale.set(me.scale.x||1,me.scale.y||1,me.scale.z||0):pe.scale.set(1,1,0),me.position&&pe.position.set(me.position.x,me.position.y,me.position.z),me.sid&&(pe.sid=me.sid),z.add(pe)})}function Be(k,z){const K=(V,_e,re,Re,Ce,Je)=>{V.beginPath(),V.moveTo(_e+Je,re),V.lineTo(_e+Re-Je,re),V.quadraticCurveTo(_e+Re,re,_e+Re,re+Je),V.lineTo(_e+Re,re+Ce-Je),V.quadraticCurveTo(_e+Re,re+Ce,_e+Re-Je,re+Ce),V.lineTo(_e+Je,re+Ce),V.quadraticCurveTo(_e,re+Ce,_e,re+Ce-Je),V.lineTo(_e,re+Je),V.quadraticCurveTo(_e,re,_e+Je,re),V.closePath(),V.fill(),V.stroke()},Q=z.fontFamily||"Arial",me=z.fontSize===0||z.fontSize?z.fontSize:18,R=z.color||"#ffffff",ae=z.fontWeight||"normal",pe=z.borderWidth===0||z.borderWidth?z.borderWidth:4,Se=z.borderColor||"rgba(0,0,0,1)",Te=z.borderRadius===0||z.borderRadius?z.borderRadius:4,He=z.backgroundColor||"rgba(255, 255, 255, 1)",Ze=document.createElement("canvas"),Qe=Ze.getContext("2d");if(Qe){Qe.font=`${ae} ${me}px ${Q}`;const _e=Qe.measureText(k).width;Qe.fillStyle=He,Qe.strokeStyle=Se,Qe.lineWidth=pe,K(Qe,pe/2,pe/2,_e+pe,me*1.4+pe,Te),Qe.fillStyle=R,Qe.fillText(k,pe,me+pe)}return Ze}function ht(k){const{filePath:z}=t;let K;return z instanceof Array&&(K=z.map((Q,me)=>{if(Q.indexOf(k.fileName)>-1)return me}).filter(Q=>Q!=null)[0]),K}function at(){const k=Ee();if(!!k){if(M.value){D(k);return}O(k)}}function O(k){const{autoPlay:z}=t;g=new $a(k),k.animations&&k.animations.length>0&&k.animations.forEach(K=>{if(K){const Q=g.clipAction(K);z?Q.play():Q.stop()}})}function D(k){const{autoPlay:z}=t;g=[],k.children.forEach((K,Q)=>{g.push(new $a(K)),K.animations&&K.animations.length>0&&K.animations.forEach(me=>{if(me){const R=g[Q].clipAction(me);z?R.play():R.stop()}})})}return(k,z)=>(kt.openBlock(),kt.createElementBlock("div",{ref_key:"containerElement",ref:T,class:"viewer-container"},[kt.createElementVNode("canvas",{ref_key:"canvasElement",ref:C,class:"viewer-canvas"},null,512)],512))}});var dc=v1(b1,[["__scopeId","data-v-04ca652e"]]);const w1=a=>{a.component(dc.name,dc)};var M1={install:w1,vue3dLoader:dc};exports.Three=Nw;exports.default=M1;exports.vue3dLoader=dc; +`);this.workerSourceURL=URL.createObjectURL(new Blob([r]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.lengths._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e{const h=u.draco,f=new h.Decoder,d=new h.DecoderBuffer;d.Init(new Int8Array(c),c.byteLength);try{const p=t(h,f,d,l),m=p.attributes.map(g=>g.array.buffer);p.index&&m.push(p.index.array.buffer),self.postMessage({type:"decode",id:o.id,geometry:p},m)}catch(p){console.error(p),self.postMessage({type:"error",id:o.id,error:p.message})}finally{h.destroy(d),h.destroy(f)}});break}};function t(r,o,c,l){const u=l.attributeIDs,h=l.attributeTypes;let f,d;const p=o.GetEncodedGeometryType(c);if(p===r.TRIANGULAR_MESH)f=new r.Mesh,d=o.DecodeBufferToMesh(c,f);else if(p===r.POINT_CLOUD)f=new r.PointCloud,d=o.DecodeBufferToPointCloud(c,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!d.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+d.error_msg());const m={index:null,attributes:[]};for(const g in u){const x=self[h[g]];let y,b;if(l.useUniqueIDs)b=u[g],y=o.GetAttributeByUniqueId(f,b);else{if(b=o.GetAttributeId(f,r[u[g]]),b===-1)continue;y=o.GetAttribute(f,b)}m.attributes.push(i(r,o,f,g,x,y))}return p===r.TRIANGULAR_MESH&&(m.index=n(r,o,f)),r.destroy(f),m}function n(r,o,c){const u=c.num_faces()*3,h=u*4,f=r._malloc(h);o.GetTrianglesUInt32Array(c,h,f);const d=new Uint32Array(r.HEAPF32.buffer,f,u).slice();return r._free(f),{array:d,itemSize:1}}function i(r,o,c,l,u,h){const f=h.num_components(),p=c.num_points()*f,m=p*u.BYTES_PER_ELEMENT,g=s(r,u),x=r._malloc(m);o.GetAttributeDataArrayForAllPoints(c,h,g,m,x);const y=new u(r.HEAPF32.buffer,x,p).slice();return r._free(x),{name:l,array:y,itemSize:f}}function s(r,o){switch(o){case Float32Array:return r.DT_FLOAT32;case Int8Array:return r.DT_INT8;case Int16Array:return r.DT_INT16;case Int32Array:return r.DT_INT32;case Uint8Array:return r.DT_UINT8;case Uint16Array:return r.DT_UINT16;case Uint32Array:return r.DT_UINT32}}}const fc=new Ei,Kn=new o1;Kn.addHandler(/\.dds$/i,new r1);Kn.addHandler(/\.tga$/i,new yu);function d1(a){return fc.setFromObject(a),fc.getSize(new P)}function p1(a){return fc.setFromObject(a),fc.getCenter(new P)}function m1(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function g1(a,e,t,n){let i;e?i=e:i=m1(a),i==="glb"&&(i="gltf");let s={loader:null,getObject:null};switch(i){case"dae":s={loader:new wM(Kn),getObject:r=>r.scene};break;case"fbx":s={loader:new uM(Kn)};break;case"gltf":s={loader:new MM(Kn),getObject:r=>{const o=r.scene;return r.animations&&(o.animations=r.animations),o}},x1(t,s,n);break;case"obj":s={loader:new s1(Kn)};break;case"ply":s={loader:new a1(Kn),getObject:r=>(r.computeVertexNormals(),new Tt(r,new Us))};break;case"stl":s={loader:new c1(Kn),getObject:r=>new Tt(r,new Qn)};break;case"json":s={loader:new tm(Kn)};break}return s}function y1(){return new l1(Kn)}function x1(a,e,t){if(a){const n=new h1;n.setDecoderPath(t||"assets/draco/gltf/"),n.setDecoderConfig({type:"js"}),e.loader.setDRACOLoader(n)}}var v1=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const _1=kt.defineComponent({name:"vue3dLoader"}),b1=kt.defineComponent({..._1,props:{filePath:null,fileType: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:()=>[]},autoPlay:{type:Boolean,default:!0},enableDraco:{type:Boolean,default:!1},dracoDir:null,intersectRecursive:{type:Boolean,default:!1},enableDamping:{type:Boolean},dampingFactor:null},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new rm,s=new de,r=new Dt(45,1,1,1e5),o=new Ac,c=new $u;let l=new ut,u=null,h={},f=[],d=null,p=0,m=null,g=null,x=null;const y=kt.ref({width:t.width||0,height:t.height||0}),b=kt.ref(0),v=kt.ref(!1),M=kt.ref(!1),T=kt.ref(null),C=kt.ref(null);kt.watch([()=>t.filePath,()=>t.fileType,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],k=>{(k[0]||k[1])&&ie(),k[2]&&ve(),(k[3]||k[4])&&W()}),kt.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],k=>{const z=["rotation","position","scale"];k.forEach((K,Q)=>{Q<3&&K?Fe(z[Q],K):ne()})},{deep:!0}),kt.watch([()=>y],()=>{j(!0),W()},{deep:!0}),kt.watch([()=>t.controlsOptions],()=>{$()},{deep:!0}),kt.watch([()=>t.cameraRotation,()=>t.cameraPosition],()=>{j()},{deep:!0}),kt.watch([()=>t.autoPlay],()=>{at()}),kt.onMounted(()=>{const{filePath:k,outputEncoding:z,webGLRendererOptions:K,showFps:Q,enableDamping:me,dampingFactor:R}=t;k&&typeof k=="object"&&(M.value=!0);const ae=T.value;_(ae),F();const Se=Object.assign({},{antialias:!0,alpha:!0},K,{canvas:C.value});u=new Fu(Se),u.shadowMap.enabled=!0;const Te=z==="linear"?bi:nt;u.outputEncoding=Te,h=new kw(r,ae),me&&(h.enableDamping=!0,R!=null&&(h.dampingFactor=R)),o.add(l),ie(),Z(),E(!0),ae.addEventListener("mousedown",U,!1),ae.addEventListener("mouseup",J,!1),ae.addEventListener("click",G,!1),ae.addEventListener("dblclick",X,!1),window.addEventListener("resize",F,!1),Q&&(m=xo(),ae.appendChild(m.dom)),Pe()}),kt.onBeforeUnmount(()=>{cancelAnimationFrame(p),u.dispose(),h&&h.dispose();const k=T.value;k.removeEventListener("mousedown",U,!1),k.removeEventListener("mousemove",q,!1),k.removeEventListener("mouseup",J,!1),k.removeEventListener("click",G,!1),k.removeEventListener("dblclick",X,!1),window.removeEventListener("resize",F,!1),n=null,l=null});function _(k){const{width:z,height:K}=t;z&&(k.style.width=`${z}px`),K&&(k.style.height=`${K}px`)}function E(k){const z=T.value;k?z.addEventListener("mousemove",q,!1):z.removeEventListener("mousemove",q,!1)}function F(){const{width:k,height:z}=t;(!k||!z)&&kt.nextTick(()=>{const K=T.value;y.value={width:k||K.offsetWidth,height:z||K.offsetHeight}})}function U(k){E(!1);const z=B(k.clientX,k.clientY);e("mousedown",k,z)}function q(k){const z=B(k.clientX,k.clientY);e("mousemove",k,z)}function J(k){const z=B(k.clientX,k.clientY);e("mouseup",k,z),E(!0)}function G(k){const z=B(k.clientX,k.clientY);e("click",k,z)}function X(k){const z=B(k.clientX,k.clientY);e("dblclick",k,z)}function B(k,z){const K=Ee();if(!K||!T.value)return null;const Q=T.value.getBoundingClientRect();k-=Q.left,z-=Q.top,s.x=k/y.value.width*2-1,s.y=-(z/y.value.height)*2+1,i.setFromCamera(s,r);const me=i.intersectObject(K,t.intersectRecursive);return(me&&me.length)>0?me[0]:null}function Z(){W(),j(),ne(),$()}function Y(){if(!n)return;const k=M.value?ht(n):null,{position:z,rotation:K,scale:Q}=t;z&&(z instanceof Array?k!=null?n.position.set(z[k].x,z[k].y,z[k].z):n.position.set(0,0,0):n.position.set(z.x,z.y,z.z)),K&&(K instanceof Array?k!=null?n.rotation.set(K[k].x,K[k].y,K[k].z):n.rotation.set(0,0,0):n.rotation.set(K.x,K.y,K.z)),Q&&(Q instanceof Array?k!=null?n.scale.set(Q[k].x,Q[k].y,Q[k].z):n.scale.set(0,0,0):n.scale.set(Q.x,Q.y,Q.z))}function W(){const{backgroundColor:k,backgroundAlpha:z}=t;u.setSize(y.value.width,y.value.height),u.setPixelRatio(window.devicePixelRatio||1),u.setClearColor(new be(k).getHex()),u.setClearAlpha(z)}function j(k){const{cameraPosition:z,cameraRotation:K,cameraUp:Q,cameraLookAt:me}=t;if(r.aspect=y.value.width/y.value.height,r.updateProjectionMatrix(),!k)if(!me||!Q){if(!n)return;const R=d1(n).length();r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),z.x===0&&z.y===0&&z.z===0&&(r.position.z=R),r.lookAt(new P)}else r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),r.up.set(Q.x,Q.y,Q.z),r.lookAt(new P(me.x,me.y,me.z))}function ne(){const{lights:k}=t;o.remove(...f),f=[],k.forEach(z=>{if(!z.type)return;const K=z.type.toLowerCase();let Q=null;if(K==="ambient"||K==="ambientlight"){const me=z.color===0?z.color:z.color||4210752,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Wo(me,R)}if(K==="point"||K==="pointlight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1,ae=z.distance||0,pe=z.decay===0?z.decay:z.decay||1;Q=new Os(me,R,ae,pe),z.position&&Q.position.copy(z.position)}if(K==="directional"||K==="directionallight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Vr(me,R),z.position&&Q.position.copy(z.position),z.target&&Q.target.copy(z.target)}if(K==="hemisphere"||K==="hemispherelight"){const me=z.skyColor===0?z.skyColor:z.skyColor||16777215,R=z.groundColor===0?z.groundColor:z.groundColor||16777215,ae=z.intensity===0?z.intensity:z.intensity||1;Q=new Zu(me,R,ae),z.position&&Q.position.copy(z.position)}Q&&(f.push(Q),o.add(Q))})}function $(){const{controlsOptions:k}=t;k&&Object.assign(h,k)}function ie(){const{filePath:k,parallelLoad:z}=t;z&&M?k.forEach((K,Q)=>{ce(Q)}):ce()}function ce(k){const{filePath:z,fileType:K,crossOrigin:Q,requestHeader:me,mtlPath:R,enableDraco:ae,dracoDir:pe}=t;if(!z)return;const Se=k||b.value,Te=M.value?z[Se]:z,He=typeof K=="string"?K:K?K[Se]:"",Ze=g1(Te,He,ae,pe);d=Ze.loader;const Qe=Ze.getObject?Ze.getObject:ye;if(n&&Se===0&&l.remove(n),me&&d.setRequestHeader(me),Q&&d.setCrossOrigin(Q),R)if(!(typeof R=="object"))H(Te,Qe,Se);else{if(!R[Se]){oe(Te,Qe,Se);return}H(Te,Qe,Se)}else oe(Te,Qe,Se)}function oe(k,z,K){const{textureImage:Q,parallelLoad:me}=t;d.load(k,(...R)=>{if(n=z(...R),we(n,k),Q){const pe=typeof Q=="string"?Q:Q[K];pe&&ue(n,pe)}je(),e("load",l)},R=>{me||he(R);const ae=b.value+1;e("process",R,ae)},R=>{e("error",R)})}function H(k,z,K){const{crossOrigin:Q,requestHeader:me,mtlPath:R}=t,ae=y1();Q&&ae.setCrossOrigin(Q),me&&ae.setRequestHeader(me);const pe=typeof R=="string"?R:R[K],Se=/^(.*\/)([^/]*)$/.exec(pe),Te=Se[1],He=Se[2];ae.setPath(Te).load(He,Ze=>{Ze.preload(),d.setMaterials(Ze),oe(k,z,K)})}function ye(k){return k}function we(k,z){const K=p1(n);v.value||(l.position.copy(K.negate()),v.value=!0),n=k;let Q=z.split("/");Q=Q[Q.length-1],n.fileName=Q,l.add(n),j(),Y(),at()}function Pe(){p=requestAnimationFrame(Pe),Ve();const k=c.getDelta();g&&g instanceof $a&&g.update(k),g&&g instanceof Array&&g.forEach(z=>{z.update(k)}),xe()}function xe(){u.render(o,r)}function Ve(){const{showFps:k}=t;k&&m.update()}function he(k){const{filePath:z}=t;Math.floor(k.loaded/k.total*100)===100&&(M.value&&z.length>b.value?kt.nextTick(()=>{if(b.value++,b.value===z.length){b.value=0;return}ce()}):b.value=0)}function ue(k,z){x||(x=new ks),k.traverse(K=>{K.isMesh&&x.load(z,Q=>{K.material.map=Q,K.material.needsUpdate=!0},()=>{},Q=>{e("error",Q)})})}function ve(){l.clear()}function Fe(k,z){const K=Ee();if(!!K){if(M.value){K.children.forEach(Q=>{const me=ht(Q),R=k==="scale"?1:0;z[me]?Q[k].set(z[me].x,z[me].y,z[me].z):Q[k].set(R,R,R)});return}K[k].set(z.x,z.y,z.z)}}function Ee(){return M.value?l:n}function je(){const{filePath:k}=t;M.value?b.value===k.length&&ze():ze()}function ze(){const{labels:k}=t;if(!k)return;const z=M.value?l:n,K=me=>(x||(x=new ks),x.load(me)),Q=(me,R)=>{const ae=Be(me,R),pe=new At(ae);return pe.needsUpdate=!0,pe};k.forEach(me=>{const R=me.image?K(me.image):Q(me.text,me.textStyle||{}),ae=new Ec({map:R,color:me.spriteMaterialColor||16777215}),pe=new Nu(ae);me.scale?pe.scale.set(me.scale.x||1,me.scale.y||1,me.scale.z||0):pe.scale.set(1,1,0),me.position&&pe.position.set(me.position.x,me.position.y,me.position.z),me.sid&&(pe.sid=me.sid),z.add(pe)})}function Be(k,z){const K=(V,_e,re,Re,Ce,Je)=>{V.beginPath(),V.moveTo(_e+Je,re),V.lineTo(_e+Re-Je,re),V.quadraticCurveTo(_e+Re,re,_e+Re,re+Je),V.lineTo(_e+Re,re+Ce-Je),V.quadraticCurveTo(_e+Re,re+Ce,_e+Re-Je,re+Ce),V.lineTo(_e+Je,re+Ce),V.quadraticCurveTo(_e,re+Ce,_e,re+Ce-Je),V.lineTo(_e,re+Je),V.quadraticCurveTo(_e,re,_e+Je,re),V.closePath(),V.fill(),V.stroke()},Q=z.fontFamily||"Arial",me=z.fontSize===0||z.fontSize?z.fontSize:18,R=z.color||"#ffffff",ae=z.fontWeight||"normal",pe=z.borderWidth===0||z.borderWidth?z.borderWidth:4,Se=z.borderColor||"rgba(0,0,0,1)",Te=z.borderRadius===0||z.borderRadius?z.borderRadius:4,He=z.backgroundColor||"rgba(255, 255, 255, 1)",Ze=document.createElement("canvas"),Qe=Ze.getContext("2d");if(Qe){Qe.font=`${ae} ${me}px ${Q}`;const _e=Qe.measureText(k).width;Qe.fillStyle=He,Qe.strokeStyle=Se,Qe.lineWidth=pe,K(Qe,pe/2,pe/2,_e+pe,me*1.4+pe,Te),Qe.fillStyle=R,Qe.fillText(k,pe,me+pe)}return Ze}function ht(k){const{filePath:z}=t;let K;return z instanceof Array&&(K=z.map((Q,me)=>{if(Q.indexOf(k.fileName)>-1)return me}).filter(Q=>Q!=null)[0]),K}function at(){const k=Ee();if(!!k){if(M.value){D(k);return}O(k)}}function O(k){const{autoPlay:z}=t;g=new $a(k),k.animations&&k.animations.length>0&&k.animations.forEach(K=>{if(K){const Q=g.clipAction(K);z?Q.play():Q.stop()}})}function D(k){const{autoPlay:z}=t;g=[],k.children.forEach((K,Q)=>{g.push(new $a(K)),K.animations&&K.animations.length>0&&K.animations.forEach(me=>{if(me){const R=g[Q].clipAction(me);z?R.play():R.stop()}})})}return(k,z)=>(kt.openBlock(),kt.createElementBlock("div",{ref_key:"containerElement",ref:T,class:"viewer-container"},[kt.createElementVNode("canvas",{ref_key:"canvasElement",ref:C,class:"viewer-canvas"},null,512)],512))}});var dc=v1(b1,[["__scopeId","data-v-04ca652e"]]);const w1=a=>{a.component(dc.name,dc)};var M1={install:w1,vue3dLoader:dc};exports.Three=Nw;exports.default=M1;exports.vue3dLoader=dc; diff --git a/dist/vue-3d-loader.esm.js b/dist/vue-3d-loader.esm.js index 9f12fd1..427bc69 100644 --- a/dist/vue-3d-loader.esm.js +++ b/dist/vue-3d-loader.esm.js @@ -40688,6 +40688,9 @@ function getLoader(filePath, fileType, isDraco, dracoDir) { loader: new GLTFLoader(manager), getObject: (gltf) => { const object = gltf.scene; + if (gltf.animations) { + object.animations = gltf.animations; + } return object; } }; diff --git a/dist/vue-3d-loader.global.js b/dist/vue-3d-loader.global.js index 5ba8c77..8386c2b 100644 --- a/dist/vue-3d-loader.global.js +++ b/dist/vue-3d-loader.global.js @@ -3156,4 +3156,4 @@ version 0.6.9 `)!==-1&&(e=e.replace(/\\\n/g,""));const n=e.split(` `);let i=[];for(let o=0,c=n.length;o=7?(Sc.setRGB(parseFloat(h[4]),parseFloat(h[5]),parseFloat(h[6])).convertSRGBToLinear(),t.colors.push(Sc.r,Sc.g,Sc.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(Um),d=[];for(let m=0,g=f.length;m0){const y=x.split("/");d.push(y)}}const p=d[0];for(let m=1,g=d.length-1;m1){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&&m.setAttribute("normal",new Ae(u.normals,3)),u.colors.length>0&&(p=!0,m.setAttribute("color",new Ae(u.colors,3))),u.hasUVIndices===!0&&m.setAttribute("uv",new Ae(u.uvs,2));const g=[];for(let y=0,b=h.length;y1){for(let y=0,b=h.length;y0){const o=new Xi({size:1,sizeAttenuation:!1}),c=new qe;c.setAttribute("position",new Ae(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(c.setAttribute("color",new Ae(t.colors,3)),o.vertexColors=!0);const l=new _r(c,o);s.add(l)}return s}}class MM extends ip{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(oe){return oe.charCodeAt(0)+(oe.charCodeAt(1)<<8)+(oe.charCodeAt(2)<<16)+(oe.charCodeAt(3)<<24)}function p(oe){return String.fromCharCode(oe&255,oe>>8&255,oe>>16&255,oe>>24&255)}function m(oe,H,ye,we){const De=ye*we*4,xe=new Uint8Array(oe,H,De),Ve=new Uint8Array(De);let he=0,ue=0;for(let ve=0;ve>1,1),ye=Math.max(ye>>1,1)}}return n}}class SM{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=p.elements[v].count&&(v++,M=0);const _=i(p.elements[v].properties,C);o(m,p.elements[v].name,_),M++}return r(m)}function r(d){let p=new qe;return d.indices.length>0&&p.setIndex(d.indices),p.setAttribute("position",new Ae(d.vertices,3)),d.normals.length>0&&p.setAttribute("normal",new Ae(d.normals,3)),d.uvs.length>0&&p.setAttribute("uv",new Ae(d.uvs,2)),d.colors.length>0&&p.setAttribute("color",new Ae(d.colors,3)),d.faceVertexUvs.length>0&&(p=p.toNonIndexed(),p.setAttribute("uv",new Ae(d.faceVertexUvs,2))),p.computeBoundingSphere(),p}function o(d,p,m){function g(q){for(let J=0,G=q.length;J>5&31)/31,p=(X>>10&31)/31):(f=x,d=y,p=b)}for(let X=1;X<=3;X++){const B=U+X*12,Z=F*3*3+(X-1)*3;_[Z]=u.getFloat32(B,!0),_[Z+1]=u.getFloat32(B+4,!0),_[Z+2]=u.getFloat32(B+8,!0),E[Z]=q,E[Z+1]=J,E[Z+2]=G,m&&(g[Z]=f,g[Z+1]=d,g[Z+2]=p)}}return C.setAttribute("position",new ft(_,3)),C.setAttribute("normal",new ft(E,3)),m&&(C.setAttribute("color",new ft(g,3)),C.hasColors=!0,C.alpha=v),C}function s(l){const u=new qe,h=/solid([\s\S]*?)endsolid/g,f=/facet([\s\S]*?)endfacet/g;let d=0;const p=/[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source,m=new RegExp("vertex"+p+p+p,"g"),g=new RegExp("normal"+p+p+p,"g"),x=[],y=[],b=new P;let v,M=0,T=0,C=0;for(;(v=h.exec(l))!==null;){T=C;const _=v[0];for(;(v=f.exec(_))!==null;){let U=0,q=0;const J=v[0];for(;(v=g.exec(J))!==null;)b.x=parseFloat(v[1]),b.y=parseFloat(v[2]),b.z=parseFloat(v[3]),q++;for(;(v=m.exec(J))!==null;)x.push(parseFloat(v[1]),parseFloat(v[2]),parseFloat(v[3])),y.push(b.x,b.y,b.z),U++,C++;q!==1&&console.error("THREE.STLLoader: Something isn't right with the normal of face number "+d),U!==3&&console.error("THREE.STLLoader: Something isn't right with the vertices of face number "+d),d++}const E=T,F=C-T;u.addGroup(E,F,M),M++}return u.setAttribute("position",new Ae(x,3)),u.setAttribute("normal",new Ae(y,3)),u}function r(l){return typeof l!="string"?tn.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 CM(this.resourcePath||t,this.materialOptions);return o.setCrossOrigin(this.crossOrigin),o.setManager(this.manager),o.setMaterials(r),o}}class CM{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:oi,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=nt),i[o]=u}for(const o in n){const c=n[o];let l;if(c!=="")switch(o.toLowerCase()){case"kd":i.color=new be().fromArray(c).convertSRGBToLinear();break;case"ks":i.specular=new be().fromArray(c).convertSRGBToLinear();break;case"ke":i.emissive=new be().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 Qn(i),this.materials[e]}getTextureParams(e,t){const n={scale:new fe(1,1),offset:new fe(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:bu;let o=r.getHandler(e);o===null&&(o=new Fs(r)),o.setCrossOrigin&&o.setCrossOrigin(this.crossOrigin);const c=o.load(e,n,i,s);return t!==void 0&&(c.mapping=t),c}}const uh=new WeakMap;class LM extends Ut{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,i){const s=new Zt(this.manager);s.setPath(this.path),s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,r=>{const o={attributeIDs:this.defaultAttributeIDs,attributeTypes:this.defaultAttributeTypes,useUniqueIDs:!1};this.decodeGeometry(r,o).then(t).catch(i)},n,i)}decodeDracoFile(e,t,n,i){const s={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:i||this.defaultAttributeTypes,useUniqueIDs:!!n};this.decodeGeometry(e,s).then(t)}decodeGeometry(e,t){for(const c in t.attributeTypes){const l=t.attributeTypes[c];l.BYTES_PER_ELEMENT!==void 0&&(t.attributeTypes[c]=l.name)}const n=JSON.stringify(t);if(uh.has(e)){const c=uh.get(e);if(c.key===n)return c.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let i;const s=this.workerNextTaskID++,r=e.byteLength,o=this._getWorker(s,r).then(c=>(i=c,new Promise((l,u)=>{i._callbacks[s]={resolve:l,reject:u},i.postMessage({type:"decode",id:s,taskConfig:t,buffer:e},[e])}))).then(c=>this._createGeometry(c.geometry));return o.catch(()=>!0).then(()=>{i&&s&&this._releaseTask(i,s)}),uh.set(e,{key:n,promise:o}),o}_createGeometry(e){const t=new qe;e.index&&t.setIndex(new ft(e.index.array,1));for(let n=0;n{n.load(e,i,void 0,s)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(n=>{const i=n[0];e||(this.decoderConfig.wasmBinary=n[1]);const s=RM.toString(),r=["/* draco decoder */",i,"","/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join(` -`);this.workerSourceURL=URL.createObjectURL(new Blob([r]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.lengths._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e{const h=u.draco,f=new h.Decoder,d=new h.DecoderBuffer;d.Init(new Int8Array(c),c.byteLength);try{const p=t(h,f,d,l),m=p.attributes.map(g=>g.array.buffer);p.index&&m.push(p.index.array.buffer),self.postMessage({type:"decode",id:o.id,geometry:p},m)}catch(p){console.error(p),self.postMessage({type:"error",id:o.id,error:p.message})}finally{h.destroy(d),h.destroy(f)}});break}};function t(r,o,c,l){const u=l.attributeIDs,h=l.attributeTypes;let f,d;const p=o.GetEncodedGeometryType(c);if(p===r.TRIANGULAR_MESH)f=new r.Mesh,d=o.DecodeBufferToMesh(c,f);else if(p===r.POINT_CLOUD)f=new r.PointCloud,d=o.DecodeBufferToPointCloud(c,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!d.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+d.error_msg());const m={index:null,attributes:[]};for(const g in u){const x=self[h[g]];let y,b;if(l.useUniqueIDs)b=u[g],y=o.GetAttributeByUniqueId(f,b);else{if(b=o.GetAttributeId(f,r[u[g]]),b===-1)continue;y=o.GetAttribute(f,b)}m.attributes.push(i(r,o,f,g,x,y))}return p===r.TRIANGULAR_MESH&&(m.index=n(r,o,f)),r.destroy(f),m}function n(r,o,c){const u=c.num_faces()*3,h=u*4,f=r._malloc(h);o.GetTrianglesUInt32Array(c,h,f);const d=new Uint32Array(r.HEAPF32.buffer,f,u).slice();return r._free(f),{array:d,itemSize:1}}function i(r,o,c,l,u,h){const f=h.num_components(),p=c.num_points()*f,m=p*u.BYTES_PER_ELEMENT,g=s(r,u),x=r._malloc(m);o.GetAttributeDataArrayForAllPoints(c,h,g,m,x);const y=new u(r.HEAPF32.buffer,x,p).slice();return r._free(x),{name:l,array:y,itemSize:f}}function s(r,o){switch(o){case Float32Array:return r.DT_FLOAT32;case Int8Array:return r.DT_INT8;case Int16Array:return r.DT_INT16;case Int32Array:return r.DT_INT32;case Uint8Array:return r.DT_UINT8;case Uint16Array:return r.DT_UINT16;case Uint32Array:return r.DT_UINT32}}}const Ac=new hi,ii=new SM;ii.addHandler(/\.dds$/i,new MM),ii.addHandler(/\.tga$/i,new sh);function IM(a){return Ac.setFromObject(a),Ac.getSize(new P)}function PM(a){return Ac.setFromObject(a),Ac.getCenter(new P)}function DM(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function FM(a,e,t,n){let i;e?i=e:i=DM(a),i==="glb"&&(i="gltf");let s={loader:null,getObject:null};switch(i){case"dae":s={loader:new Uw(ii),getObject:r=>r.scene};break;case"fbx":s={loader:new Cw(ii)};break;case"gltf":s={loader:new Gw(ii),getObject:r=>r.scene},kM(t,s,n);break;case"obj":s={loader:new wM(ii)};break;case"ply":s={loader:new TM(ii),getObject:r=>(r.computeVertexNormals(),new St(r,new Cs))};break;case"stl":s={loader:new AM(ii),getObject:r=>new St(r,new Qn)};break;case"json":s={loader:new dp(ii)};break}return s}function NM(){return new EM(ii)}function kM(a,e,t){if(a){const n=new LM;n.setDecoderPath(t||"assets/draco/gltf/"),n.setDecoderConfig({type:"js"}),e.loader.setDRACOLoader(n)}}var S1="",OM=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const BM=Nt.defineComponent({name:"vue3dLoader"}),zM=Nt.defineComponent({...BM,props:{filePath:null,fileType: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:()=>[]},autoPlay:{type:Boolean,default:!0},enableDraco:{type:Boolean,default:!1},dracoDir:null,intersectRecursive:{type:Boolean,default:!1},enableDamping:{type:Boolean},dampingFactor:null},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new Sp,s=new fe,r=new Dt(45,1,1,1e5),o=new ka,c=new Au;let l=new lt,u=null,h={},f=[],d=null,p=0,m=null,g=null,x=null;const y=Nt.ref({width:t.width||0,height:t.height||0}),b=Nt.ref(0),v=Nt.ref(!1),M=Nt.ref(!1),T=Nt.ref(null),C=Nt.ref(null);Nt.watch([()=>t.filePath,()=>t.fileType,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],k=>{(k[0]||k[1])&&ie(),k[2]&&ve(),(k[3]||k[4])&&W()}),Nt.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],k=>{const z=["rotation","position","scale"];k.forEach((K,Q)=>{Q<3&&K?Fe(z[Q],K):ne()})},{deep:!0}),Nt.watch([()=>y],()=>{j(!0),W()},{deep:!0}),Nt.watch([()=>t.controlsOptions],()=>{$()},{deep:!0}),Nt.watch([()=>t.cameraRotation,()=>t.cameraPosition],()=>{j()},{deep:!0}),Nt.watch([()=>t.autoPlay],()=>{ct()}),Nt.onMounted(()=>{const{filePath:k,outputEncoding:z,webGLRendererOptions:K,showFps:Q,enableDamping:me,dampingFactor:R}=t;k&&typeof k=="object"&&(M.value=!0);const ae=T.value;_(ae),F();const Se=Object.assign({},{antialias:!0,alpha:!0},K,{canvas:C.value});u=new Jl(Se),u.shadowMap.enabled=!0;const Te=z==="linear"?ui:nt;u.outputEncoding=Te,h=new ew(r,ae),me&&(h.enableDamping=!0,R!=null&&(h.dampingFactor=R)),o.add(l),ie(),Z(),E(!0),ae.addEventListener("mousedown",U,!1),ae.addEventListener("mouseup",J,!1),ae.addEventListener("click",G,!1),ae.addEventListener("dblclick",X,!1),window.addEventListener("resize",F,!1),Q&&(m=Fo(),ae.appendChild(m.dom)),De()}),Nt.onBeforeUnmount(()=>{cancelAnimationFrame(p),u.dispose(),h&&h.dispose();const k=T.value;k.removeEventListener("mousedown",U,!1),k.removeEventListener("mousemove",q,!1),k.removeEventListener("mouseup",J,!1),k.removeEventListener("click",G,!1),k.removeEventListener("dblclick",X,!1),window.removeEventListener("resize",F,!1),n=null,l=null});function _(k){const{width:z,height:K}=t;z&&(k.style.width=`${z}px`),K&&(k.style.height=`${K}px`)}function E(k){const z=T.value;k?z.addEventListener("mousemove",q,!1):z.removeEventListener("mousemove",q,!1)}function F(){const{width:k,height:z}=t;(!k||!z)&&Nt.nextTick(()=>{const K=T.value;y.value={width:k||K.offsetWidth,height:z||K.offsetHeight}})}function U(k){E(!1);const z=B(k.clientX,k.clientY);e("mousedown",k,z)}function q(k){const z=B(k.clientX,k.clientY);e("mousemove",k,z)}function J(k){const z=B(k.clientX,k.clientY);e("mouseup",k,z),E(!0)}function G(k){const z=B(k.clientX,k.clientY);e("click",k,z)}function X(k){const z=B(k.clientX,k.clientY);e("dblclick",k,z)}function B(k,z){const K=Ee();if(!K||!T.value)return null;const Q=T.value.getBoundingClientRect();k-=Q.left,z-=Q.top,s.x=k/y.value.width*2-1,s.y=-(z/y.value.height)*2+1,i.setFromCamera(s,r);const me=i.intersectObject(K,t.intersectRecursive);return(me&&me.length)>0?me[0]:null}function Z(){W(),j(),ne(),$()}function Y(){if(!n)return;const k=M.value?dt(n):null,{position:z,rotation:K,scale:Q}=t;z&&(z instanceof Array?k!=null?n.position.set(z[k].x,z[k].y,z[k].z):n.position.set(0,0,0):n.position.set(z.x,z.y,z.z)),K&&(K instanceof Array?k!=null?n.rotation.set(K[k].x,K[k].y,K[k].z):n.rotation.set(0,0,0):n.rotation.set(K.x,K.y,K.z)),Q&&(Q instanceof Array?k!=null?n.scale.set(Q[k].x,Q[k].y,Q[k].z):n.scale.set(0,0,0):n.scale.set(Q.x,Q.y,Q.z))}function W(){const{backgroundColor:k,backgroundAlpha:z}=t;u.setSize(y.value.width,y.value.height),u.setPixelRatio(window.devicePixelRatio||1),u.setClearColor(new be(k).getHex()),u.setClearAlpha(z)}function j(k){const{cameraPosition:z,cameraRotation:K,cameraUp:Q,cameraLookAt:me}=t;if(r.aspect=y.value.width/y.value.height,r.updateProjectionMatrix(),!k)if(!me||!Q){if(!n)return;const R=IM(n).length();r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),z.x===0&&z.y===0&&z.z===0&&(r.position.z=R),r.lookAt(new P)}else r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),r.up.set(Q.x,Q.y,Q.z),r.lookAt(new P(me.x,me.y,me.z))}function ne(){const{lights:k}=t;o.remove(...f),f=[],k.forEach(z=>{if(!z.type)return;const K=z.type.toLowerCase();let Q=null;if(K==="ambient"||K==="ambientlight"){const me=z.color===0?z.color:z.color||4210752,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Do(me,R)}if(K==="point"||K==="pointlight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1,ae=z.distance||0,pe=z.decay===0?z.decay:z.decay||1;Q=new Ns(me,R,ae,pe),z.position&&Q.position.copy(z.position)}if(K==="directional"||K==="directionallight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Nr(me,R),z.position&&Q.position.copy(z.position),z.target&&Q.target.copy(z.target)}if(K==="hemisphere"||K==="hemispherelight"){const me=z.skyColor===0?z.skyColor:z.skyColor||16777215,R=z.groundColor===0?z.groundColor:z.groundColor||16777215,ae=z.intensity===0?z.intensity:z.intensity||1;Q=new wu(me,R,ae),z.position&&Q.position.copy(z.position)}Q&&(f.push(Q),o.add(Q))})}function $(){const{controlsOptions:k}=t;k&&Object.assign(h,k)}function ie(){const{filePath:k,parallelLoad:z}=t;z&&M?k.forEach((K,Q)=>{ce(Q)}):ce()}function ce(k){const{filePath:z,fileType:K,crossOrigin:Q,requestHeader:me,mtlPath:R,enableDraco:ae,dracoDir:pe}=t;if(!z)return;const Se=k||b.value,Te=M.value?z[Se]:z,He=typeof K=="string"?K:K?K[Se]:"",Ze=FM(Te,He,ae,pe);d=Ze.loader;const Qe=Ze.getObject?Ze.getObject:ye;if(n&&Se===0&&l.remove(n),me&&d.setRequestHeader(me),Q&&d.setCrossOrigin(Q),R)if(!(typeof R=="object"))H(Te,Qe,Se);else{if(!R[Se]){oe(Te,Qe,Se);return}H(Te,Qe,Se)}else oe(Te,Qe,Se)}function oe(k,z,K){const{textureImage:Q,parallelLoad:me}=t;d.load(k,(...R)=>{if(n=z(...R),we(n,k),Q){const pe=typeof Q=="string"?Q:Q[K];pe&&ue(n,pe)}je(),e("load",l)},R=>{me||he(R);const ae=b.value+1;e("process",R,ae)},R=>{e("error",R)})}function H(k,z,K){const{crossOrigin:Q,requestHeader:me,mtlPath:R}=t,ae=NM();Q&&ae.setCrossOrigin(Q),me&&ae.setRequestHeader(me);const pe=typeof R=="string"?R:R[K],Se=/^(.*\/)([^/]*)$/.exec(pe),Te=Se[1],He=Se[2];ae.setPath(Te).load(He,Ze=>{Ze.preload(),d.setMaterials(Ze),oe(k,z,K)})}function ye(k){return k}function we(k,z){const K=PM(n);v.value||(l.position.copy(K.negate()),v.value=!0),n=k;let Q=z.split("/");Q=Q[Q.length-1],n.fileName=Q,l.add(n),j(),Y(),ct()}function De(){p=requestAnimationFrame(De),Ve();const k=c.getDelta();g&&g instanceof rc&&g.update(k),g&&g instanceof Array&&g.forEach(z=>{z.update(k)}),xe()}function xe(){u.render(o,r)}function Ve(){const{showFps:k}=t;k&&m.update()}function he(k){const{filePath:z}=t;Math.floor(k.loaded/k.total*100)===100&&(M.value&&z.length>b.value?Nt.nextTick(()=>{if(b.value++,b.value===z.length){b.value=0;return}ce()}):b.value=0)}function ue(k,z){x||(x=new Fs),k.traverse(K=>{K.isMesh&&x.load(z,Q=>{K.material.map=Q,K.material.needsUpdate=!0},()=>{},Q=>{e("error",Q)})})}function ve(){l.clear()}function Fe(k,z){const K=Ee();if(!!K){if(M.value){K.children.forEach(Q=>{const me=dt(Q),R=k==="scale"?1:0;z[me]?Q[k].set(z[me].x,z[me].y,z[me].z):Q[k].set(R,R,R)});return}K[k].set(z.x,z.y,z.z)}}function Ee(){return M.value?l:n}function je(){const{filePath:k}=t;M.value?b.value===k.length&&ze():ze()}function ze(){const{labels:k}=t;if(!k)return;const z=M.value?l:n,K=me=>(x||(x=new Fs),x.load(me)),Q=(me,R)=>{const ae=Be(me,R),pe=new Mt(ae);return pe.needsUpdate=!0,pe};k.forEach(me=>{const R=me.image?K(me.image):Q(me.text,me.textStyle||{}),ae=new Oa({map:R,color:me.spriteMaterialColor||16777215}),pe=new Ql(ae);me.scale?pe.scale.set(me.scale.x||1,me.scale.y||1,me.scale.z||0):pe.scale.set(1,1,0),me.position&&pe.position.set(me.position.x,me.position.y,me.position.z),me.sid&&(pe.sid=me.sid),z.add(pe)})}function Be(k,z){const K=(V,_e,re,Ie,Ce,Je)=>{V.beginPath(),V.moveTo(_e+Je,re),V.lineTo(_e+Ie-Je,re),V.quadraticCurveTo(_e+Ie,re,_e+Ie,re+Je),V.lineTo(_e+Ie,re+Ce-Je),V.quadraticCurveTo(_e+Ie,re+Ce,_e+Ie-Je,re+Ce),V.lineTo(_e+Je,re+Ce),V.quadraticCurveTo(_e,re+Ce,_e,re+Ce-Je),V.lineTo(_e,re+Je),V.quadraticCurveTo(_e,re,_e+Je,re),V.closePath(),V.fill(),V.stroke()},Q=z.fontFamily||"Arial",me=z.fontSize===0||z.fontSize?z.fontSize:18,R=z.color||"#ffffff",ae=z.fontWeight||"normal",pe=z.borderWidth===0||z.borderWidth?z.borderWidth:4,Se=z.borderColor||"rgba(0,0,0,1)",Te=z.borderRadius===0||z.borderRadius?z.borderRadius:4,He=z.backgroundColor||"rgba(255, 255, 255, 1)",Ze=document.createElement("canvas"),Qe=Ze.getContext("2d");if(Qe){Qe.font=`${ae} ${me}px ${Q}`;const _e=Qe.measureText(k).width;Qe.fillStyle=He,Qe.strokeStyle=Se,Qe.lineWidth=pe,K(Qe,pe/2,pe/2,_e+pe,me*1.4+pe,Te),Qe.fillStyle=R,Qe.fillText(k,pe,me+pe)}return Ze}function dt(k){const{filePath:z}=t;let K;return z instanceof Array&&(K=z.map((Q,me)=>{if(Q.indexOf(k.fileName)>-1)return me}).filter(Q=>Q!=null)[0]),K}function ct(){const k=Ee();if(!!k){if(M.value){D(k);return}O(k)}}function O(k){const{autoPlay:z}=t;g=new rc(k),k.animations&&k.animations.length>0&&k.animations.forEach(K=>{if(K){const Q=g.clipAction(K);z?Q.play():Q.stop()}})}function D(k){const{autoPlay:z}=t;g=[],k.children.forEach((K,Q)=>{g.push(new rc(K)),K.animations&&K.animations.length>0&&K.animations.forEach(me=>{if(me){const R=g[Q].clipAction(me);z?R.play():R.stop()}})})}return(k,z)=>(Nt.openBlock(),Nt.createElementBlock("div",{ref_key:"containerElement",ref:T,class:"viewer-container"},[Nt.createElementVNode("canvas",{ref_key:"canvasElement",ref:C,class:"viewer-canvas"},null,512)],512))}});var Ec=OM(zM,[["__scopeId","data-v-04ca652e"]]),UM={install:a=>{a.component(Ec.name,Ec)},vue3dLoader:Ec};return Jr.Three=Qb,Jr.default=UM,Jr.vue3dLoader=Ec,Object.defineProperties(Jr,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Jr}({},Vue); +`);this.workerSourceURL=URL.createObjectURL(new Blob([r]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.lengths._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e{const h=u.draco,f=new h.Decoder,d=new h.DecoderBuffer;d.Init(new Int8Array(c),c.byteLength);try{const p=t(h,f,d,l),m=p.attributes.map(g=>g.array.buffer);p.index&&m.push(p.index.array.buffer),self.postMessage({type:"decode",id:o.id,geometry:p},m)}catch(p){console.error(p),self.postMessage({type:"error",id:o.id,error:p.message})}finally{h.destroy(d),h.destroy(f)}});break}};function t(r,o,c,l){const u=l.attributeIDs,h=l.attributeTypes;let f,d;const p=o.GetEncodedGeometryType(c);if(p===r.TRIANGULAR_MESH)f=new r.Mesh,d=o.DecodeBufferToMesh(c,f);else if(p===r.POINT_CLOUD)f=new r.PointCloud,d=o.DecodeBufferToPointCloud(c,f);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!d.ok()||f.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+d.error_msg());const m={index:null,attributes:[]};for(const g in u){const x=self[h[g]];let y,b;if(l.useUniqueIDs)b=u[g],y=o.GetAttributeByUniqueId(f,b);else{if(b=o.GetAttributeId(f,r[u[g]]),b===-1)continue;y=o.GetAttribute(f,b)}m.attributes.push(i(r,o,f,g,x,y))}return p===r.TRIANGULAR_MESH&&(m.index=n(r,o,f)),r.destroy(f),m}function n(r,o,c){const u=c.num_faces()*3,h=u*4,f=r._malloc(h);o.GetTrianglesUInt32Array(c,h,f);const d=new Uint32Array(r.HEAPF32.buffer,f,u).slice();return r._free(f),{array:d,itemSize:1}}function i(r,o,c,l,u,h){const f=h.num_components(),p=c.num_points()*f,m=p*u.BYTES_PER_ELEMENT,g=s(r,u),x=r._malloc(m);o.GetAttributeDataArrayForAllPoints(c,h,g,m,x);const y=new u(r.HEAPF32.buffer,x,p).slice();return r._free(x),{name:l,array:y,itemSize:f}}function s(r,o){switch(o){case Float32Array:return r.DT_FLOAT32;case Int8Array:return r.DT_INT8;case Int16Array:return r.DT_INT16;case Int32Array:return r.DT_INT32;case Uint8Array:return r.DT_UINT8;case Uint16Array:return r.DT_UINT16;case Uint32Array:return r.DT_UINT32}}}const Ac=new hi,ii=new SM;ii.addHandler(/\.dds$/i,new MM),ii.addHandler(/\.tga$/i,new sh);function IM(a){return Ac.setFromObject(a),Ac.getSize(new P)}function PM(a){return Ac.setFromObject(a),Ac.getCenter(new P)}function DM(a){const e=a.split(".");if(e.length<=1)return"";{let t=e.pop();return t=t.toLowerCase(),t}}function FM(a,e,t,n){let i;e?i=e:i=DM(a),i==="glb"&&(i="gltf");let s={loader:null,getObject:null};switch(i){case"dae":s={loader:new Uw(ii),getObject:r=>r.scene};break;case"fbx":s={loader:new Cw(ii)};break;case"gltf":s={loader:new Gw(ii),getObject:r=>{const o=r.scene;return r.animations&&(o.animations=r.animations),o}},kM(t,s,n);break;case"obj":s={loader:new wM(ii)};break;case"ply":s={loader:new TM(ii),getObject:r=>(r.computeVertexNormals(),new St(r,new Cs))};break;case"stl":s={loader:new AM(ii),getObject:r=>new St(r,new Qn)};break;case"json":s={loader:new dp(ii)};break}return s}function NM(){return new EM(ii)}function kM(a,e,t){if(a){const n=new LM;n.setDecoderPath(t||"assets/draco/gltf/"),n.setDecoderConfig({type:"js"}),e.loader.setDRACOLoader(n)}}var S1="",OM=(a,e)=>{const t=a.__vccOpts||a;for(const[n,i]of e)t[n]=i;return t};const BM=Nt.defineComponent({name:"vue3dLoader"}),zM=Nt.defineComponent({...BM,props:{filePath:null,fileType: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:()=>[]},autoPlay:{type:Boolean,default:!0},enableDraco:{type:Boolean,default:!1},dracoDir:null,intersectRecursive:{type:Boolean,default:!1},enableDamping:{type:Boolean},dampingFactor:null},emits:["mousedown","mousemove","mouseup","click","dblclick","load","process","error"],setup(a,{emit:e}){const t=a;let n=null;const i=new Sp,s=new fe,r=new Dt(45,1,1,1e5),o=new ka,c=new Au;let l=new lt,u=null,h={},f=[],d=null,p=0,m=null,g=null,x=null;const y=Nt.ref({width:t.width||0,height:t.height||0}),b=Nt.ref(0),v=Nt.ref(!1),M=Nt.ref(!1),T=Nt.ref(null),C=Nt.ref(null);Nt.watch([()=>t.filePath,()=>t.fileType,()=>t.clearScene,()=>t.backgroundAlpha,()=>t.backgroundColor],k=>{(k[0]||k[1])&&ie(),k[2]&&ve(),(k[3]||k[4])&&W()}),Nt.watch([()=>t.rotation,()=>t.position,()=>t.scale,()=>t.lights],k=>{const z=["rotation","position","scale"];k.forEach((K,Q)=>{Q<3&&K?Fe(z[Q],K):ne()})},{deep:!0}),Nt.watch([()=>y],()=>{j(!0),W()},{deep:!0}),Nt.watch([()=>t.controlsOptions],()=>{$()},{deep:!0}),Nt.watch([()=>t.cameraRotation,()=>t.cameraPosition],()=>{j()},{deep:!0}),Nt.watch([()=>t.autoPlay],()=>{ct()}),Nt.onMounted(()=>{const{filePath:k,outputEncoding:z,webGLRendererOptions:K,showFps:Q,enableDamping:me,dampingFactor:R}=t;k&&typeof k=="object"&&(M.value=!0);const ae=T.value;_(ae),F();const Se=Object.assign({},{antialias:!0,alpha:!0},K,{canvas:C.value});u=new Jl(Se),u.shadowMap.enabled=!0;const Te=z==="linear"?ui:nt;u.outputEncoding=Te,h=new ew(r,ae),me&&(h.enableDamping=!0,R!=null&&(h.dampingFactor=R)),o.add(l),ie(),Z(),E(!0),ae.addEventListener("mousedown",U,!1),ae.addEventListener("mouseup",J,!1),ae.addEventListener("click",G,!1),ae.addEventListener("dblclick",X,!1),window.addEventListener("resize",F,!1),Q&&(m=Fo(),ae.appendChild(m.dom)),De()}),Nt.onBeforeUnmount(()=>{cancelAnimationFrame(p),u.dispose(),h&&h.dispose();const k=T.value;k.removeEventListener("mousedown",U,!1),k.removeEventListener("mousemove",q,!1),k.removeEventListener("mouseup",J,!1),k.removeEventListener("click",G,!1),k.removeEventListener("dblclick",X,!1),window.removeEventListener("resize",F,!1),n=null,l=null});function _(k){const{width:z,height:K}=t;z&&(k.style.width=`${z}px`),K&&(k.style.height=`${K}px`)}function E(k){const z=T.value;k?z.addEventListener("mousemove",q,!1):z.removeEventListener("mousemove",q,!1)}function F(){const{width:k,height:z}=t;(!k||!z)&&Nt.nextTick(()=>{const K=T.value;y.value={width:k||K.offsetWidth,height:z||K.offsetHeight}})}function U(k){E(!1);const z=B(k.clientX,k.clientY);e("mousedown",k,z)}function q(k){const z=B(k.clientX,k.clientY);e("mousemove",k,z)}function J(k){const z=B(k.clientX,k.clientY);e("mouseup",k,z),E(!0)}function G(k){const z=B(k.clientX,k.clientY);e("click",k,z)}function X(k){const z=B(k.clientX,k.clientY);e("dblclick",k,z)}function B(k,z){const K=Ee();if(!K||!T.value)return null;const Q=T.value.getBoundingClientRect();k-=Q.left,z-=Q.top,s.x=k/y.value.width*2-1,s.y=-(z/y.value.height)*2+1,i.setFromCamera(s,r);const me=i.intersectObject(K,t.intersectRecursive);return(me&&me.length)>0?me[0]:null}function Z(){W(),j(),ne(),$()}function Y(){if(!n)return;const k=M.value?dt(n):null,{position:z,rotation:K,scale:Q}=t;z&&(z instanceof Array?k!=null?n.position.set(z[k].x,z[k].y,z[k].z):n.position.set(0,0,0):n.position.set(z.x,z.y,z.z)),K&&(K instanceof Array?k!=null?n.rotation.set(K[k].x,K[k].y,K[k].z):n.rotation.set(0,0,0):n.rotation.set(K.x,K.y,K.z)),Q&&(Q instanceof Array?k!=null?n.scale.set(Q[k].x,Q[k].y,Q[k].z):n.scale.set(0,0,0):n.scale.set(Q.x,Q.y,Q.z))}function W(){const{backgroundColor:k,backgroundAlpha:z}=t;u.setSize(y.value.width,y.value.height),u.setPixelRatio(window.devicePixelRatio||1),u.setClearColor(new be(k).getHex()),u.setClearAlpha(z)}function j(k){const{cameraPosition:z,cameraRotation:K,cameraUp:Q,cameraLookAt:me}=t;if(r.aspect=y.value.width/y.value.height,r.updateProjectionMatrix(),!k)if(!me||!Q){if(!n)return;const R=IM(n).length();r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),z.x===0&&z.y===0&&z.z===0&&(r.position.z=R),r.lookAt(new P)}else r.position.set(z.x,z.y,z.z),K&&r.rotation.set(K.x,K.y,K.z),r.up.set(Q.x,Q.y,Q.z),r.lookAt(new P(me.x,me.y,me.z))}function ne(){const{lights:k}=t;o.remove(...f),f=[],k.forEach(z=>{if(!z.type)return;const K=z.type.toLowerCase();let Q=null;if(K==="ambient"||K==="ambientlight"){const me=z.color===0?z.color:z.color||4210752,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Do(me,R)}if(K==="point"||K==="pointlight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1,ae=z.distance||0,pe=z.decay===0?z.decay:z.decay||1;Q=new Ns(me,R,ae,pe),z.position&&Q.position.copy(z.position)}if(K==="directional"||K==="directionallight"){const me=z.color===0?z.color:z.color||16777215,R=z.intensity===0?z.intensity:z.intensity||1;Q=new Nr(me,R),z.position&&Q.position.copy(z.position),z.target&&Q.target.copy(z.target)}if(K==="hemisphere"||K==="hemispherelight"){const me=z.skyColor===0?z.skyColor:z.skyColor||16777215,R=z.groundColor===0?z.groundColor:z.groundColor||16777215,ae=z.intensity===0?z.intensity:z.intensity||1;Q=new wu(me,R,ae),z.position&&Q.position.copy(z.position)}Q&&(f.push(Q),o.add(Q))})}function $(){const{controlsOptions:k}=t;k&&Object.assign(h,k)}function ie(){const{filePath:k,parallelLoad:z}=t;z&&M?k.forEach((K,Q)=>{ce(Q)}):ce()}function ce(k){const{filePath:z,fileType:K,crossOrigin:Q,requestHeader:me,mtlPath:R,enableDraco:ae,dracoDir:pe}=t;if(!z)return;const Se=k||b.value,Te=M.value?z[Se]:z,He=typeof K=="string"?K:K?K[Se]:"",Ze=FM(Te,He,ae,pe);d=Ze.loader;const Qe=Ze.getObject?Ze.getObject:ye;if(n&&Se===0&&l.remove(n),me&&d.setRequestHeader(me),Q&&d.setCrossOrigin(Q),R)if(!(typeof R=="object"))H(Te,Qe,Se);else{if(!R[Se]){oe(Te,Qe,Se);return}H(Te,Qe,Se)}else oe(Te,Qe,Se)}function oe(k,z,K){const{textureImage:Q,parallelLoad:me}=t;d.load(k,(...R)=>{if(n=z(...R),we(n,k),Q){const pe=typeof Q=="string"?Q:Q[K];pe&&ue(n,pe)}je(),e("load",l)},R=>{me||he(R);const ae=b.value+1;e("process",R,ae)},R=>{e("error",R)})}function H(k,z,K){const{crossOrigin:Q,requestHeader:me,mtlPath:R}=t,ae=NM();Q&&ae.setCrossOrigin(Q),me&&ae.setRequestHeader(me);const pe=typeof R=="string"?R:R[K],Se=/^(.*\/)([^/]*)$/.exec(pe),Te=Se[1],He=Se[2];ae.setPath(Te).load(He,Ze=>{Ze.preload(),d.setMaterials(Ze),oe(k,z,K)})}function ye(k){return k}function we(k,z){const K=PM(n);v.value||(l.position.copy(K.negate()),v.value=!0),n=k;let Q=z.split("/");Q=Q[Q.length-1],n.fileName=Q,l.add(n),j(),Y(),ct()}function De(){p=requestAnimationFrame(De),Ve();const k=c.getDelta();g&&g instanceof rc&&g.update(k),g&&g instanceof Array&&g.forEach(z=>{z.update(k)}),xe()}function xe(){u.render(o,r)}function Ve(){const{showFps:k}=t;k&&m.update()}function he(k){const{filePath:z}=t;Math.floor(k.loaded/k.total*100)===100&&(M.value&&z.length>b.value?Nt.nextTick(()=>{if(b.value++,b.value===z.length){b.value=0;return}ce()}):b.value=0)}function ue(k,z){x||(x=new Fs),k.traverse(K=>{K.isMesh&&x.load(z,Q=>{K.material.map=Q,K.material.needsUpdate=!0},()=>{},Q=>{e("error",Q)})})}function ve(){l.clear()}function Fe(k,z){const K=Ee();if(!!K){if(M.value){K.children.forEach(Q=>{const me=dt(Q),R=k==="scale"?1:0;z[me]?Q[k].set(z[me].x,z[me].y,z[me].z):Q[k].set(R,R,R)});return}K[k].set(z.x,z.y,z.z)}}function Ee(){return M.value?l:n}function je(){const{filePath:k}=t;M.value?b.value===k.length&&ze():ze()}function ze(){const{labels:k}=t;if(!k)return;const z=M.value?l:n,K=me=>(x||(x=new Fs),x.load(me)),Q=(me,R)=>{const ae=Be(me,R),pe=new Mt(ae);return pe.needsUpdate=!0,pe};k.forEach(me=>{const R=me.image?K(me.image):Q(me.text,me.textStyle||{}),ae=new Oa({map:R,color:me.spriteMaterialColor||16777215}),pe=new Ql(ae);me.scale?pe.scale.set(me.scale.x||1,me.scale.y||1,me.scale.z||0):pe.scale.set(1,1,0),me.position&&pe.position.set(me.position.x,me.position.y,me.position.z),me.sid&&(pe.sid=me.sid),z.add(pe)})}function Be(k,z){const K=(V,_e,re,Ie,Ce,Je)=>{V.beginPath(),V.moveTo(_e+Je,re),V.lineTo(_e+Ie-Je,re),V.quadraticCurveTo(_e+Ie,re,_e+Ie,re+Je),V.lineTo(_e+Ie,re+Ce-Je),V.quadraticCurveTo(_e+Ie,re+Ce,_e+Ie-Je,re+Ce),V.lineTo(_e+Je,re+Ce),V.quadraticCurveTo(_e,re+Ce,_e,re+Ce-Je),V.lineTo(_e,re+Je),V.quadraticCurveTo(_e,re,_e+Je,re),V.closePath(),V.fill(),V.stroke()},Q=z.fontFamily||"Arial",me=z.fontSize===0||z.fontSize?z.fontSize:18,R=z.color||"#ffffff",ae=z.fontWeight||"normal",pe=z.borderWidth===0||z.borderWidth?z.borderWidth:4,Se=z.borderColor||"rgba(0,0,0,1)",Te=z.borderRadius===0||z.borderRadius?z.borderRadius:4,He=z.backgroundColor||"rgba(255, 255, 255, 1)",Ze=document.createElement("canvas"),Qe=Ze.getContext("2d");if(Qe){Qe.font=`${ae} ${me}px ${Q}`;const _e=Qe.measureText(k).width;Qe.fillStyle=He,Qe.strokeStyle=Se,Qe.lineWidth=pe,K(Qe,pe/2,pe/2,_e+pe,me*1.4+pe,Te),Qe.fillStyle=R,Qe.fillText(k,pe,me+pe)}return Ze}function dt(k){const{filePath:z}=t;let K;return z instanceof Array&&(K=z.map((Q,me)=>{if(Q.indexOf(k.fileName)>-1)return me}).filter(Q=>Q!=null)[0]),K}function ct(){const k=Ee();if(!!k){if(M.value){D(k);return}O(k)}}function O(k){const{autoPlay:z}=t;g=new rc(k),k.animations&&k.animations.length>0&&k.animations.forEach(K=>{if(K){const Q=g.clipAction(K);z?Q.play():Q.stop()}})}function D(k){const{autoPlay:z}=t;g=[],k.children.forEach((K,Q)=>{g.push(new rc(K)),K.animations&&K.animations.length>0&&K.animations.forEach(me=>{if(me){const R=g[Q].clipAction(me);z?R.play():R.stop()}})})}return(k,z)=>(Nt.openBlock(),Nt.createElementBlock("div",{ref_key:"containerElement",ref:T,class:"viewer-container"},[Nt.createElementVNode("canvas",{ref_key:"canvasElement",ref:C,class:"viewer-canvas"},null,512)],512))}});var Ec=OM(zM,[["__scopeId","data-v-04ca652e"]]),UM={install:a=>{a.component(Ec.name,Ec)},vue3dLoader:Ec};return Jr.Three=Qb,Jr.default=UM,Jr.vue3dLoader=Ec,Object.defineProperties(Jr,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),Jr}({},Vue); diff --git a/package-lock.json b/package-lock.json index c5d7c60..5e2e4a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vue-3d-loader", - "version": "2.0.9", + "version": "2.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vue-3d-loader", - "version": "2.0.9", + "version": "2.1.1", "license": "MIT", "dependencies": { "@types/three": "^0.143.0", diff --git a/package.json b/package.json index 0670dbd..6a10a1a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-3d-loader", "private": false, - "version": "2.1.1", + "version": "2.1.2", "main": "dist/vue-3d-loader.cjs.js", "module": "dist/vue-3d-loader.esm.js", "types": "dist/types/index.d.ts", diff --git a/src/3dLoader/loadModel.ts b/src/3dLoader/loadModel.ts index 131bbb6..4017bfa 100644 --- a/src/3dLoader/loadModel.ts +++ b/src/3dLoader/loadModel.ts @@ -81,6 +81,10 @@ function getLoader(filePath: string, fileType: string, isDraco: boolean, dracoDi loader: new GLTFLoader(manager), getObject: (gltf: any) => { const object = gltf.scene + // resolve gltf animations lose + if (gltf.animations) { + object.animations = gltf.animations; + } return object; }, };