@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3 kB
JavaScript
import{createScreenPointArray as e,createRenderScreenPointArray3 as t}from"../../../../core/screenUtils.js";import{g as i,a as r}from"../../../../chunks/vec3.js";import{c as s}from"../../../../chunks/vec3f64.js";import{create as o,fromValues as n,distance as a,empty as c,expandPointInPlace as l,expand as h}from"../../../../geometry/support/aaBoundingRect.js";import{PlaneIndex as m}from"../../../../geometry/support/frustum.js";import{signedDistance as _,normal as u}from"../../../../geometry/support/plane.js";import{areaPoints2d as p}from"../../../../geometry/support/triangle.js";import{Visibility as d}from"./FeatureTileDescriptor3D.js";import{FeatureTileVisibility3D as f}from"./FeatureTileVisibility3D.js";import{Camera as S}from"../../webgl-engine/lib/Camera.js";class j{constructor(e){this._camera=new S,this._focusOnMap=[0,0],this._screenRect=o(),this._tileSize=e.tileSize,this._renderCoordsHelper=e.renderCoordsHelper,this._tilingScheme=e.tilingScheme,this._visibility=new f(e.renderCoordsHelper)}begin(e,t,i){this._camera.copyFrom(e),this._surfaceElevation=i,this._focusOnMap[0]=t.x,this._focusOnMap[1]=t.y,n(0,0,e.fullWidth,e.fullHeight,this._screenRect),this._visibility.begin(this._camera,i)}end(){this._visibility.end()}updateTile(e){e.measures.visibility=this._visibility.calculate(e),e.measures.distance=a(e.extent,this._focusOnMap),e.measures.visibility!==d.INVISIBLE&&this._updateScreenMeasure(e)}_updateScreenMeasure(e){const t=T,i=1<<t,r=e.measures.screenRect;c(r);let s=0;const o=e.lij[0]+t,n=e.lij[1]<<t,a=e.lij[2]<<t,l=this._tileSizeWithBias(e),h=l*l;for(let c=0;c<i;c++)for(let t=0;t<i;t++)if(s+=this._computeScreenArea(e,o,n+c,a+t,r),s>h)return void(e.measures.shouldSplit=!0);e.measures.shouldSplit=!1}_tileSizeWithBias(e){return e.measures.visibility===d.VISIBLE_WHEN_EXTENDED?this._tileSize*y:this._tileSize}_computeScreenArea(e,t,i,r,s){const o=e.measures.visibility===d.VISIBLE_WHEN_EXTENDED;this._projectToScreen(t,i,r,o,E),c(g);for(let n=0;n<4;n++)l(g,E[n]);return h(s,g,s),p(E[0],E[1],E[2])+p(E[0],E[2],E[3])}_projectToScreen(e,t,i,r,s){this._tilingScheme.ensureMaxLod(e),this._tilingScheme.getExtent(e,t,i,b),this._toRenderCoords(b,0,3,R[0]),this._toRenderCoords(b,2,3,R[1]),this._toRenderCoords(b,2,1,R[2]),this._toRenderCoords(b,0,1,R[3]),r&&(this._projectToPlane(R,this._camera.frustum[m.NEAR]),this._projectToPlane(R,this._camera.frustum[m.TOP]),this._projectToPlane(R,this._camera.frustum[m.BOTTOM]));for(let o=0;o<4;o++)this._camera.projectToRenderScreen(R[o],M),this._camera.renderToScreen(M,s[o])}_projectToPlane(e,t){for(let i=0;i<4;i++)C[i]=_(t,e[i]);const s=Math.max(C[0],C[1],C[2],C[3]);if(s>0){const o=i(v,u(t),-s);for(let t=0;t<4;t++)r(e[t],e[t],o)}}_toRenderCoords(e,t,i,r){return v[0]=e[t],v[1]=e[i],v[2]=this._surfaceElevation,this._renderCoordsHelper.toRenderCoords(v,this._tilingScheme.spatialReference,r),r}}const g=o(),T=2,y=5,E=[e(),e(),e(),e()],b=o(),v=s(),R=[s(),s(),s(),s()],C=[0,0,0,0],M=t();export{j as FeatureTileMeasurements3D};