polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
2 lines • 6.65 kB
JavaScript
(window.webpackJsonpPOLY=window.webpackJsonpPOLY||[]).push([[5],{223:function(e,t,r){"use strict";r.r(t),r.d(t,"BasisTextureLoader",(function(){return c}));var s=r(21);function a(e,t,r,a,o,i,n,c,h,T,d,p){s.a.call(this,null,i,n,c,h,T,a,o,d,p),this.image={width:t,height:r},this.mipmaps=e,this.flipY=!1,this.generateMipmaps=!1}a.prototype=Object.create(s.a.prototype),a.prototype.constructor=a,a.prototype.isCompressedTexture=!0;var o=r(42),i=r(0),n=r(19),c=function(e){n.a.call(this,e),this.transcoderPath="",this.transcoderBinary=null,this.transcoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.workerConfig={format:null,astcSupported:!1,bptcSupported:!1,etcSupported:!1,dxtSupported:!1,pvrtcSupported:!1}};c.taskCache=new WeakMap,c.prototype=Object.assign(Object.create(n.a.prototype),{constructor:c,setTranscoderPath:function(e){return this.transcoderPath=e,this},setWorkerLimit:function(e){return this.workerLimit=e,this},detectSupport:function(e){var t=this.workerConfig;if(t.astcSupported=e.extensions.has("WEBGL_compressed_texture_astc"),t.bptcSupported=e.extensions.has("EXT_texture_compression_bptc"),t.etcSupported=e.extensions.has("WEBGL_compressed_texture_etc1"),t.dxtSupported=e.extensions.has("WEBGL_compressed_texture_s3tc"),t.pvrtcSupported=e.extensions.has("WEBGL_compressed_texture_pvrtc")||e.extensions.has("WEBKIT_WEBGL_compressed_texture_pvrtc"),t.astcSupported)t.format=c.BASIS_FORMAT.cTFASTC_4x4;else if(t.bptcSupported)t.format=c.BASIS_FORMAT.cTFBC7_M5;else if(t.dxtSupported)t.format=c.BASIS_FORMAT.cTFBC3;else if(t.pvrtcSupported)t.format=c.BASIS_FORMAT.cTFPVRTC1_4_RGBA;else{if(!t.etcSupported)throw new Error("THREE.BasisTextureLoader: No suitable compressed texture format found.");t.format=c.BASIS_FORMAT.cTFETC1}return this},load:function(e,t,r,s){var a=new o.a(this.manager);a.setResponseType("arraybuffer"),a.setWithCredentials(this.withCredentials),a.load(e,(r=>{if(c.taskCache.has(r))return c.taskCache.get(r).promise.then(t).catch(s);this._createTexture(r,e).then(t).catch(s)}),r,s)},_createTexture:function(e,t){var r,s,o=e.byteLength,n=this._allocateWorker(o).then((t=>(r=t,s=this.workerNextTaskID++,new Promise(((t,a)=>{r._callbacks[s]={resolve:t,reject:a},r.postMessage({type:"transcode",id:s,buffer:e},[e])}))))).then((e=>{var t,r=this.workerConfig,{width:s,height:o,mipmaps:n,format:h}=e;switch(h){case c.BASIS_FORMAT.cTFASTC_4x4:t=new a(n,s,o,i.Qb);break;case c.BASIS_FORMAT.cTFBC7_M5:t=new a(n,s,o,i.Yb);break;case c.BASIS_FORMAT.cTFBC1:case c.BASIS_FORMAT.cTFBC3:t=new a(n,s,o,c.DXT_FORMAT_MAP[r.format],i.Zc);break;case c.BASIS_FORMAT.cTFETC1:t=new a(n,s,o,i.mc);break;case c.BASIS_FORMAT.cTFPVRTC1_4_RGB:t=new a(n,s,o,i.pc);break;case c.BASIS_FORMAT.cTFPVRTC1_4_RGBA:t=new a(n,s,o,i.bc);break;default:throw new Error("THREE.BasisTextureLoader: No supported format available.")}return t.minFilter=1===n.length?i.V:i.Y,t.magFilter=i.V,t.generateMipmaps=!1,t.needsUpdate=!0,t}));return n.catch((()=>!0)).then((()=>{r&&s&&(r._taskLoad-=o,delete r._callbacks[s])})),c.taskCache.set(e,{url:t,promise:n}),n},_initTranscoder:function(){if(!this.transcoderPending){var e=new o.a(this.manager);e.setPath(this.transcoderPath),e.setWithCredentials(this.withCredentials);var t=new Promise(((t,r)=>{e.load("basis_transcoder.js",t,void 0,r)})),r=new o.a(this.manager);r.setPath(this.transcoderPath),r.setResponseType("arraybuffer"),r.setWithCredentials(this.withCredentials);var s=new Promise(((e,t)=>{r.load("basis_transcoder.wasm",e,void 0,t)}));this.transcoderPending=Promise.all([t,s]).then((([e,t])=>{var r=c.BasisWorker.toString(),s=["/* basis_transcoder.js */",e,"/* worker */",r.substring(r.indexOf("{")+1,r.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([s])),this.transcoderBinary=t}))}return this.transcoderPending},_allocateWorker:function(e){return this._initTranscoder().then((()=>{var t;this.workerPool.length<this.workerLimit?((t=new Worker(this.workerSourceURL))._callbacks={},t._taskLoad=0,t.postMessage({type:"init",config:this.workerConfig,transcoderBinary:this.transcoderBinary}),t.onmessage=function(e){var r=e.data;switch(r.type){case"transcode":t._callbacks[r.id].resolve(r);break;case"error":t._callbacks[r.id].reject(r);break;default:console.error('THREE.BasisTextureLoader: Unexpected message, "'+r.type+'"')}},this.workerPool.push(t)):this.workerPool.sort((function(e,t){return e._taskLoad>t._taskLoad?-1:1}));return(t=this.workerPool[this.workerPool.length-1])._taskLoad+=e,t}))},dispose:function(){for(var e=0;e<this.workerPool.length;e++)this.workerPool[e].terminate();return this.workerPool.length=0,this}}),c.BASIS_FORMAT={cTFETC1:0,cTFETC2:1,cTFBC1:2,cTFBC3:3,cTFBC4:4,cTFBC5:5,cTFBC7_M6_OPAQUE_ONLY:6,cTFBC7_M5:7,cTFPVRTC1_4_RGB:8,cTFPVRTC1_4_RGBA:9,cTFASTC_4x4:10,cTFATC_RGB:11,cTFATC_RGBA_INTERPOLATED_ALPHA:12,cTFRGBA32:13,cTFRGB565:14,cTFBGR565:15,cTFRGBA4444:16},c.DXT_FORMAT={COMPRESSED_RGB_S3TC_DXT1_EXT:33776,COMPRESSED_RGBA_S3TC_DXT1_EXT:33777,COMPRESSED_RGBA_S3TC_DXT3_EXT:33778,COMPRESSED_RGBA_S3TC_DXT5_EXT:33779},c.DXT_FORMAT_MAP={},c.DXT_FORMAT_MAP[c.BASIS_FORMAT.cTFBC1]=c.DXT_FORMAT.COMPRESSED_RGB_S3TC_DXT1_EXT,c.DXT_FORMAT_MAP[c.BASIS_FORMAT.cTFBC3]=c.DXT_FORMAT.COMPRESSED_RGBA_S3TC_DXT5_EXT,c.BasisWorker=function(){var e,t,r;onmessage=function(s){var a,o,i=s.data;switch(i.type){case"init":e=i.config,a=i.transcoderBinary,t=new Promise((e=>{o={wasmBinary:a,onRuntimeInitialized:e},BASIS(o)})).then((()=>{var{BasisFile:e,initializeBasis:t}=o;r=e,t()}));break;case"transcode":t.then((()=>{try{for(var{width:t,height:s,hasAlpha:a,mipmaps:o,format:n}=function(t){var s=new r(new Uint8Array(t)),a=s.getImageWidth(0,0),o=s.getImageHeight(0,0),i=s.getNumLevels(0),n=s.getHasAlpha();function c(){s.close(),s.delete()}if(!n)switch(e.format){case 9:e.format=8}if(!a||!o||!i)throw c(),new Error("THREE.BasisTextureLoader:\tInvalid .basis file");if(!s.startTranscoding())throw c(),new Error("THREE.BasisTextureLoader: .startTranscoding failed");for(var h=[],T=0;T<i;T++){var d=s.getImageWidth(0,T),p=s.getImageHeight(0,T),_=new Uint8Array(s.getImageTranscodedSizeInBytes(0,T,e.format));if(!s.transcodeImage(_,0,T,e.format,0,n))throw c(),new Error("THREE.BasisTextureLoader: .transcodeImage failed.");h.push({data:_,width:d,height:p})}return c(),{width:a,height:o,hasAlpha:n,mipmaps:h,format:e.format}}(i.buffer),c=[],h=0;h<o.length;++h)c.push(o[h].data.buffer);self.postMessage({type:"transcode",id:i.id,width:t,height:s,hasAlpha:a,mipmaps:o,format:n},c)}catch(e){console.error(e),self.postMessage({type:"error",id:i.id,error:e.message})}}))}}}}}]);
//# sourceMappingURL=5.js.map