mapbox-gl
Version:
A WebGL interactive maps library
2 lines (1 loc) • 28.7 kB
JavaScript
import{ee as t,fE as e,f4 as r,w as a,fI as o,eH as n,P as i,fJ as s,fK as l,fL as u,fM as d,ae as h,bG as c,fN as f,fO as g,fP as y,ao as p,fQ as m,fR as x,fS as A,fT as F,fU as b,cX as B,fA as w,dD as v,ef as M,fV as C,eD as I,fW as V,fX as L,dH as P,fY as O,fZ as E,aC as k,f8 as R}from"./shared.js";const _=t([{name:"a_pos_3f",components:3,type:"Float32"}]),S=t([{name:"a_normal_3",components:3,type:"Int16"}]),U=t([{name:"a_centroid_3",components:3,type:"Int16"}]),N=t([{name:"a_part_color_emissive",components:2,type:"Uint16"}]),D=t([{name:"a_faux_facade_color_emissive",components:2,type:"Uint16"}]),T=t([{name:"a_faux_facade_data",components:4,type:"Uint16"}]),z=t([{name:"a_faux_facade_vertical_range",components:2,type:"Uint16"}]),W=t([{name:"a_bloom_attenuation",components:4,type:"Float32"}]),H=t([{name:"a_flood_light_wall_radius_1i16",components:1,type:"Int16"}]),G=4096;class Y{constructor(t){this.module=t,this.memoryStack=this.module.malloc(G),this.memoryStackNextFree=this.memoryStack}createIntArray(t){const e=this.memoryStackNextFree;return this.memoryStackNextFree+=t.length*Int32Array.BYTES_PER_ELEMENT,this.memoryStackNextFree-this.memoryStack>G?-1:(new Int32Array(this.module.heap32.buffer,e,t.length).set(t),e)}createFloatArray(t){const e=this.memoryStackNextFree;return this.memoryStackNextFree+=t.length*Float32Array.BYTES_PER_ELEMENT,this.memoryStackNextFree-this.memoryStack>G?-1:(new Float32Array(this.module.heapF32.buffer,e,t.length).set(t),e)}readStringBuffer(t){let e="";for(;0!==this.module.heapU8[t];)e+=String.fromCharCode(this.module.heapU8[t]),++t;return e}setStyle(t){const e=t.normalScale;this.module.setStyle(e[0],e[1],e[2],t.tileToMeters)}setAOOptions(t,e){this.module.setAOOptions(t?1:0,e)}setMetricOptions(t,e){this.module.setMetricOptions(t?1:0,e)}setStructuralOptions(t){this.module.setStructuralOptions(t?1:0)}setFacadeOptions(t,e){this.module.setFacadeOptions(t,e?1:0)}setFauxFacadeOptions(t,e,r){this.module.setFauxFacadeOptions(t?1:0,e?1:0,r)}setFacadeClassifierOptions(t){this.module.setFacadeClassifierOptions(t)}generateMesh(t,e){this.memoryStackNextFree=this.memoryStack;for(const e of t){const t=this.createIntArray(e.ringIndices),r=this.createFloatArray(e.coordinates);if(-1===t||-1===r)return`building_gen: Out of stack memory: ${this.memoryStackNextFree-this.memoryStack}/4096`;this.module.addFeature(e.id,e.sourceId,e.minHeight,e.height,e.roofType,r,t,e.ringIndices.length-1)}for(const t of e){let e;e=t.entrances?JSON.parse(t.entrances):[];const r=this.createFloatArray(e),a=this.createFloatArray(t.coordinates);if(-1===r||-1===a)return`building_gen: Out of stack memory: ${this.memoryStackNextFree-this.memoryStack}/4096`;this.module.addFacade(t.sourceId,t.crossPerc,t.distanceToRoad,r,e.length,a,t.coordinates.length)}if(!this.module.generateMesh()){const t=this.module.getLastError();return this.readStringBuffer(t)}const r=this.module.getMeshCount(),a=new Array(r);for(let t=0;t<r;t++){const e=this.module.getPositionsPtr(t),r=this.module.getPositionsLength(t),o=new Float32Array(this.module.heapF32.buffer,e,r),n=this.module.getNormalsPtr(t),i=this.module.getNormalsLength(t),s=new Float32Array(this.module.heapF32.buffer,n,i),l=this.module.getAOPtr(t),u=this.module.getAOLength(t),d=new Float32Array(this.module.heapF32.buffer,l,u),h=this.module.getUVPtr(t),c=this.module.getUVLength(t),f=new Float32Array(this.module.heapF32.buffer,h,c),g=this.module.getFauxFacadePtr(t),y=this.module.getFauxFacadeLength(t),p=new Uint8Array(this.module.heapU8.buffer,g,y),m=this.module.getIndicesPtr(t),x=this.module.getIndicesLength(t),A=new Int16Array(this.module.heap16.buffer,m,x),F=this.module.getBuildingPart(t);a[t]={positions:o,normals:s,ao:d,uv:f,isFauxFacade:p,indices:A,buildingPart:F}}const o=this.module.getRingCount(),n=[];for(let t=0;t<o;t++){const e=this.module.getRingPtr(t),r=this.module.getRingLength(t),a=new Float32Array(this.module.heapF32.buffer,e,r);n.push(a)}return{meshes:a,outerRingLength:this.module.getOuterRingLength(),modifiedPolygonRings:n}}}const $=w.types,j=32767;function J(t,e){const r=p+e;for(const a of t)for(const t of a)if(t.x<-e||t.x>r||t.y<-e||t.y>r)return!1;return!0}function q(t){switch(t){case"flat":return 3;case"hipped":return 1;case"gabled":return 2;case"parapet":return 0;case"mansard":return 4;case"skillion":return 5;case"pyramidal":return 6;default:throw new Error(`Unknown roof shape: ${t}`)}}let K=null,X=null,Q=null;function Z(){if(!e(self))return null;if(null!=Q||null!=X)return null;if(null!=K)return K;const t=fetch(r());return K=function(t){let e,r,a,o,n;function i(){e=new Uint8Array(n.buffer),r=new Int16Array(n.buffer),a=new Int32Array(n.buffer),o=new Float32Array(n.buffer)}function s(){throw new Error("Unexpected BuildingGen error.")}const l=()=>{},u={a:{a:s,f:function(t){const r=e.length,a=Math.max(t>>>0,Math.ceil(1.2*r)),o=Math.ceil((a-r)/65536);try{return n.grow(o),i(),!0}catch(t){return!1}},g:s,b:l,c:l,d:l,e:l}};return(WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(t,u):t.then(t=>t.arrayBuffer()).then(t=>WebAssembly.instantiate(t,u))).then(t=>{const s=t.instance.exports;return(0,s.g)(),n=s.f,i(),new Y({setStyle:s.h,setAOOptions:s.i,setMetricOptions:s.j,setStructuralOptions:s.k,setFacadeOptions:s.l,setFauxFacadeOptions:s.m,setFacadeClassifierOptions:s.n,addFeature:s.o,addFacade:s.p,generateMesh:s.q,getLastError:s.r,getOuterRingLength:s.s,getMeshCount:s.t,getPositionsPtr:s.u,getPositionsLength:s.v,getNormalsPtr:s.w,getNormalsLength:s.x,getAOPtr:s.y,getAOLength:s.z,getUVPtr:s.A,getUVLength:s.B,getFauxFacadePtr:s.C,getFauxFacadeLength:s.D,getIndicesPtr:s.E,getIndicesLength:s.F,getBuildingPart:s.G,getRingCount:s.H,getRingPtr:s.I,getRingLength:s.J,malloc:s.K,free:s.L,heapU8:e,heap16:r,heap32:a,heapF32:o})})}(t).then(t=>{K=null,Q=t}).catch(t=>{a("Could not load building-gen"),K=null,X=t}),K}class tt{constructor(){this.layoutVertexArray=new M,this.layoutAttenuationArray=new E,this.layoutColorArray=new I,this.indexArray=new P,this.indexArrayForConflation=new P,this.segmentsBucket=new v}}class et{constructor(t){this.layoutFacadePaintArray=null,this.layoutFacadeDataArray=null,this.layoutFacadeVerticalRangeArray=null,this.segmentsBucket=new v,this.entranceBloom=new tt;const e=66560;this.layoutVertexArray=new M,this.layoutVertexArray.reserve(e),this.layoutNormalArray=new C,this.layoutNormalArray.reserve(e),this.layoutCentroidArray=new C,this.layoutCentroidArray.reserve(e),this.layoutColorArray=new I,this.layoutColorArray.reserve(e),this.layoutFloodLightDataArray=new V,this.layoutFloodLightDataArray.reserve(e),this.layoutAOArray=new L,this.layoutAOArray.reserve(e),this.indexArray=new P,this.indexArray.reserve(66560),this.indexArrayForConflation=new P,this.segmentsBucket=new v,this.entranceBloom=new tt,t&&(this.layoutFacadePaintArray=new I,this.layoutFacadeDataArray=new O,this.layoutFacadeVerticalRangeArray=new I)}reserve(t,e,r){this.layoutVertexArray.reserveForAdditional(t),this.layoutCentroidArray.reserveForAdditional(t),this.layoutFloodLightDataArray.reserveForAdditional(t),this.layoutNormalArray.reserveForAdditional(t),this.layoutAOArray.reserveForAdditional(t),this.layoutColorArray.reserveForAdditional(t),this.indexArray.reserveForAdditional(e),r&&(this.layoutFacadePaintArray.reserveForAdditional(t),this.layoutFacadeDataArray.reserveForAdditional(t),this.layoutFacadeVerticalRangeArray.reserveForAdditional(t))}}class rt{constructor(t){this.colorBufferUploaded=!1,this.maxHeight=0,this.replacementUpdateTime=0,this.activeReplacements=[],this.footprints=[],this.footprintsVertices=new o,this.footprintsIndices=new n,this.footprintsMin=new i(1/0,1/0),this.footprintsMax=new i(-1/0,-1/0),this.featuresOnBorder=[],this.buildingWithoutFacade=new et(!1),this.buildingWithFacade=new et(!0),this.indexArrayForConflationUploaded=!1,this.featureFootprintLookup=new Map,this.buildingIds=new Set,this.footprintLookup={},this.zoom=t.zoom,this.canonical=t.canonical,this.layers=t.layers,this.layerIds=this.layers.map(t=>t.fqid),this.index=t.index,this.hasPattern=!1,this.worldview=t.worldview,this.lut=t.lut,this.programConfigurations=new s(t.layers,{zoom:t.zoom,lut:t.lut}),this.stateDependentLayerIds=this.layers.filter(t=>t.isStateDependent()).map(t=>t.id),this.projection=t.projection,this.groundEffect=new l(t),this.groundEffect.groundRadiusArray=new u,this.hasAppearances=null}updateFootprints(t,e){const r=new d([],[],1),a={vertices:[],indices:new Uint32Array(0),grid:r,min:this.footprintsMin,max:this.footprintsMax,buildingIds:this.buildingIds};e.push({footprint:a,id:t})}updateAppearances(t,e,r,a){return{hasLayoutChanges:!1,hasUboChanges:!1}}populate(t,e,r,o){if(!Q)return;const n=B(r);this.tileToMeter=n,this.brightness=e.brightness,Q.setStyle({normalScale:[1,-1,n],tileToMeters:n}),Q.setAOOptions(!1,.3),Q.setMetricOptions(!1,16),Q.setStructuralOptions(!0),Q.setFacadeClassifierOptions(3);const s=new Map,l=new Map;let u=0;for(const{feature:e}of t){if("LineString"!==$[e.type]){s.set(e.id,e.properties.source_id);continue}const t=this.layers[0]._featureFilter.needGeometry;if(t&&!this.layers[0]._featureFilter.filter(new h(this.zoom),e,r))continue;const a=c(e,t);if(!t&&!this.layers[0]._featureFilter.filter(new h(this.zoom),a,r))continue;const n=t?a.geometry:f(e,r,o),i=[];for(const t of n)for(const e of t)i.push(e.x),i.push(e.y);const d={coordinates:i,crossPerc:e.properties.cross_perc,distanceToRoad:e.properties.distance_to_road,entrances:e.properties.entrances,sourceId:0},g=e.properties.source_id;let y=l.get(g);y||(y=[],l.set(g,y)),y.push(d),++u}this.maxHeight=0;const d=new Array,A=new Set,F=t=>{null!=t&&A.add(t)},b=(t,e)=>{null!=t&&d.push({buildingId:t,footprintIndex:e})},w=64*(t.length-u),v=w/2;this.buildingWithFacade.reserve(w,v,!0),this.buildingWithoutFacade.reserve(2*w,2*v,!1),this.footprintsIndices.reserve(16*(t.length-u)),this.footprintsVertices.reserve(8*(t.length-u));for(const{feature:u,id:d,index:B,sourceLayerIndex:w}of t){if("LineString"===$[u.type])continue;const t=this.layers[0]._featureFilter.needGeometry;if(t&&!this.layers[0]._featureFilter.filter(new h(this.zoom),u,r))continue;let v=null;if(u.properties&&u.properties.hasOwnProperty("building_id")&&(v=Number(u.properties.building_id),A.has(v)))continue;const M=c(u,t);if(!t&&!this.layers[0]._featureFilter.filter(new h(this.zoom),M,r))continue;const C=t?M.geometry:f(u,r,o),I=g(C,500);let V=!1;for(const t of I)if(1!==t.length){V=!0;break}if(V){F(v);continue}if(!J(C,163)){F(v);continue}const L=this.layers[0],P=q(L.layout.get("building-roof-shape").evaluate(u,{},r)),O=L.layout.get("building-base").evaluate(u,{},r),E=L.layout.get("building-height").evaluate(u,{},r),R=L.layout.get("building-flood-light-ground-radius").evaluate(u,{},r),_=L.paint.get("building-ambient-occlusion-intensity"),S=R/this.tileToMeter;u.properties["building-part"]="roof";const U=L.paint.get("building-color").evaluate(u,{},this.canonical).toPremultipliedRenderColor(this.lut),N=L.paint.get("building-emissive-strength").evaluate(u,{},this.canonical);u.properties["building-part"]="wall";const D=L.paint.get("building-color").evaluate(u,{},this.canonical).toPremultipliedRenderColor(this.lut),T=L.paint.get("building-emissive-strength").evaluate(u,{},this.canonical);u.properties["building-part"]="window";const z=L.paint.get("building-color").evaluate(u,{},this.canonical).toPremultipliedRenderColor(this.lut),W=L.paint.get("building-emissive-strength").evaluate(u,{},this.canonical);u.properties["building-part"]="door";const H=L.paint.get("building-color").evaluate(u,{},this.canonical).toPremultipliedRenderColor(this.lut),G=L.paint.get("building-emissive-strength").evaluate(u,{},this.canonical);let Y=L.layout.get("building-flood-light-wall-radius").evaluate(u,{},r);Y=k(Y,0,2048);const K=Y/2048*j,X=s.get(d),Z=l.get(X)||[],tt=0!==Z.length&&L.layout.get("building-facade").evaluate(u,{},r);Q.setFacadeOptions(4,!0),Q.setFauxFacadeOptions(tt,!1,1);let et=0,rt=0,at=0,ot=0,nt=0,it=0,st=0,lt=0,ut=0,dt=0,ht=0;if(tt){let t=Math.round(L.layout.get("building-facade-floors").evaluate(u,{},r));if(0===O){t=Math.max(1,t-(Z.length>0?1:0));let e=4;if(E>100){const t=[10,13,15];e=t[u.id?u.id%t.length:0]}else E<=10&&(e=3);Q.setFacadeOptions(e,!0),nt=(E<15?1.3:1.61803)*e/n}else nt=O/n;it=E/n,nt=Math.min(nt,it),at=L.layout.get("building-facade-unit-width").evaluate(u,{},r)/n,ot=(it-nt)/t,Q.setFauxFacadeOptions(!0,!0,at);const e=L.layout.get("building-facade-window").evaluate(u,{},r);et=e[0],rt=e[1],st=Math.floor(65535*Math.min(1,nt/p)),lt=Math.floor(65535*Math.min(1,it/p)),ut=Math.floor(255*et)<<8|Math.floor(255*rt),dt=Math.floor(65535*Math.min(1,at/p)),ht=Math.floor(65535*Math.min(1,ot/p))}const ct=Array(I.length),ft={x:1/0,y:1/0},gt={x:-1/0,y:-1/0},yt={x:0,y:0};let pt=0;for(let t=0;t<I.length;t++){const e=I[t];if(e.length>0){const r=[],a=Array(e.length+1);a[0]=0;for(let t=0;t<e.length;t++){const o=e[t];for(let t=0;t<o.length;t++){const e=o[o.length-t-1];ft.x=Math.min(ft.x,e.x),ft.y=Math.min(ft.y,e.y),gt.x=Math.max(gt.x,e.x),gt.y=Math.max(gt.y,e.y),yt.x+=e.x,yt.y+=e.y,pt++,r.push(e.x),r.push(e.y)}a[t+1]=r.length}ct[t]={id:u.id?u.id:0,height:E,minHeight:O,sourceId:0,roofType:P,coordinates:r,ringIndices:a}}}yt.x/=pt||1,yt.y/=pt||1;const mt=Q.generateMesh(ct,Z);if("string"==typeof mt){a(`Unable to generate building ${u.id}: ${mt}`),F(v);continue}if(0===mt.meshes.length||0===mt.modifiedPolygonRings.length){F(v);continue}const xt=tt?this.buildingWithFacade:this.buildingWithoutFacade;let At=0;for(const t of mt.meshes)At+=t.positions.length/3;const Ft=xt.segmentsBucket.prepareSegment(At,xt.layoutVertexArray,xt.indexArray),bt=[];let Bt=null,wt=0,vt=-1;const Mt=xt.layoutVertexArray.length,Ct=Mt+At;xt.layoutVertexArray.resize(Ct),xt.layoutCentroidArray.resize(Ct),xt.layoutNormalArray.resize(Ct),xt.layoutAOArray.resize(Ct),xt.layoutColorArray.resize(Ct),xt.layoutFloodLightDataArray.resize(Ct),tt&&(xt.layoutFacadePaintArray.resize(Ct),xt.layoutFacadeDataArray.resize(Ct),xt.layoutFacadeVerticalRangeArray.resize(Ct));const It=xt.indexArray.length;let Vt=0,Lt=Mt;for(const t of mt.meshes){let e,r;if(1===t.buildingPart)e=U,r=N;else if(0===t.buildingPart)e=D,r=T;else if(2===t.buildingPart)e=z,r=W;else{if(3!==t.buildingPart)continue;e=H,r=G}if(r=k(r,0,1),3===t.buildingPart){const e=new Array;for(let r=0;r<t.positions.length;r+=12){const a=t.positions[r+0],o=t.positions[r+1],n=t.positions[r+3],i=t.positions[r+4],s=t.positions[r+2],l=t.positions[r+8]-s,u=1,d=n-a,h=i-o,c=Math.hypot(d,h);e.push({pos:[a+.5*d,o+.5*h,s],normal:[h/c,-d/c,0],width:c,height:l,depth:u,points:[a,o,n,i]})}const r=xt.entranceBloom.segmentsBucket.prepareSegment(10*e.length,xt.entranceBloom.layoutVertexArray,xt.entranceBloom.indexArray),a=xt.entranceBloom.layoutVertexArray.length;wt=xt.entranceBloom.indexArray.length,y(e,.5/this.tileToMeter,xt.entranceBloom.indexArray,xt.entranceBloom.layoutVertexArray,xt.entranceBloom.layoutAttenuationArray);const o=xt.entranceBloom.layoutVertexArray.length-a;vt=xt.entranceBloom.indexArray.length-wt;for(let t=0;t<o;t++)xt.entranceBloom.layoutColorArray.emplaceBack(255*H.r<<8|255*H.g,255*H.b<<8|51*G);r.vertexLength+=o,r.primitiveLength+=vt,Bt={part:t.buildingPart,vertexOffset:a,vertexLength:o}}xt.layoutVertexArray.float32.set(t.positions,3*Lt);const a=t.positions.length/3;for(let o=0;o<a;++o){const a=3*o;Vt=Math.max(Vt,t.positions[a+2]);const n=t.normals[a+1]*j,i=t.normals[a+2]*j,s=3*(Lt+o);xt.layoutNormalArray.int16[s]=t.normals[a]*j,xt.layoutNormalArray.int16[s+1]=n,xt.layoutNormalArray.int16[s+2]=i;const l=t.ao[o];xt.layoutAOArray.uint8[Lt+o]=255*l;const u=1+(l-1)*_,d=255*e.b*u<<8|255*r;xt.layoutColorArray.uint16[2*(Lt+o)]=255*e.r*u<<8|255*e.g*u,xt.layoutColorArray.uint16[2*(Lt+o)+1]=d}const o=Math.min(8191,Math.max(0,Math.floor(yt.x))),n=Math.min(8191,Math.max(0,Math.floor(yt.y))),i=Math.floor(E),s=20,l=4*o+Math.min(3,Math.round((gt.x-ft.x)*this.tileToMeter/s)),u=4*n+Math.min(3,Math.round((gt.y-ft.y)*this.tileToMeter/s));for(let t=0;t<a;++t){const e=3*(Lt+t);xt.layoutCentroidArray.int16[e]=l,xt.layoutCentroidArray.int16[e+1]=u,xt.layoutCentroidArray.int16[e+2]=i}if(xt.layoutFloodLightDataArray.int16.fill(0===t.buildingPart?K:0,Lt,Lt+a),tt){const e=255*z.r<<8|255*z.g,r=255*z.b<<8|255*W;for(let t=0;t<a;++t){const a=2*(Lt+t);xt.layoutFacadePaintArray.uint16[a]=e,xt.layoutFacadePaintArray.uint16[a+1]=r}for(let e=0;e<a;++e)if(t.isFauxFacade[e]){const r=Math.min(65535,Math.floor(t.uv[2*e]*mt.outerRingLength));xt.layoutFacadeDataArray.emplace(Lt+e,1|r,ut,dt,ht),xt.layoutFacadeVerticalRangeArray.emplace(Lt+e,st,lt)}else xt.layoutFacadeDataArray.emplace(Lt+e,0,0,0,0),xt.layoutFacadeVerticalRangeArray.emplace(Lt+e,0,0)}const d=Ft.vertexLength,h=t.indices.length/3,c=xt.indexArray.length;xt.indexArray.resize(c+h);for(let e=0;e<h;++e){const r=3*e,a=3*c+r;xt.indexArray.uint16[a]=d+t.indices[r],xt.indexArray.uint16[a+1]=d+t.indices[r+1],xt.indexArray.uint16[a+2]=d+t.indices[r+2]}1!==t.buildingPart&&0!==t.buildingPart&&2!==t.buildingPart&&3!==t.buildingPart||bt.push({part:t.buildingPart,vertexOffset:Lt,vertexLength:t.positions.length/3}),Lt+=a,Ft.vertexLength+=a,Ft.primitiveLength+=t.indices.length/3}this.maxHeight=Math.max(this.maxHeight,Vt);const Pt=xt.indexArray.length-It,Ot=this.footprintsIndices.length,Et=this.footprintsVertices.length,kt=[],Rt=new i(1/0,1/0),_t=new i(-1/0,-1/0),St=this.groundEffect.vertexArray.length;for(const t of mt.modifiedPolygonRings){const e=[],r=new i(1/0,1/0),a=new i(-1/0,-1/0);for(let o=0;o<t.length;o+=2){const n=t.length-o-2;r.x=Math.min(r.x,t[n]),r.y=Math.min(r.y,t[n+1]),a.x=Math.max(a.x,t[n]),a.y=Math.max(a.y,t[n+1]);const s=new i(t[n],t[n+1]);e.push(s),kt.push(s.x,s.y),this.footprintsVertices.emplaceBack(s.x,s.y)}Rt.x=Math.min(Rt.x,r.x),Rt.y=Math.min(Rt.y,r.y),_t.x=Math.max(_t.x,a.x),_t.y=Math.max(_t.y,a.y),this.groundEffect.addData(e,[r,a],S)}const Ut=this.groundEffect.vertexArray.length-St;this.groundEffect.groundRadiusArray.reserveForAdditional(Ut);for(let t=0;t<Ut;t++)this.groundEffect.groundRadiusArray.emplaceBack(R);(ft.x<0||gt.x>p||ft.y<0||gt.y>p)&&this.featuresOnBorder.push({featureId:u.id,footprintIndex:this.footprints.length});{const t=m(kt,null,2);this.footprintsIndices.resize(this.footprintsIndices.length+t.length),this.footprintsIndices.uint16.set(t,Ot),this.buildingIds.add(null!=v?v:u.id),this.footprintsMin.x=Math.min(this.footprintsMin.x,Rt.x),this.footprintsMin.y=Math.min(this.footprintsMin.y,Rt.y),this.footprintsMax.x=Math.max(this.footprintsMax.x,_t.x),this.footprintsMax.y=Math.max(this.footprintsMax.y,_t.y);const e={footprintVertexOffset:Et,footprintVertexLength:this.footprintsVertices.length-Et,footprintIndexOffset:Ot,footprintIndexLength:this.footprintsIndices.length-Ot,min:Rt,max:_t,hiddenFlags:x,indicesOffset:It,indicesLength:Pt,bloomIndicesOffset:wt,bloomIndicesLength:vt,groundEffectVertexOffset:St,groundEffectVertexLength:Ut,hasFauxFacade:tt,height:Vt,promoteId:d,feature:M,parts:bt,buildingBloom:Bt},r=this.footprints.length;void 0!==u.id&&this.featureFootprintLookup.set(u.id,r),b(v,r),this.footprints.push(e)}this.programConfigurations.populatePaintArrays(xt.layoutVertexArray.length,u,B,{},e.availableImages,r,e.brightness),this.groundEffect.addPaintPropertiesData(u,B,{},e.availableImages,r,e.brightness),e.featureIndex.insert(u,C,B,w,this.index,Mt)}d.forEach(({buildingId:t,footprintIndex:e})=>{A.has(t)&&(this.footprints[e].hiddenFlags|=4)});const M=new Set;this.buildingIds.forEach((t,e,r)=>{A.has(t)||M.add(t)}),this.buildingIds=M,this.groundEffect.prepareBorderSegments()}update(t,e,r,a,o,n,i){this.programConfigurations.updatePaintArrays(t,e,o,r,a,n,i),this.groundEffect.update(t,e,o,r,a,n,i),this.evaluate(this.layers[0],t),this.colorBufferUploaded=!1}isEmpty(){return 0===this.buildingWithoutFacade.layoutVertexArray.length&&0===this.buildingWithFacade.layoutVertexArray.length}uploadPending(){return!this.uploaded||this.programConfigurations.needsUpload||this.groundEffect.programConfigurations.needsUpload}upload(t){const e=e=>{e.layoutVertexBuffer=t.createVertexBuffer(e.layoutVertexArray,_.members),e.layoutNormalBuffer=t.createVertexBuffer(e.layoutNormalArray,S.members),e.layoutCentroidBuffer=t.createVertexBuffer(e.layoutCentroidArray,U.members),e.layoutFloodLightDataBuffer=t.createVertexBuffer(e.layoutFloodLightDataArray,H.members),e.layoutFacadeDataArray&&e.layoutFacadeDataArray.length&&(e.layoutFacadeDataBuffer=t.createVertexBuffer(e.layoutFacadeDataArray,T.members)),e.layoutFacadeVerticalRangeArray&&e.layoutFacadeVerticalRangeArray.length&&(e.layoutFacadeVerticalRangeBuffer=t.createVertexBuffer(e.layoutFacadeVerticalRangeArray,z.members)),e.entranceBloom.layoutVertexArray.length&&(e.entranceBloom.layoutVertexBuffer=t.createVertexBuffer(e.entranceBloom.layoutVertexArray,_.members),e.entranceBloom.layoutAttenuationBuffer=t.createVertexBuffer(e.entranceBloom.layoutAttenuationArray,W.members)),this.uploadUpdatedColorBuffer(t),this.uploadUpdatedIndexBuffer(t)};this.uploaded||(e(this.buildingWithoutFacade),e(this.buildingWithFacade),this.groundEffect.upload(t)),this.groundEffect.uploadPaintProperties(t),this.programConfigurations.upload(t),this.uploaded=!0}destroy(){const t=t=>{t.layoutVertexBuffer&&(t.layoutVertexBuffer.destroy(),t.layoutNormalBuffer.destroy(),t.layoutColorBuffer.destroy(),t.segmentsBucket.destroy(),t.indexBuffer&&t.indexBuffer.destroy(),t.entranceBloom.layoutVertexBuffer&&(t.entranceBloom.layoutVertexBuffer.destroy(),t.entranceBloom.layoutColorBuffer.destroy(),t.entranceBloom.layoutAttenuationBuffer.destroy(),t.entranceBloom.indexBuffer.destroy(),t.entranceBloom.segmentsBucket.destroy()))};t(this.buildingWithoutFacade),t(this.buildingWithFacade),this.groundEffect.destroy(),this.programConfigurations.destroy()}updateFootprintHiddenFlags(t,e,r=!0){let a=!1;const o=r?e:0,n=0|(r?-1:~e);0===this.groundEffect.hiddenByLandmarkVertexArray.length&&this.groundEffect.hiddenByLandmarkVertexArray.resize(this.groundEffect.vertexArray.length);for(const e of t){const t=this.footprints[e],r=t.hiddenFlags&n|o;t.hiddenFlags!==r&&(t.hiddenFlags=r,a=!0,this.groundEffect.updateHiddenByLandmarkRange(t.groundEffectVertexOffset,t.groundEffectVertexLength,t.hiddenFlags!==x))}return a&&(this.indexArrayForConflationUploaded=!1),a}uploadUpdatedIndexBuffer(t){if(this.groundEffect.uploadHiddenByLandmark(t),this.indexArrayForConflationUploaded)return;const e=t=>{0!==t.indexArray.length&&(t.indexArrayForConflation.resize(t.indexArray.length),t.indexArrayForConflation.uint16.set(t.indexArray.uint16),t.entranceBloom.indexArrayForConflation.resize(t.entranceBloom.indexArray.length),t.entranceBloom.indexArrayForConflation.uint16.set(t.entranceBloom.indexArray.uint16))};e(this.buildingWithoutFacade),e(this.buildingWithFacade);for(const t of this.footprints){const e=t.hasFauxFacade?this.buildingWithFacade:this.buildingWithoutFacade,r=t.indicesOffset+t.indicesLength;if(t.hiddenFlags!==x){for(let a=t.indicesOffset;a<r;a++)e.indexArrayForConflation.uint16[3*a+0]=0,e.indexArrayForConflation.uint16[3*a+1]=0,e.indexArrayForConflation.uint16[3*a+2]=0;const a=t.bloomIndicesOffset+t.bloomIndicesLength;for(let r=t.bloomIndicesOffset;r<a;r++)e.entranceBloom.indexArrayForConflation.uint16[3*r+0]=0,e.entranceBloom.indexArrayForConflation.uint16[3*r+1]=0,e.entranceBloom.indexArrayForConflation.uint16[3*r+2]=0}}const r=e=>{0!==e.indexArray.length&&(e.indexBuffer?e.indexBuffer.updateData(e.indexArrayForConflation):e.indexBuffer=t.createIndexBuffer(e.indexArrayForConflation,!0),e.entranceBloom.indexBuffer?e.entranceBloom.indexBuffer.updateData(e.entranceBloom.indexArrayForConflation):e.entranceBloom.indexBuffer=t.createIndexBuffer(e.entranceBloom.indexArrayForConflation,!0))};r(this.buildingWithoutFacade),r(this.buildingWithFacade),this.indexArrayForConflationUploaded=!0}uploadUpdatedColorBuffer(t){const e=e=>{e.layoutColorBuffer?e.layoutColorBuffer.updateData(e.layoutColorArray):e.layoutColorBuffer=t.createVertexBuffer(e.layoutColorArray,N.members,!0),e.layoutFacadePaintArray&&(e.layoutFacadePaintBuffer?e.layoutFacadePaintBuffer.updateData(e.layoutFacadePaintArray):e.layoutFacadePaintBuffer=t.createVertexBuffer(e.layoutFacadePaintArray,D.members,!0)),e.entranceBloom.layoutColorBuffer?e.entranceBloom.layoutColorBuffer.updateData(e.entranceBloom.layoutColorArray):e.entranceBloom.layoutColorBuffer=t.createVertexBuffer(e.entranceBloom.layoutColorArray,N.members,!0)};e(this.buildingWithoutFacade),e(this.buildingWithFacade),this.colorBufferUploaded=!0}evaluate(t,e){const r=t.paint.get("building-ambient-occlusion-intensity");for(const a of this.footprints){if(4&a.hiddenFlags)continue;const o=e[a.promoteId],n=a.feature;n.properties["building-part"]="roof";const i=t.paint.get("building-color").evaluate(n,o,this.canonical).toPremultipliedRenderColor(this.lut),s=t.paint.get("building-emissive-strength").evaluate(n,o,this.canonical);n.properties["building-part"]="wall";const l=t.paint.get("building-color").evaluate(n,o,this.canonical).toPremultipliedRenderColor(this.lut),u=t.paint.get("building-emissive-strength").evaluate(n,o,this.canonical);n.properties["building-part"]="window";const d=t.paint.get("building-color").evaluate(n,o,this.canonical).toPremultipliedRenderColor(this.lut),h=t.paint.get("building-emissive-strength").evaluate(n,o,this.canonical);n.properties["building-part"]="door";const c=t.paint.get("building-color").evaluate(n,o,this.canonical).toPremultipliedRenderColor(this.lut),f=t.paint.get("building-emissive-strength").evaluate(n,o,this.canonical),g=a.hasFauxFacade?this.buildingWithFacade:this.buildingWithoutFacade;for(const t of a.parts){let e,o=i;1===t.part?(o=i,e=s):0===t.part?(o=l,e=u):2===t.part?(o=d,e=h):3===t.part&&(o=c,e=f),e=k(e,0,1);for(let n=0;n<t.vertexLength;n++){const i=t.vertexOffset+n,s=1+(g.layoutAOArray.uint8[i]/255-1)*r;g.layoutColorArray.emplace(i,o.r*s*255<<8|o.g*s*255,o.b*s*255<<8|255*e),a.hasFauxFacade&&g.layoutFacadePaintArray.emplace(i,255*d.r<<8|255*d.g,255*d.b<<8|255*h)}}const y=a.buildingBloom;if(y)for(let t=0;t<y.vertexLength;t++)g.entranceBloom.layoutColorArray.emplace(y.vertexOffset+t,255*c.r<<8|255*c.g,255*c.b<<8|51*f)}}needsEvaluation(){return!this.colorBufferUploaded}updateReplacement(t,e,r){if(e.updateTime===this.replacementUpdateTime)return;this.replacementUpdateTime=e.updateTime;const a=e.getReplacementRegionsForTile(t.toUnwrapped());if(A(this.activeReplacements,a))return;this.activeReplacements=a;for(const t of this.footprints)t.hiddenFlags&=~b;const o=[];for(const e of this.activeReplacements){if(e.order<r)continue;const a=Math.max(1,Math.pow(2,e.footprintTileId.canonical.z-t.canonical.z));for(const r of this.footprints)r.min.x>e.max.x||r.max.x<e.min.x||r.min.y>e.max.y||r.max.y<e.min.y||(o.length=0,ot(this.footprintsVertices,r.footprintVertexOffset,r.footprintVertexLength,e.footprintTileId.canonical,t.canonical,o),F(e.footprint,o,this.footprintsIndices.uint16,r.footprintIndexOffset,r.footprintIndexLength,0,-a)&&(r.hiddenFlags|=b))}0===this.groundEffect.hiddenByLandmarkVertexArray.length&&this.groundEffect.hiddenByLandmarkVertexArray.resize(this.groundEffect.vertexArray.length);for(const t of this.footprints)this.groundEffect.updateHiddenByLandmarkRange(t.groundEffectVertexOffset,t.groundEffectVertexLength,t.hiddenFlags!==x);this.indexArrayForConflationUploaded=!1}getFootprint(t){if(void 0!==t.id){const e=this.featureFootprintLookup.get(t.id);return this.footprints[e]}return null}getHeightAtTileCoord(t,e){let r=Number.NEGATIVE_INFINITY,a=!0;const o=4*(t+p)*p+(e+p);if(this.footprintLookup.hasOwnProperty(o)){const t=this.footprintLookup[o];return t?{height:t.height,hidden:t.hiddenFlags!==x}:void 0}const n=new i(t,e);for(const i of this.footprints)t>i.max.x||i.min.x>t||e>i.max.y||i.min.y>e||i.height<=r||at(n,this.footprintsVertices.float32.subarray(2*i.footprintVertexOffset,2*(i.footprintVertexOffset+i.footprintVertexLength)),this.footprintsIndices.uint16.subarray(i.footprintIndexOffset,i.footprintIndexOffset+i.footprintIndexLength))&&(r=i.height,this.footprintLookup[o]=i,a=i.hiddenFlags!==x);if(r!==Number.NEGATIVE_INFINITY)return{height:r,hidden:a};this.footprintLookup[o]=void 0}}function at(t,e,r){for(let a=0;a<r.length;a+=3){const o=r[a],n=r[a+1],i=r[a+2],s=e[2*o+0],l=e[2*o+1],u=e[2*n+0],d=e[2*n+1],h=e[2*i+0],c=e[2*i+1],f=(s-h)*(t.y-c)-(l-c)*(t.x-h),g=(u-s)*(t.y-l)-(d-l)*(t.x-s);if(f<0!=g<0&&0!==f&&0!==g)continue;const y=(h-u)*(t.y-d)-(c-d)*(t.x-u);if(0===y||y<0==f+g<=0)return!0}return!1}function ot(t,e,r,a,o,n){const s=Math.pow(2,a.z-o.z);for(let l=0;l<r;l++){let r=t.float32[2*(l+e)+0],u=t.float32[2*(l+e)+1];r=(r+o.x*p)*s-a.x*p,u=(u+o.y*p)*s-a.y*p,n.push(new i(r,u))}}R(rt,"BuildingBucket",{omit:["layers"]}),R(et,"BuildingGeometry"),R(tt,"BuildingBloomGeometry");export{rt as BuildingBucket,Z as waitForBuildingGen};//# sourceMappingURL=hd.worker.js.map