2023-05-29 23:44:47 +08:00
|
|
|
import{aB as ve,y as Ie,a1 as Ne,a2 as pe,a3 as I,a4 as X,ab as R,ak as Ce,ai as Oe,al as Pe,d as G,ac as N,aC as D,h as fe,aD as Fe,a5 as De,aE as ke,aF as Ue,f as z,aG as me,aH as ge,a6 as J,aI as He,aJ as q,b as Ge,aK as te,D as Be,af as je,g as Te,am as Ke,M as Ve,aL as Xe,K as ze,aM as qe,aN as We,G as W,ah as Ye,aj as Qe,ag as Je,aO as Ae,as as $e,ae as ye,O as Ze,a as _e,an as et,aP as Ee,aw as tt,ax as ne,ay as st,az as nt,aQ as ot,aR as rt,aS as it,aT as at,a7 as ct,aU as lt,aV as ut,F as ht,aW as dt,a8 as oe,aX as pt,at as ft,au as re,av as mt,V,aY as gt,B as Tt,S as At,Q as yt}from"./model.vue.d813c242.js";import"./entry.c4818dcd.js";class _t extends pe{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new xt(t)}),this.register(function(t){return new Nt(t)}),this.register(function(t){return new Ct(t)}),this.register(function(t){return new St(t)}),this.register(function(t){return new bt(t)}),this.register(function(t){return new wt(t)}),this.register(function(t){return new vt(t)}),this.register(function(t){return new Lt(t)}),this.register(function(t){return new It(t)}),this.register(function(t){return new Rt(t)}),this.register(function(t){return new Ot(t)})}load(e,t,r,s){const o=this;let n;this.resourcePath!==""?n=this.resourcePath:this.path!==""?n=this.path:n=I.extractUrlBase(e),this.manager.itemStart(e);const a=function(c){s?s(c):console.error(c),o.manager.itemError(e),o.manager.itemEnd(e)},i=new X(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,function(c){try{o.parse(c,n,function(u){t(u),o.manager.itemEnd(e)},a)}catch(u){a(u)}},r,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,r,s){let o;const n={},a={};if(typeof e=="string")o=e;else if(I.decodeText(new Uint8Array(e,0,4))===Re){try{n[A.KHR_BINARY_GLTF]=new Pt(e)}catch(l){s&&s(l);return}o=n[A.KHR_BINARY_GLTF].content}else o=I.decodeText(new Uint8Array(e));const i=JSON.parse(o);if(i.asset===void 0||i.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new qt(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const l=this.pluginCallbacks[u](c);a[l.name]=l,n[l.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const l=i.extensionsUsed[u],d=i.extensionsRequired||[];switch(l){case A.KHR_MATERIALS_UNLIT:n[l]=new Mt;break;case A.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:n[l]=new kt;break;case A.KHR_DRACO_MESH_COMPRESSION:n[l]=new Ft(i,this.dracoLoader);break;case A.KHR_TEXTURE_TRANSFORM:n[l]=new Dt;break;case A.KHR_MESH_QUANTIZATION:n[l]=new Ut;break;default:d.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}c.setExtensions(n),c.setPlugins(a),c.parse(r,s)}parseAsync(e,t){const r=this;return new Promise(function(s,o){r.parse(e,t,s,o)})}}function Et(){let h={};return{get:function(e){return h[e]},add:function(e,t){h[e]=t},remove:function(e){delete h[e]},removeAll:function(){h={}}}}const A={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:"KHR_mater
|
2023-05-28 15:00:40 +08:00
|
|
|
`),r=["#ifdef USE_GLOSSINESSMAP"," uniform sampler2D glossinessMap;","#endif"].join(`
|
|
|
|
`),s=["vec3 specularFactor = specular;","#ifdef USE_SPECULARMAP"," vec4 texelSpecular = texture2D( specularMap, vUv );"," // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture"," specularFactor *= texelSpecular.rgb;","#endif"].join(`
|
|
|
|
`),o=["float glossinessFactor = glossiness;","#ifdef USE_GLOSSINESSMAP"," vec4 texelGlossiness = texture2D( glossinessMap, vUv );"," // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture"," glossinessFactor *= texelGlossiness.a;","#endif"].join(`
|
|
|
|
`),n=["PhysicalMaterial material;","material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );","vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );","float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );","material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.","material.roughness += geometryRoughness;","material.roughness = min( material.roughness, 1.0 );","material.specularColor = specularFactor;"].join(`
|
|
|
|
`),a={specular:{value:new R().setHex(16777215)},glossiness:{value:1},specularMap:{value:null},glossinessMap:{value:null}};this._extraUniforms=a,this.onBeforeCompile=function(i){for(const c in a)i.uniforms[c]=a[c];i.fragmentShader=i.fragmentShader.replace("uniform float roughness;","uniform vec3 specular;").replace("uniform float metalness;","uniform float glossiness;").replace("#include <roughnessmap_pars_fragment>",t).replace("#include <metalnessmap_pars_fragment>",r).replace("#include <roughnessmap_fragment>",s).replace("#include <metalnessmap_fragment>",o).replace("#include <lights_physical_fragment>",n)},Object.defineProperties(this,{specular:{get:function(){return a.specular.value},set:function(i){a.specular.value=i}},specularMap:{get:function(){return a.specularMap.value},set:function(i){a.specularMap.value=i,i?this.defines.USE_SPECULARMAP="":delete this.defines.USE_SPECULARMAP}},glossiness:{get:function(){return a.glossiness.value},set:function(i){a.glossiness.value=i}},glossinessMap:{get:function(){return a.glossinessMap.value},set:function(i){a.glossinessMap.value=i,i?(this.defines.USE_GLOSSINESSMAP="",this.defines.USE_UV=""):(delete this.defines.USE_GLOSSINESSMAP,delete this.defines.USE_UV)}}}),delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this.setValues(e)}copy(e){return super.copy(e),this.specularMap=e.specularMap,this.specular.copy(e.specular),this.glossinessMap=e.glossinessMap,this.glossiness=e.glossiness,delete this.metalness,delete this.roughness,delete this.metalnessMap,delete this.roughnessMap,this}}class kt{constructor(){this.name=A.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,this.specularGlossinessParams=["color","map","lightMap","lightMapIntensity","aoMap","aoMapIntensity","emissive","emissiveIntensity","emissiveMap","bumpMap","bumpScale","normalMap","normalMapType","displacementMap","displacementScale","displacementBias","specularMap","specular","glossinessMap","glossiness","alphaMap","envMap","envMapIntensity"]}getMaterialType(){return $}extendParams(e,t,r){const s=t.extensions[this.name];e.color=new R(1,1,1),e.opacity=1;const o=[];if(Array.isArray(s.diffuseFactor)){const n=s.diffuseFactor;e.color.fromArray(n),e.opacity=n[3]}if(s.diffuseTexture!==void 0&&o.push(r.assignTexture(e,"map",s.diffuseTexture,N)),e.emissive=new R(0,0,0),e.glossiness=s.glossinessFactor!==void 0?s.glossinessFactor:1,e.specular=new R(1,1,1),Array.isArray(s.specularFactor)&&e.specular.fromArray(s.specularFactor),s.specularGlossinessTexture!==void 0){const n=s.specularGlossinessTexture;o.push(r.assignTexture(e,"glossinessMap",n)),o.push(r.assignTexture(e,"specularMap",n,N))}return Promise.all(o)}createMaterial(e){const t=new $(e);return t.fog=!0,t.color=e.color,t.map=e.map===void 0?null:e.map,t.lightMap=null,t.lightMapIntensity=1,t.aoMap=e.aoMap===void 0?null:e.aoMap,t.aoMapIntensity=1,t.emissive=e.emissive,t.emissiveIntensity=e.emissiveIntensity===void 0?1:e.emissiveIntensity,t.emissiveMap=e.emissiveMap===void 0?null:e.emissiveMap,t.bumpMap=e.bumpMap===void 0?null:e.bumpMap,t.bumpScale=1,t.normalMap=e.normalMap===void 0?null:e.normalMap,t.normalMapType=Fe,e.normalScale&&(t.normalScale=e.normalScale),t.displacementMap=null,t.displacementScale=1,t.displacementBias=0,t.specularMap=e.specularMap===void 0?null:e.specularMap,t.specular=e.specular,t.glossinessMap=e.glossinessMap===void 0?null:e.glossinessMap,t.glossiness=e.glossiness,t.alphaMap=null,t.envMap=e.envMap===void 0?null:e.envMap,t.envMapIntensity=1,t}}class Ut{constructor(){this.name=A.KHR_MESH_QUANTIZATION}}class C extends gt{constructor(e,t,r,s){super(e,t,r,s)}copySampleValue_(e){const t=this.resultBuffer,r=this.sampleValues,s=this.valueSize,o=e*s*3+s;for(let n=0;n!==s;n++)t[n]=r[o+n];return t}}C.prototype.beforeStart_=C.prototype.copySampleValue_;C.prototype.afterEnd_=C.prototype.copySampleValue_;C.prototype.interpolate_=function(h,e,t,r){const s=this.resultBuffer,o=this.sampleValues,n=this.valueSize,a=n*2,i=n*3,c=r-e,u=(t-e)/c,l=u*u,d=l*u,p=h*i,m=p-i,T=-2*d+3*l,f=d-l,g=1-T,_=f-l+u;for(let y=0;y!==n;y++){const k=o[m+y+n],w=o[m+
|
|
|
|
`);this.workerSourceURL=URL.createObjectURL(new Blob([n]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const s=new Worker(this.workerSourceURL);s._callbacks={},s._taskCosts={},s._taskLoad=0,s.postMessage({type:"init",decoderConfig:this.decoderConfig}),s.onmessage=function(o){const n=o.data;switch(n.type){case"decode":s._callbacks[n.id].resolve(n);break;case"error":s._callbacks[n.id].reject(n);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+n.type+'"')}},this.workerPool.push(s)}else this.workerPool.sort(function(s,o){return s._taskLoad>o._taskLoad?-1:1});const r=this.workerPool[this.workerPool.length-1];return r._taskCosts[e]=t,r._taskLoad+=t,r})}_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<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this}}function Qt(){let h,e;onmessage=function(n){const a=n.data;switch(a.type){case"init":h=a.decoderConfig,e=new Promise(function(u){h.onModuleLoaded=function(l){u({draco:l})},DracoDecoderModule(h)});break;case"decode":const i=a.buffer,c=a.taskConfig;e.then(u=>{const l=u.draco,d=new l.Decoder,p=new l.DecoderBuffer;p.Init(new Int8Array(i),i.byteLength);try{const m=t(l,d,p,c),T=m.attributes.map(f=>f.array.buffer);m.index&&T.push(m.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:m},T)}catch(m){console.error(m),self.postMessage({type:"error",id:a.id,error:m.message})}finally{l.destroy(p),l.destroy(d)}});break}};function t(n,a,i,c){const u=c.attributeIDs,l=c.attributeTypes;let d,p;const m=a.GetEncodedGeometryType(i);if(m===n.TRIANGULAR_MESH)d=new n.Mesh,p=a.DecodeBufferToMesh(i,d);else if(m===n.POINT_CLOUD)d=new n.PointCloud,p=a.DecodeBufferToPointCloud(i,d);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!p.ok()||d.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+p.error_msg());const T={index:null,attributes:[]};for(const f in u){const g=self[l[f]];let _,y;if(c.useUniqueIDs)y=u[f],_=a.GetAttributeByUniqueId(d,y);else{if(y=a.GetAttributeId(d,n[u[f]]),y===-1)continue;_=a.GetAttribute(d,y)}T.attributes.push(s(n,a,d,f,g,_))}return m===n.TRIANGULAR_MESH&&(T.index=r(n,a,d)),n.destroy(d),T}function r(n,a,i){const u=i.num_faces()*3,l=u*4,d=n._malloc(l);a.GetTrianglesUInt32Array(i,l,d);const p=new Uint32Array(n.HEAPF32.buffer,d,u).slice();return n._free(d),{array:p,itemSize:1}}function s(n,a,i,c,u,l){const d=l.num_components(),m=i.num_points()*d,T=m*u.BYTES_PER_ELEMENT,f=o(n,u),g=n._malloc(T);a.GetAttributeDataArrayForAllPoints(i,l,f,T,g);const _=new u(n.HEAPF32.buffer,g,m).slice();return n._free(g),{name:c,array:_,itemSize:d}}function o(n,a){switch(a){case Float32Array:return n.DT_FLOAT32;case Int8Array:return n.DT_INT8;case Int16Array:return n.DT_INT16;case Int32Array:return n.DT_INT32;case Uint8Array:return n.DT_UINT8;case Uint16Array:return n.DT_UINT16;case Uint32Array:return n.DT_UINT32}}}const Jt=new Map,Le=new _t,xe=new Yt;xe.setDecoderPath(ve.wasmPath);Le.setDRACOLoader(xe);var es=async(h,e)=>{const[t,r]=await Ie(Jt,h,()=>new Promise((s,o)=>{tt(),Le.load(h,n=>{ne();let a=!0;for(const i of n.scenes)i.traverse(c=>{var u;a&&c instanceof ye&&(a=!1),!((u=c.material)===null||u===void 0)&&u.map&&(c.material.map.encoding=st)});s([n,a])},nt,()=>{ne(),o()})}));return e?Ne(t.scene,r,t.animations):t.scene};export{es as default};
|