polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
2 lines • 7.21 kB
JavaScript
(window.webpackJsonpPOLY=window.webpackJsonpPOLY||[]).push([[6],{214:function(e,t,r){"use strict";r.r(t),r.d(t,"DRACOLoader",(function(){return i}));var o=r(3),a=r(5),s=r(42),n=r(19),i=function(e){n.a.call(this,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"}};i.prototype=Object.assign(Object.create(n.a.prototype),{constructor:i,setDecoderPath:function(e){return this.decoderPath=e,this},setDecoderConfig:function(e){return this.decoderConfig=e,this},setWorkerLimit:function(e){return this.workerLimit=e,this},setVerbosity:function(){console.warn("THREE.DRACOLoader: The .setVerbosity() method has been removed.")},setDrawMode:function(){console.warn("THREE.DRACOLoader: The .setDrawMode() method has been removed.")},setSkipDequantization:function(){console.warn("THREE.DRACOLoader: The .setSkipDequantization() method has been removed.")},load:function(e,t,r,o){var a=new s.a(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(e,(e=>{var r={attributeIDs:this.defaultAttributeIDs,attributeTypes:this.defaultAttributeTypes,useUniqueIDs:!1};this.decodeGeometry(e,r).then(t).catch(o)}),r,o)},decodeDracoFile:function(e,t,r,o){var a={attributeIDs:r||this.defaultAttributeIDs,attributeTypes:o||this.defaultAttributeTypes,useUniqueIDs:!!r};this.decodeGeometry(e,a).then(t)},decodeGeometry:function(e,t){for(var r in t.attributeTypes){var o=t.attributeTypes[r];void 0!==o.BYTES_PER_ELEMENT&&(t.attributeTypes[r]=o.name)}var a,s=JSON.stringify(t);if(i.taskCache.has(e)){var n=i.taskCache.get(e);if(n.key===s)return n.promise;if(0===e.byteLength)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}var d=this.workerNextTaskID++,c=e.byteLength,u=this._getWorker(d,c).then((r=>(a=r,new Promise(((r,o)=>{a._callbacks[d]={resolve:r,reject:o},a.postMessage({type:"decode",id:d,taskConfig:t,buffer:e},[e])}))))).then((e=>this._createGeometry(e.geometry)));return u.catch((()=>!0)).then((()=>{a&&d&&this._releaseTask(a,d)})),i.taskCache.set(e,{key:s,promise:u}),u},_createGeometry:function(e){var t=new a.a;e.index&&t.setIndex(new o.a(e.index.array,1));for(var r=0;r<e.attributes.length;r++){var s=e.attributes[r],n=s.name,i=s.array,d=s.itemSize;t.setAttribute(n,new o.a(i,d))}return t},_loadLibrary:function(e,t){var r=new s.a(this.manager);return r.setPath(this.decoderPath),r.setResponseType(t),r.setWithCredentials(this.withCredentials),new Promise(((t,o)=>{r.load(e,t,void 0,o)}))},preload:function(){return this._initDecoder(),this},_initDecoder:function(){if(this.decoderPending)return this.decoderPending;var e="object"!=typeof WebAssembly||"js"===this.decoderConfig.type,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((t=>{var r=t[0];e||(this.decoderConfig.wasmBinary=t[1]);var o=i.DRACOWorker.toString(),a=["/* draco decoder */",r,"","/* worker */",o.substring(o.indexOf("{")+1,o.lastIndexOf("}"))].join("\n");this.workerSourceURL=URL.createObjectURL(new Blob([a]))})),this.decoderPending},_getWorker:function(e,t){return this._initDecoder().then((()=>{var r;this.workerPool.length<this.workerLimit?((r=new Worker(this.workerSourceURL))._callbacks={},r._taskCosts={},r._taskLoad=0,r.postMessage({type:"init",decoderConfig:this.decoderConfig}),r.onmessage=function(e){var t=e.data;switch(t.type){case"decode":r._callbacks[t.id].resolve(t);break;case"error":r._callbacks[t.id].reject(t);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+t.type+'"')}},this.workerPool.push(r)):this.workerPool.sort((function(e,t){return e._taskLoad>t._taskLoad?-1:1}));return(r=this.workerPool[this.workerPool.length-1])._taskCosts[e]=t,r._taskLoad+=t,r}))},_releaseTask:function(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]},debug:function(){console.log("Task load: ",this.workerPool.map((e=>e._taskLoad)))},dispose:function(){for(var e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this}}),i.DRACOWorker=function(){var e,t;function r(e,t,r,o,a,s){var n=s.num_components(),i=r.num_points()*n,d=i*a.BYTES_PER_ELEMENT,c=function(e,t){switch(t){case Float32Array:return e.DT_FLOAT32;case Int8Array:return e.DT_INT8;case Int16Array:return e.DT_INT16;case Int32Array:return e.DT_INT32;case Uint8Array:return e.DT_UINT8;case Uint16Array:return e.DT_UINT16;case Uint32Array:return e.DT_UINT32}}(e,a),u=e._malloc(d);t.GetAttributeDataArrayForAllPoints(r,s,c,d,u);var h=new a(e.HEAPF32.buffer,u,i).slice();return e._free(u),{name:o,array:h,itemSize:n}}onmessage=function(o){var a=o.data;switch(a.type){case"init":e=a.decoderConfig,t=new Promise((function(t){e.onModuleLoaded=function(e){t({draco:e})},DracoDecoderModule(e)}));break;case"decode":var s=a.buffer,n=a.taskConfig;t.then((e=>{var t=e.draco,o=new t.Decoder,i=new t.DecoderBuffer;i.Init(new Int8Array(s),s.byteLength);try{var d=function(e,t,o,a){var s,n,i=a.attributeIDs,d=a.attributeTypes,c=t.GetEncodedGeometryType(o);if(c===e.TRIANGULAR_MESH)s=new e.Mesh,n=t.DecodeBufferToMesh(o,s);else{if(c!==e.POINT_CLOUD)throw new Error("THREE.DRACOLoader: Unexpected geometry type.");s=new e.PointCloud,n=t.DecodeBufferToPointCloud(o,s)}if(!n.ok()||0===s.ptr)throw new Error("THREE.DRACOLoader: Decoding failed: "+n.error_msg());var u={index:null,attributes:[]};for(var h in i){var l,f,y=self[d[h]];if(a.useUniqueIDs)f=i[h],l=t.GetAttributeByUniqueId(s,f);else{if(-1===(f=t.GetAttributeId(s,e[i[h]])))continue;l=t.GetAttribute(s,f)}u.attributes.push(r(e,t,s,h,y,l))}c===e.TRIANGULAR_MESH&&(u.index=function(e,t,r){var o=3*r.num_faces(),a=4*o,s=e._malloc(a);t.GetTrianglesUInt32Array(r,a,s);var n=new Uint32Array(e.HEAPF32.buffer,s,o).slice();return e._free(s),{array:n,itemSize:1}}(e,t,s));return e.destroy(s),u}(t,o,i,n),c=d.attributes.map((e=>e.array.buffer));d.index&&c.push(d.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:d},c)}catch(e){console.error(e),self.postMessage({type:"error",id:a.id,error:e.message})}finally{t.destroy(i),t.destroy(o)}}))}}},i.taskCache=new WeakMap,i.setDecoderPath=function(){console.warn("THREE.DRACOLoader: The .setDecoderPath() method has been removed. Use instance methods.")},i.setDecoderConfig=function(){console.warn("THREE.DRACOLoader: The .setDecoderConfig() method has been removed. Use instance methods.")},i.releaseDecoderModule=function(){console.warn("THREE.DRACOLoader: The .releaseDecoderModule() method has been removed. Use instance methods.")},i.getDecoderModule=function(){console.warn("THREE.DRACOLoader: The .getDecoderModule() method has been removed. Use instance methods.")}}}]);
//# sourceMappingURL=6.js.map