-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb6bc9b01ba1689bed692.js
1 lines (1 loc) · 18 KB
/
b6bc9b01ba1689bed692.js
1
(()=>{var t={948:function(t){(function(){var s,e,o,n,i,r;"undefined"!=typeof performance&&null!==performance&&performance.now?t.exports=function(){return performance.now()}:"undefined"!=typeof process&&null!==process&&process.hrtime?(t.exports=function(){return(s()-i)/1e6},e=process.hrtime,n=(s=function(){var t;return 1e9*(t=e())[0]+t[1]})(),r=1e9*process.uptime(),i=n-r):Date.now?(t.exports=function(){return Date.now()-o},o=Date.now()):(t.exports=function(){return(new Date).getTime()-o},o=(new Date).getTime())}).call(this)},26:(t,s,e)=>{for(var o=e(948),n="undefined"==typeof window?e.g:window,i=["moz","webkit"],r="AnimationFrame",h=n["request"+r],a=n["cancel"+r]||n["cancelRequest"+r],c=0;!h&&c<i.length;c++)h=n[i[c]+"Request"+r],a=n[i[c]+"Cancel"+r]||n[i[c]+"CancelRequest"+r];if(!h||!a){var l=0,u=0,p=[];h=function(t){if(0===p.length){var s=o(),e=Math.max(0,16.666666666666668-(s-l));l=e+s,setTimeout((function(){var t=p.slice(0);p.length=0;for(var s=0;s<t.length;s++)if(!t[s].cancelled)try{t[s].callback(l)}catch(t){setTimeout((function(){throw t}),0)}}),Math.round(e))}return p.push({handle:++u,callback:t,cancelled:!1}),u},a=function(t){for(var s=0;s<p.length;s++)p[s].handle===t&&(p[s].cancelled=!0)}}t.exports=function(t){return h.call(n,t)},t.exports.cancel=function(){a.apply(n,arguments)},t.exports.polyfill=function(t){t||(t=n),t.requestAnimationFrame=h,t.cancelAnimationFrame=a}},963:t=>{const s=/\((-?[.\d]+), (-?[.\d]+), (-?[.\d]+)\)/;class e{constructor(t,s,e){this.x=t,this.y=s,this.z=e}set(t,s,e){return this.x=t,this.y=s,this.z=e,this}update(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}floored(){return new e(Math.floor(this.x),Math.floor(this.y),Math.floor(this.z))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}offset(t,s,o){return new e(this.x+t,this.y+s,this.z+o)}translate(t,s,e){return this.x+=t,this.y+=s,this.z+=e,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}subtract(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}plus(t){return this.offset(t.x,t.y,t.z)}minus(t){return this.offset(-t.x,-t.y,-t.z)}scaled(t){return new e(this.x*t,this.y*t,this.z*t)}abs(){return new e(Math.abs(this.x),Math.abs(this.y),Math.abs(this.z))}volume(){return this.x*this.y*this.z}modulus(t){return new e(n(this.x,t.x),n(this.y,t.y),n(this.z,t.z))}distanceTo(t){var s=t.x-this.x,e=t.y-this.y,o=t.z-this.z;return Math.sqrt(s*s+e*e+o*o)}distanceSquared(t){var s=t.x-this.x,e=t.y-this.y,o=t.z-this.z;return s*s+e*e+o*o}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z}toString(){return"("+this.x+", "+this.y+", "+this.z+")"}clone(){return this.offset(0,0,0)}min(t){return new e(Math.min(this.x,t.x),Math.min(this.y,t.y),Math.min(this.z,t.z))}max(t){return new e(Math.max(this.x,t.x),Math.max(this.y,t.y),Math.max(this.z,t.z))}norm(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}cross(t){return new e(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)}unit(){const t=this.norm();return 0===t?this.clone():this.scaled(1/t)}normalize(){const t=this.norm();return 0!==t&&(this.x/=t,this.y/=t,this.z/=t),this}scale(t){return this.x*=t,this.y*=t,this.z*=t,this}xyDistanceTo(t){var s=t.x-this.x,e=t.y-this.y;return Math.sqrt(s*s+e*e)}xzDistanceTo(t){var s=t.x-this.x,e=t.z-this.z;return Math.sqrt(s*s+e*e)}yzDistanceTo(t){var s=t.y-this.y,e=t.z-this.z;return Math.sqrt(s*s+e*e)}innerProduct(t){return this.x*t.x+this.y*t.y+this.z*t.z}manhattanDistanceTo(t){return Math.abs(t.x-this.x)+Math.abs(t.y-this.y)+Math.abs(t.z-this.z)}toArray(){return[this.x,this.y,this.z]}}function o(t,o,n){if(null==t)return new e(0,0,0);if(Array.isArray(t))return new e(parseFloat(t[0],10),parseFloat(t[1],10),parseFloat(t[2],10));if("object"==typeof t)return new e(parseFloat(t.x,10),parseFloat(t.y,10),parseFloat(t.z,10));if("string"==typeof t&&null==o){var i=t.match(s);if(i)return new e(parseFloat(i[1],10),parseFloat(i[2],10),parseFloat(i[3],10));throw new Error("vec3: cannot parse: "+t)}return new e(parseFloat(t,10),parseFloat(o,10),parseFloat(n,10))}function n(t,s){var e=t%s;return e<0?e+s:e}t.exports=o,o.Vec3=e}},s={};function e(o){var n=s[o];if(void 0!==n)return n.exports;var i=s[o]={exports:{}};return t[o].call(i.exports,i,i.exports,e),i.exports}e.n=t=>{var s=t&&t.__esModule?()=>t.default:()=>t;return e.d(s,{a:s}),s},e.d=(t,s)=>{for(var o in s)e.o(s,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:s[o]})},e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),e.o=(t,s)=>Object.prototype.hasOwnProperty.call(t,s),(()=>{"use strict";const t=function(t,s){return(+t%(s=+s)+s)%s};class s{constructor(t){this.chunkSize=16,this.chunks={},this.blocksDef=t.blocksDef,this.neighbours={px:[-1,0,0],nx:[1,0,0],ny:[0,-1,0],py:[0,1,0],pz:[0,0,1],nz:[0,0,-1]}}vecToStr(t,s,e){return`${parseInt(t)}:${parseInt(s)}:${parseInt(e)}`}strToVec(t){return t=t.split(":"),[parseInt(t[0]),parseInt(t[1]),parseInt(t[2])]}computeVoxelOffset(s,e,o){const n=0|t(s,this.chunkSize),i=0|t(e,this.chunkSize),r=0|t(o,this.chunkSize);return i*this.chunkSize*this.chunkSize+r*this.chunkSize+n}computeChunkForVoxel(t,s,e){return[Math.floor(t/this.chunkSize),Math.floor(s/this.chunkSize),Math.floor(e/this.chunkSize)]}addChunkForVoxel(t,s,e){const o=this.vecToStr(...this.computeChunkForVoxel(t,s,e));let n=this.chunks[o];return n||(n=new Uint32Array(this.chunkSize*this.chunkSize*this.chunkSize),this.chunks[o]=n),n}getChunkForVoxel(t,s,e){const o=this.vecToStr(...this.computeChunkForVoxel(t,s,e));return this.chunks[o]}setVoxel(t,s,e,o){let n=this.getChunkForVoxel(t,s,e);n||(n=this.addChunkForVoxel(t,s,e)),n[this.computeVoxelOffset(t,s,e)]=o}getVoxel(t,s,e){const o=this.getChunkForVoxel(t,s,e);return o?o[this.computeVoxelOffset(t,s,e)]:0}setChunk(t,s,e,o){this.chunks[this.vecToStr(t,s,e)]=o}getBlock(t,s,e){const o=this.getVoxel(t,s,e),n=this.blocksDef[o];return void 0!==n&&{name:n[0],stateId:o,boundingBox:1===n[1]?"block":"empty",transparent:n[2]}}getBlockNeighbours(t,s,e){const o={},n=this.getBlock(t,s,e);for(const n in this.neighbours){const i=this.neighbours[n];o[n]=this.getBlock(t+i[0],s+i[1],e+i[2])}return[n,o]}intersectsRay(t,s){t.x+=.5,t.y+=.5,t.z+=.5,s.x+=.5,s.y+=.5,s.z+=.5;let e=s.x-t.x,o=s.y-t.y,n=s.z-t.z;const i=e*e+o*o+n*n,r=Math.sqrt(i);e/=r,o/=r,n/=r;let h=0,a=Math.floor(t.x),c=Math.floor(t.y),l=Math.floor(t.z);const u=e>0?1:-1,p=o>0?1:-1,k=n>0?1:-1,x=Math.abs(1/e),f=Math.abs(1/o),d=Math.abs(1/n),g=u>0?a+1-t.x:t.x-a,b=p>0?c+1-t.y:t.y-c,y=k>0?l+1-t.z:t.z-l;let m=x<1/0?x*g:1/0,z=f<1/0?f*b:1/0,M=d<1/0?d*y:1/0,v=-1;for(;h<=r;){const s=this.getBlock(a,c,l);let i;if(i="air"===s.name||"cave_air"===s.name||"void_air"===s.name||"water"===s.name?0:1,i)return{position:[t.x+h*e,t.y+h*o,t.z+h*n],normal:[0===v?-u:0,1===v?-p:0,2===v?-k:0],voxel:i};m<z?m<M?(a+=u,h=m,m+=x,v=0):(l+=k,h=M,M+=d,v=2):z<M?(c+=p,h=z,z+=f,v=1):(l+=k,h=M,M+=d,v=2)}return null}reset(){this.chunks={}}}const o={water:function(t,s,e){const o=this.chunkTerrain.getBlock(e[0],e[1],e[2]);if(10==o.stateId-32)for(const o in this.neighbours){const n=this.neighbours[o];"water"!==this.chunkTerrain.getBlock(e[0]+n[0],e[1]+n[1],e[2]+n[2]).name&&this.addFace(t,s,o,e)}else for(const n in this.neighbours){const i=this.neighbours[n];if("water"===this.chunkTerrain.getBlock(e[0]+i[0],e[1]+i[1],e[2]+i[2]).name)continue;const r=this.genBlockFace(n,o,e),h=[];for(let t=-1;t<=1;t++)for(let s=-1;s<=1;s++){const o=this.chunkTerrain.getBlock(e[0]+t,e[1],e[2]+s);"water"===o.name?o.stateId-32==10?h.push(0):h.push((o.stateId-33)/10):"block"===o.boundingBox?h.push(10):h.push(1)}const a=[Math.min(h[0],h[1],h[3],h[4]),Math.min(h[1],h[2],h[4],h[5]),Math.min(h[4],h[5],h[7],h[8]),Math.min(h[3],h[4],h[6],h[7])];switch(n){case"py":r.pos[1]-=a[3],r.pos[4]-=a[0],r.pos[7]-=a[2],r.pos[10]-=a[2],r.pos[13]-=a[0],r.pos[16]-=a[1];break;case"nx":r.pos[7]-=a[2],r.pos[10]-=a[2],r.pos[16]-=a[3];break;case"px":r.pos[7]-=a[0],r.pos[10]-=a[0],r.pos[16]-=a[1];break;case"nz":r.pos[7]-=a[3],r.pos[10]-=a[3],r.pos[16]-=a[0];break;case"pz":r.pos[7]-=a[1],r.pos[10]-=a[1],r.pos[16]-=a[2]}const c=this.ambientOcclusion(o,e,n);r.color=[...c[0],...c[2],...c[1],...c[1],...c[2],...c[3]],this.push(t,s,r,this.chunkTerrain.getBlock(...e).transparent)}},grass:function(t,s,e){const o=this.getUV("grass"),n={pos:[-.4+e[0],-.5+e[1],.4+e[2],.4+e[0],-.5+e[1],-.4+e[2],-.4+e[0],.4+e[1],.4+e[2],-.4+e[0],.4+e[1],.4+e[2],.4+e[0],-.5+e[1],-.4+e[2],.4+e[0],.4+e[1],-.4+e[2],-.4+e[0],-.5+e[1],-.4+e[2],.4+e[0],-.5+e[1],.4+e[2],-.4+e[0],.4+e[1],-.4+e[2],-.4+e[0],.4+e[1],-.4+e[2],.4+e[0],-.5+e[1],.4+e[2],.4+e[0],.4+e[1],.4+e[2],.4+e[0],-.5+e[1],-.4+e[2],-.4+e[0],-.5+e[1],.4+e[2],-.4+e[0],.4+e[1],.4+e[2],.4+e[0],-.5+e[1],-.4+e[2],-.4+e[0],.4+e[1],.4+e[2],.4+e[0],.4+e[1],-.4+e[2],.4+e[0],-.5+e[1],.4+e[2],-.4+e[0],-.5+e[1],-.4+e[2],-.4+e[0],.4+e[1],-.4+e[2],.4+e[0],-.5+e[1],.4+e[2],-.4+e[0],.4+e[1],-.4+e[2],.4+e[0],.4+e[1],.4+e[2]],norm:[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1],uv:[...o[0],...o[2],...o[1],...o[1],...o[2],...o[3],...o[0],...o[2],...o[1],...o[1],...o[2],...o[3],...o[2],...o[0],...o[1],...o[2],...o[1],...o[3],...o[2],...o[0],...o[1],...o[2],...o[1],...o[3]],color:[.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1,.1,1,.1]};this.push(t,s,n,!0)},lava:function(t,s,e){const o=this.chunkTerrain.getBlock(e[0],e[1],e[2]);if(9==(14&o.stateId)-1)for(const o in this.neighbours){const n=this.neighbours[o];"lava"!==this.chunkTerrain.getBlock(e[0]+n[0],e[1]+n[1],e[2]+n[2]).name&&this.addFace(t,s,o,e)}else for(const n in this.neighbours){const i=this.neighbours[n];if("lava"===this.chunkTerrain.getBlock(e[0]+i[0],e[1]+i[1],e[2]+i[2]).name)continue;const r=this.genBlockFace(n,o,e),h=[];for(let t=-1;t<=1;t++)for(let s=-1;s<=1;s++){const o=this.chunkTerrain.getBlock(e[0]+t,e[1],e[2]+s);"lava"===o.name?(14&o.stateId)-1==10?h.push(0):h.push(((14&o.stateId)-1)/10):"block"===o.boundingBox?h.push(10):h.push(1)}const a=[Math.min(h[0],h[1],h[3],h[4]),Math.min(h[1],h[2],h[4],h[5]),Math.min(h[4],h[5],h[7],h[8]),Math.min(h[3],h[4],h[6],h[7])];switch(n){case"py":r.pos[1]-=a[3],r.pos[4]-=a[0],r.pos[7]-=a[2],r.pos[10]-=a[2],r.pos[13]-=a[0],r.pos[16]-=a[1];break;case"nx":r.pos[7]-=a[2],r.pos[10]-=a[2],r.pos[16]-=a[3];break;case"px":r.pos[7]-=a[0],r.pos[10]-=a[0],r.pos[16]-=a[1];break;case"nz":r.pos[7]-=a[3],r.pos[10]-=a[3],r.pos[16]-=a[0];break;case"pz":r.pos[7]-=a[1],r.pos[10]-=a[1],r.pos[16]-=a[2]}this.ambientOcclusion(o,e,n);const c=this.ambientOcclusion(o,e,n);r.color=[...c[0],...c[2],...c[1],...c[1],...c[2],...c[3]],this.push(t,s,r,this.chunkTerrain.getBlock(...e).transparent)}}};class n{constructor(t){this.cellSize=16,this.undefinedBlock="black_shulker_box",this.blocksTex=t.blocksTex,this.blocksMapping=t.blocksMapping,this.chunkTerrain=t.chunkTerrain,this.toxelSize=t.toxelSize,this.q=1/this.toxelSize,this.neighbours={px:[-1,0,0],nx:[1,0,0],ny:[0,-1,0],py:[0,1,0],pz:[0,0,1],nz:[0,0,-1]},this.customRender={};for(const t in o)this.customRender[t]=o[t].bind(this)}getUV(t){let{x:s,y:e}=this.blocksMapping[t];s-=1,e-=1;const o=this.q*s,n=1-this.q*e-this.q,i=this.q*s+this.q,r=1-this.q*e;return[[o,n],[o,r],[i,n],[i,r]]}getUvForFace(t,s,e){let o,n,i;if(void 0!==this.blocksTex[t.name]||void 0!==this.blocksTex[String(t.stateId)])if(o=void 0!==this.blocksTex[String(t.stateId)]?this.blocksTex[String(t.stateId)]:this.blocksTex[t.name],void 0!==o.all)n=this.blocksMapping[o.all].x,i=this.blocksMapping[o.all].y;else if(void 0!==o.side){const t={py:"top",ny:"bottom"};void 0!==t[s]?(n=this.blocksMapping[o[t[s]]].x,i=this.blocksMapping[o[t[s]]].y):(n=this.blocksMapping[o.side].x,i=this.blocksMapping[o.side].y)}else n=this.blocksMapping[o[s]].x,i=this.blocksMapping[o[s]].y;else"water"===t.name?(n=this.blocksMapping.water_flow.x,i=this.blocksMapping.water_flow.y):"lava"===t.name?(n=this.blocksMapping.lava_flow.x,i=this.blocksMapping.lava_flow.y):this.blocksMapping[t.name]?(n=this.blocksMapping[t.name].x,i=this.blocksMapping[t.name].y):(n=this.blocksMapping[this.undefinedBlock].x,i=this.blocksMapping[this.undefinedBlock].y);n-=1,i-=1;const r=this.q*n,h=1-this.q*i-this.q,a=this.q*n+this.q,c=1-this.q*i,l=[[r,h],[r,c],[a,h],[a,c]];return e?[...l[0],...l[1],...l[2],...l[2],...l[1],...l[3]]:[...l[2],...l[0],...l[3],...l[3],...l[0],...l[1]]}genBlockFace(t,s,e,o){const n=this.getUvForFace(s,t,o),i=[];for(let s=0;s<6;s++)i.push(...this.neighbours[t]);const r={pz:[0,1,2,3],nx:[1,4,3,5],nz:[4,6,5,7],px:[6,0,7,2],py:[5,7,3,2],ny:[1,0,4,6]}[t];let h;h=o?[1,3,0,0,3,2]:[0,1,2,2,1,3];const a=[],c=[[-.5,-.5,.5],[.5,-.5,.5],[-.5,.5,.5],[.5,.5,.5],[.5,-.5,-.5],[.5,.5,-.5],[-.5,-.5,-.5],[-.5,.5,-.5]];for(let t=0;t<h.length;t++)a.push(c[r[h[t]]][0]+e[0],c[r[h[t]]][1]+e[1],c[r[h[t]]][2]+e[2]);return{pos:a,norm:i,uv:n}}addFace(t,s,e,o){const n=this.chunkTerrain.getBlock(...o),i=this.ambientOcclusion(n,o,e);let r;i[0]+i[3]>=i[1]+i[2]?(r=this.genBlockFace(e,n,o,!0),r.color=[...i[2],...i[3],...i[0],...i[0],...i[3],...i[1]]):(r=this.genBlockFace(e,n,o,!1),r.color=[...i[0],...i[2],...i[1],...i[1],...i[2],...i[3]]),this.push(t,s,r,this.chunkTerrain.getBlock(...o).transparent)}ambientOcclusion(t,s,e){const o={};for(let t=-1;t<=1;t++)for(let e=-1;e<=1;e++)for(let n=-1;n<=1;n++)o[`${t}:${e}:${n}`]="block"===this.chunkTerrain.getBlock(s[0]+t,s[1]+e,s[2]+n).boundingBox?1:0;const n={py:[this.aoColor(o["1:1:-1"]+o["0:1:-1"]+o["1:1:0"]),this.aoColor(o["1:1:1"]+o["0:1:1"]+o["1:1:0"]),this.aoColor(o["-1:1:-1"]+o["0:1:-1"]+o["-1:1:0"]),this.aoColor(o["-1:1:1"]+o["0:1:1"]+o["-1:1:0"])],ny:[this.aoColor(o["1:-1:1"]+o["0:-1:1"]+o["1:-1:0"]),this.aoColor(o["1:-1:-1"]+o["0:-1:-1"]+o["1:-1:0"]),this.aoColor(o["-1:-1:1"]+o["0:-1:1"]+o["-1:-1:0"]),this.aoColor(o["-1:-1:-1"]+o["0:-1:-1"]+o["-1:-1:0"])],px:[this.aoColor(o["-1:-1:0"]+o["-1:-1:-1"]+o["-1:0:-1"]),this.aoColor(o["-1:1:0"]+o["-1:1:-1"]+o["-1:0:-1"]),this.aoColor(o["-1:-1:0"]+o["-1:-1:1"]+o["-1:0:1"]),this.aoColor(o["-1:1:0"]+o["-1:1:1"]+o["-1:0:1"])],nx:[this.aoColor(o["1:-1:0"]+o["1:-1:1"]+o["1:0:1"]),this.aoColor(o["1:1:0"]+o["1:1:1"]+o["1:0:1"]),this.aoColor(o["1:-1:0"]+o["1:-1:-1"]+o["1:0:-1"]),this.aoColor(o["1:1:0"]+o["1:1:-1"]+o["1:0:-1"])],pz:[this.aoColor(o["0:-1:1"]+o["-1:-1:1"]+o["-1:0:1"]),this.aoColor(o["0:1:1"]+o["-1:1:1"]+o["-1:0:1"]),this.aoColor(o["0:-1:1"]+o["1:-1:1"]+o["1:0:1"]),this.aoColor(o["0:1:1"]+o["1:1:1"]+o["1:0:1"])],nz:[this.aoColor(o["0:-1:-1"]+o["1:-1:-1"]+o["1:0:-1"]),this.aoColor(o["0:1:-1"]+o["1:1:-1"]+o["1:0:-1"]),this.aoColor(o["0:-1:-1"]+o["-1:-1:-1"]+o["-1:0:-1"]),this.aoColor(o["0:1:-1"]+o["-1:1:-1"]+o["-1:0:-1"])]}[e];if("water"===t.name)for(let t=0;t<4;t++)n[t][0]/=4,n[t][1]/=4;else if("grass_block"===t.name&&"py"===e||t.name.includes("leaves"))for(let t=0;t<4;t++)n[t][0]/=4,n[t][2]/=4;return n}push(t,s,e,o){o?(t.positions.push(...e.pos),t.normals.push(...e.norm),t.uvs.push(...e.uv),t.colors.push(...e.color)):(s.positions.push(...e.pos),s.normals.push(...e.norm),s.uvs.push(...e.uv),s.colors.push(...e.color))}aoColor(t){const s={0:.9,1:.7,2:.5,3:.3}[t];return[s,s,s]}genChunkGeo(t,s,e){const o={positions:[],normals:[],uvs:[],colors:[]},n={positions:[],normals:[],uvs:[],colors:[]};for(let i=0;i<this.cellSize;i++)for(let r=0;r<this.cellSize;r++)for(let h=0;h<this.cellSize;h++){const a=[t*this.cellSize+i,s*this.cellSize+r,e*this.cellSize+h],[c,l]=this.chunkTerrain.getBlockNeighbours(...a);if("block"===c.boundingBox)for(const t in l){const s=l[t];(c.transparent&&"block"!==s.boundingBox||"block"!==s.boundingBox||s.transparent)&&this.addFace(n,o,t,a)}else this.customRender[c.name]&&this.customRender[c.name](n,o,a)}for(let t=0;t<n.positions.length;t++)o.positions.push(n.positions[t]),o.normals.push(n.normals[t]),o.colors.push(n.colors[t]);for(let t=0;t<n.uvs.length;t++)o.uvs.push(n.uvs[t]);return o}}var i=e(26),r=e.n(i),h=e(963),a=e.n(h);self.requestAnimationFrame=r();let c=null;class l{constructor(t){this.chunkTerrain=new s({blocksDef:t.blocksDef}),this.chunkMesher=new n({blocksTex:t.blocksTex,blocksMapping:t.blocksMapping,toxelSize:t.toxelSize,chunkTerrain:this.chunkTerrain}),this.neighbours=[[-1,0,0],[1,0,0],[0,-1,0],[0,1,0],[0,0,-1],[0,0,1]],this.chunkNeedsUpdate={},this.generatedChunks={},this.renderRadius=10,this.playerChunk=[0,0,0],this.loop()}distance(t){const s=this.chunkTerrain.strToVec(t),e=a()(...s);return a()(...this.playerChunk).distanceTo(e)}setVoxel(t){this.chunkTerrain.setVoxel(...t);const s=this.chunkTerrain.vecToStr(...c.chunkTerrain.computeChunkForVoxel(t[0],t[1],t[2]));this.chunkNeedsUpdate[s]=!0;for(let s=0;s<this.neighbours.length;s++){const e=this.neighbours[s],o=this.chunkTerrain.vecToStr(...this.chunkTerrain.computeChunkForVoxel(t[0]+e[0],t[1]+e[1],t[2]+e[2]));this.chunkNeedsUpdate[o]=!0}}setChunk(t){this.chunkTerrain.setChunk(t[0],t[1],t[2],t[3]);const s=c.chunkTerrain.vecToStr(t[0],t[1],t[2]);this.chunkNeedsUpdate[s]=!0;for(let s=0;s<this.neighbours.length;s++){const e=this.neighbours[s],o=this.chunkTerrain.vecToStr(t[0]+e[0],t[1]+e[1],t[2]+e[2]);this.chunkNeedsUpdate[o]=!0}}genNearestChunk(){let t="",s=-1,e=!1;for(const o in this.chunkNeedsUpdate){const n=this.distance(o);(-1===s||s>n)&&n<=this.renderRadius&&(e=!0,s=n,t=o)}if(e){const s=this.chunkTerrain.strToVec(t);this.generatedChunks[t]=!0,postMessage({type:"cellGeo",data:{cell:this.chunkMesher.genChunkGeo(...s),info:s,p:performance.now()}}),delete this.chunkNeedsUpdate[t]}}removeChunks(){for(const t in this.generatedChunks)this.distance(t)>this.renderRadius&&(delete this.generatedChunks[t],this.chunkNeedsUpdate[t]=!0,postMessage({type:"removeCell",data:t}))}loop(){this.removeChunks(),this.genNearestChunk(),self.requestAnimationFrame((()=>{this.loop()}))}updateChunksAroundPlayer(t){this.playerChunk=t[0],this.renderRadius=t[1]}}addEventListener("message",(function(t){const s=t.data.type,e=t.data.data;switch(s){case"init":if(c)return;c=new l(e);break;case"setVoxel":c.setVoxel(e);break;case"genChunkGeo":c.genChunkGeo(e);break;case"setChunk":c.setChunk(e);break;case"resetWorld":console.log("RESET WORLD!"),c.chunkTerrain.reset();break;case"updateChunksAroundPlayer":c.updateChunksAroundPlayer(e)}}))})()})();