text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.11/esri/copyright.txt for details.
  //>>built
  define("require exports ../../../../core/libs/gl-matrix-2/vec3 ../../../../core/libs/gl-matrix-2/vec3f64 ../../../../core/libs/gl-matrix-2/vec4 ../../../../core/libs/gl-matrix-2/vec4f64 ../../../../geometry/Point ../graphics/ElevationContext ../graphics/featureExpressionInfoUtils ../graphics/Graphics3DSymbolCommonCode ./I3SUtil ../../support/geometryUtils ../../support/orientedBoundingBox ../../support/projectionUtils".split(" "),function(x,y,e,h,r,t,u,v,p,q,w,l,m,n){return function(){function c(a,
  b,d,c,e,f,k){void 0===k&&(k={});this.indexSR=a;this._renderCoordsHelper=b;this.extent=c;this.elevationProvider=e;this.options=k;this._computedOBBs={};this._computedMBSs={};this._isNodeVisibleCached={};this.fp=l.frustum.create();this._poi=h.vec3f64.create();this._idleCamera=!0;this.maxDistance=0;this.maxLodLevel=2;this._tmp1=h.vec3f64.create();this._tmp2=h.vec3f64.create();this._tmp3=h.vec3f64.create();this._tmp0=h.vec3f64.create();this.supportedMetrics=["maxScreenThreshold","screenSpaceRelative",
  "removedFeatureDiameter","distanceRangeFromDefaultCamera"];this.screenspaceErrorBias=k.screenspaceErrorBias||1;this.progressiveLoadFactor=k.progressiveLoadFactor||1;this.updateCamera(d);this.engineSR=this._renderCoordsHelper.spatialReference;this.updateElevationInfo(f);this.tmpPoint=new u({x:0,y:0,z:0,spatialReference:a})}c.prototype.updateElevationInfo=function(a){this.invalidateCache();null==a?this._elevationContext=null:(this._elevationContext=new v,this._elevationContext.featureExpressionInfoContext=
  p.createContext(p.extractExpressionInfo(a,!1)),this._elevationContext.mixinApi(a))};c.prototype.updateCamera=function(a){l.frustum.fromMatrix(a.viewMatrix,a.projectionMatrix,this.fp);this._screenSizeFactor=1/(a.perScreenPixelRatio/2);this._camPos=a.eye;this._isNodeVisibleCached={};this.maxDistance=0};c.prototype.updateNode=function(a){delete this._isNodeVisibleCached[a]};c.prototype.setPointOfInterest=function(a){e.vec3.copy(this._poi,a)};c.prototype.updateScreenSpaceErrorBias=function(a){var b=this.screenspaceErrorBias;
  this.screenspaceErrorBias=a;return b};c.prototype.setCameraIdle=function(a){this._idleCamera!==a&&(this._idleCamera=a,this._isNodeVisibleCached={})};c.prototype.updateExtent=function(a){this.extent=a;this._isNodeVisibleCached={}};c.prototype.computeMbs=function(a){var b=this._computedMBSs[a.id];b||(b=t.vec4f64.fromValues(a.mbs[0],a.mbs[1],a.mbs[2],-1),this._computedMBSs[a.id]=b);0>b[3]&&(r.vec4.copy(b,a.mbs),this._elevationContext&&1E5>b[3]&&(this.tmpPoint.x=b[0],this.tmpPoint.y=b[1],this.tmpPoint.z=
  b[2],b[2]=q.computeElevation(this.elevationProvider,this.tmpPoint,this._elevationContext,this._renderCoordsHelper,null)),n.mbsToMbs(b,this.indexSR,b,this.engineSR));return b};c.prototype.computeObb=function(a){if(a.obb&&!(0>a.obb.halfSize[0])){var b=this._computedOBBs[a.id];b||(b=m.clone(a.obb),b.halfSize[0]=-1,this._computedOBBs[a.id]=b);0>b.halfSize[0]&&(b.halfSize[0]=a.obb.halfSize[0],e.vec3.copy(b.center,a.obb.center),this._elevationContext&&1E5>a.mbs[3]&&(this.tmpPoint.x=a.obb.center[0],this.tmpPoint.y=
  a.obb.center[1],this.tmpPoint.z=a.obb.center[2],b.center[2]=q.computeElevation(this.elevationProvider,this.tmpPoint,this._elevationContext,this._renderCoordsHelper,null)),n.bufferToBuffer(b.center,this.indexSR,0,b.center,this.engineSR,0,1));return b}};c.prototype._isNodeVisible=function(a){var b=this.computeMbs(a);return this.isMBSinExtent(b)?a.hasServiceOBB&&a.obb?(a=this.computeObb(a),m.isVisible(a,this.fp)):this.isMBSVisible(b):!1};c.prototype.isNodeVisible=function(a){if(!this._idleCamera)return this._isNodeVisible(a);
  if(null!=this._isNodeVisibleCached[a.id])return this._isNodeVisibleCached[a.id];this._isNodeVisibleCached[a.id]=this._isNodeVisible(a);return this._isNodeVisibleCached[a.id]};c.prototype.isGeometryVisible=function(a){return this.isNodeVisible(a)?a.hasServiceOBB?!0:(a=this.computeObb(a))?m.isVisible(a,this.fp):!0:!1};c.prototype.invalidateCache=function(a){if(null==a){for(var b=0,d=Object.keys(this._computedMBSs);b<d.length;b++)a=d[b],this._computedMBSs[a][3]=-1;b=0;for(d=Object.keys(this._computedOBBs);b<
  d.length;b++)a=d[b],this._computedOBBs[a].halfSize[0]=-1}else this._computedMBSs[a]&&(this._computedMBSs[a][3]=-1),this._computedOBBs[a]&&(this._computedOBBs[a].halfSize[0]=-1)};c.prototype.isMBSinExtent=function(a){return this.extent?0!==w.intersectBoundingBoxWithMbs(this.extent,a):!0};c.prototype.isMBSVisible=function(a){return l.frustum.intersectsSphere(this.fp.planes,l.sphere.wrap(a[3],a))};c.prototype.calcScreenSpaceSize=function(a,b){var d=this.computeMbs(a);a=e.vec3.squaredDistance(d,this._camPos);
  d=d[3];this.maxDistance=Math.max(this.maxDistance,Math.sqrt(a)-d);a-=d*d;return 0>a?.5*Number.MAX_VALUE:b/Math.sqrt(a)*this._screenSizeFactor};c.prototype.calcCameraDistance=function(a){a=this.computeMbs(a);a=e.vec3.distance(a,this._camPos)-a[3];this.maxDistance=Math.max(this.maxDistance,a);return a};c.prototype.calcAngleDependentLoD=function(a){a=this.computeMbs(a);var b=a[3];a=(Math.abs(a[0]*(a[0]-this._camPos[0])+a[1]*(a[1]-this._camPos[1])+a[2]*(a[2]-this._camPos[2]))/e.vec3.length(a)+b)/e.vec3.distance(a,
  this._camPos);return Math.min(1,a)};c.prototype.hasLOD=function(a){return null!=a.lodSelection};c.prototype.hasFeatures=function(a){return null!=a.featureData};c.prototype.getDistancePlanarMode=function(a,b){var d=a[0]-b[0],c=a[1]-b[1];a=a[2]-b[2];d=d*d+c*c;b=b[3];if(d<=b*b)return Math.abs(a);b=Math.sqrt(d)-b;return Math.sqrt(a*a+b*b)};c.prototype.getDistanceGlobeMode=function(a,b){var d=e.vec3.length(b),c=e.vec3.length(a)-d;e.vec3.scale(this._tmp0,a,e.vec3.dot(a,b)/e.vec3.squaredLength(a));var g=
  e.vec3.squaredDistance(b,this._tmp0),f=b[3];if(g<=f*f)return Math.abs(c);b=e.vec3.scale(this._tmp0,b,1/d);d=e.vec3.scale(this._tmp1,b,d-f*f/2/d);g=e.vec3.subtract(this._tmp2,a,d);g=e.vec3.subtract(this._tmp2,g,e.vec3.scale(this._tmp3,b,e.vec3.dot(b,g)));d=e.vec3.add(this._tmp2,d,e.vec3.scale(this._tmp2,g,f/e.vec3.length(g)));f=e.vec3.distance(a,d);2E5<=c&&(a=e.vec3.subtract(this._tmp1,a,d),a=e.vec3.dot(a,b)/e.vec3.length(a),.08>a&&(a=1E-4),f/=a);return f};c.prototype.getDistance=function(a,b){return this.engineSR===
  n.SphericalECEFSpatialReference?this.getDistanceGlobeMode(a,b):this.getDistancePlanarMode(a,b)};c.prototype._selectErrorMetric=function(a){for(var b=0;b<a.length;b++)if(0<=this.supportedMetrics.indexOf(a[b].metricType))return a[b];return null};c.prototype.getLodLevel=function(a){if(!a.lodSelection||0>=a.lodSelection.length||!1===this.hasFeatures(a))return 0;if(null==a.children||0===a.children.length)return this.maxLodLevel;var b=this._selectErrorMetric(a.lodSelection);if(null==b)return 0;if(1>this.progressiveLoadFactor){var d=
  this.screenspaceErrorBias;return this.evaluateLODmetric(a,this.progressiveLoadFactor*this.screenspaceErrorBias,b)?this.evaluateLODmetric(a,d,b)?2:1:0}return this.evaluateLODmetric(a,this.screenspaceErrorBias,b)?this.maxLodLevel:0};c.prototype.evaluateLODmetric=function(a,b,d){switch(d.metricType){case "screenSpaceRelative":a=this.computeMbs(a);a=this.getDistance(this._camPos,a);var c=2*a/this._screenSizeFactor;this.maxDistance=Math.max(this.maxDistance,a);return d.maxError*b<=c;case "maxScreenThreshold":return b=
  this.calcScreenSpaceSize(a,a.mbs[3]*b),this.options.angleDependentLoD&&(b*=this.calcAngleDependentLoD(a)),b<d.maxError;case "removedFeatureDiameter":return 10>this.calcScreenSpaceSize(a,d.maxError)*b;case "distanceRangeFromDefaultCamera":return this.calcCameraDistance(a)>d.maxError*b}return!1};c.prototype.distToPOI=function(a){a=this.computeMbs(a);return e.vec3.distance(a,this._poi)-a[3]};c.prototype.distCameraToPOI=function(){return e.vec3.distance(this._camPos,this._poi)};return c}()});