@arcgis/core 4.32.0-next.20241226 → 4.32.0-next.20241228

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{defaultFontFamily as t}from"../../core/fontUtils.js";import has from"../../core/has.js";import{clone as e}from"../../core/lang.js";import r from"../../core/Logger.js";import{deg2rad as i}from"../../core/mathUtils.js";import s from"../../core/ObjectPool.js";import{px2pt as o,pt2px as n}from"../../core/screenUtils.js";import{GeometryCursor as a}from"../../geometry/GeometryCursor.js";import{fromValues as l,create as h,expandPointInPlace as c,center as m,width as f,height as u,diagonal as d}from"../../geometry/support/aaBoundingRect.js";import{getBoundsXY as g}from"../../geometry/support/boundsUtils.js";import{polygonCentroid as p}from"../../geometry/support/centroid.js";import{isPoint as _,isPolygon as y,isPolyline as P,isExtent as S,isMultipoint as w}from"../../geometry/support/jsonUtils.js";import{SimpleEffectCursor as x}from"./CIMEffects.js";import M from"./CIMImageColorSubstitutionHelper.js";import{getEffectOperator as b,getPlacementOperator as k}from"./CIMOperators.js";import{Placement as C}from"./CIMPlacements.js";import{defaultCIMValues as v}from"./defaultCIMValues.js";import{LineCapStyle as I,LineJoinStyle as T}from"./enums.js";import{getFirstFrame as R}from"./imageUtils.js";import{rotate as z}from"./mathUtils.js";import{addColorStops as L}from"./rasterizingUtils.js";import F from"./Rect.js";import U from"./TextRasterizer.js";import{getNumericValue as A,isCIMFill as j,getSize as G,isSVGImage as D,getRelativeGradientSize as H,fromCIMFontDecoration as B,fromCIMFontStyle as E,fromCIMHorizontalAlignment as X,fromCIMVerticalAlignment as J,getFillColor as N,getStrokeColor as O,getStrokeWidth as q,getFontStyle as V,getFontWeight as W}from"./utils.js";import{destroyHiddenSvg as Y,createHiddenSvg as $,createSvgElement as K}from"../../views/2d/engine/svgUtils.js";import{glyphSize as Q,magicLabelLineHeight as Z,hittestToleranceSmallSymbol as tt,hittestSmallSymbolThreshold as et}from"../../views/2d/engine/webgl/definitions.js";import{shapeGlyphs as rt}from"../../views/2d/engine/webgl/mesh/templates/shapingUtils.js";import{roundPtToWholePixel as it,getLineWidth as st}from"../../views/2d/layers/graphics/graphicsUtils.js";const ot=Math.PI/180,nt=.5,at=()=>r.getLogger("esri.symbols.cim.CIMSymbolDrawHelper");class lt{constructor(t){this._t=t}static createIdentity(){return new lt([1,0,0,0,1,0])}clone(){const t=this._t;return new lt(t.slice())}transform(t){const e=this._t;return[e[0]*t[0]+e[1]*t[1]+e[2],e[3]*t[0]+e[4]*t[1]+e[5]]}static createScale(t,e){return new lt([t,0,0,0,e,0])}scale(t,e){const r=this._t;return r[0]*=t,r[1]*=t,r[2]*=t,r[3]*=e,r[4]*=e,r[5]*=e,this}scaleRatio(){return Math.sqrt(this._t[0]*this._t[0]+this._t[1]*this._t[1])}static createTranslate(t,e){return new lt([0,0,t,0,0,e])}translate(t,e){const r=this._t;return r[2]+=t,r[5]+=e,this}static createRotate(t){const e=Math.cos(t),r=Math.sin(t);return new lt([e,-r,0,r,e,0])}rotate(t){return lt.multiply(this,lt.createRotate(t),this)}angle(){const t=this._t[0],e=this._t[3],r=Math.sqrt(t*t+e*e);return[t/r,e/r]}static multiply(t,e,r){const i=t._t,s=e._t,o=i[0]*s[0]+i[3]*s[1],n=i[1]*s[0]+i[4]*s[1],a=i[2]*s[0]+i[5]*s[1]+s[2],l=i[0]*s[3]+i[3]*s[4],h=i[1]*s[3]+i[4]*s[4],c=i[2]*s[3]+i[5]*s[4]+s[5],m=r._t;return m[0]=o,m[1]=n,m[2]=a,m[3]=l,m[4]=h,m[5]=c,r}invert(){const t=this._t;let e=t[0]*t[4]-t[1]*t[3];if(0===e)return new lt([0,0,0,0,0,0]);e=1/e;const r=(t[1]*t[5]-t[2]*t[4])*e,i=(t[2]*t[3]-t[0]*t[5])*e,s=t[4]*e,o=-t[1]*e,n=-t[3]*e,a=t[0]*e;return new lt([s,o,r,n,a,i])}}class ht{constructor(t,e){this._resourceManager=t,this._transfos=[],this._sizeTransfos=[],this._geomUnitsPerPoint=1,this._placementPool=new s(C,void 0,void 0,100),this._earlyReturn=!1,this._mapRotation=0,this._transfos.push(e||lt.createIdentity()),this._sizeTransfos.push(e?e.scaleRatio():1)}setTransform(t,e){this._transfos=[t||lt.createIdentity()],this._sizeTransfos=[e||(t?t.scaleRatio():1)]}setGeomUnitsPerPoint(t){this._geomUnitsPerPoint=t}transformPt(t){return this._transfos[this._transfos.length-1].transform(t)}transformSize(t){return t*this._sizeTransfos[this._sizeTransfos.length-1]}reverseTransformPt(t){return this._transfos[this._transfos.length-1].invert().transform(t)}reverseTransformSize(t){return t/this._sizeTransfos[this._sizeTransfos.length-1]}reverseTransformScalar(t){return t/this._transfos[this._transfos.length-1].scaleRatio()}getTransformAngle(){return this._transfos[this._transfos.length-1].angle()}geomUnitsPerPoint(){return this.isEmbedded()?1:this._geomUnitsPerPoint}prevGeomUnitsPerPoint(){return this._transfos.length>2?1:this._geomUnitsPerPoint}isEmbedded(){return this._transfos.length>1}back(){return this._transfos[this._transfos.length-1]}push(t,e){const r=e?t.scaleRatio():1;lt.multiply(t,this.back(),t),this._transfos.push(t),this._sizeTransfos.push(this._sizeTransfos[this._sizeTransfos.length-1]*r)}pop(){this._transfos.splice(-1,1),this._sizeTransfos.splice(-1,1)}drawSymbol(t,e,r){if(t)switch(t.type){case"CIMPointSymbol":case"CIMLineSymbol":case"CIMPolygonSymbol":this.drawMultiLayerSymbol(t,e);break;case"CIMTextSymbol":this.drawTextSymbol(t,e,r)}}drawMultiLayerSymbol(t,e){if(!t||!e)return;const r=t.symbolLayers;if(!r)return;const i=t.effects;if(i&&i.length>0){const t=this.executeEffects(i,e);if(t){let e=t.next();for(;e;)this.drawSymbolLayers(r,e.asJSON()),e=t.next()}}else this.drawSymbolLayers(r,e)}executeEffects(t,e){const r=this._resourceManager.geometryEngine;let i=new x(a.fromJSONCIM(e));for(const s of t){const t=b(s);t&&(i=t.execute(i,s,this.geomUnitsPerPoint(),null,r))}return i}drawSymbolLayers(t,e){let r=t.length;for(;r--;){const i=t[r];if(!i||!1===i.enable)continue;const s=i.effects;if(s&&s.length>0){const t=this.executeEffects(s,e);if(t){let e=null;for(;(e=t.next())&&(this.drawSymbolLayer(i,e.asJSON()),!this._earlyReturn););}}else this.drawSymbolLayer(i,e);if(this._earlyReturn)return}}drawSymbolLayer(t,e){switch(t.type){case"CIMSolidFill":this.drawSolidFill(e,t.color,t.path);break;case"CIMHatchFill":this.drawHatchFill(e,t);break;case"CIMPictureFill":this.drawPictureFill(e,t);break;case"CIMGradientFill":this.drawGradientFill(e,t);break;case"CIMSolidStroke":this.drawSolidStroke(e,t.color,t.width,t.capStyle,t.joinStyle,t.miterLimit,t.path);break;case"CIMPictureStroke":this.drawPictureStroke(e,t);break;case"CIMGradientStroke":this.drawGradientStroke(e,t);break;case"CIMCharacterMarker":case"CIMPictureMarker":case"CIMVectorMarker":this.drawMarkerLayer(t,e)}}drawHatchFill(t,e){const r=ut(e,t,this.geomUnitsPerPoint());r&&(this.pushClipPath(t),this.drawMultiLayerSymbol(e.lineSymbol,r),this.popClipPath())}drawPictureFill(t,e){}drawGradientFill(t,e){}drawPictureStroke(t,e){}drawGradientStroke(t,e){}drawMarkerLayer(t,e){const r=t.markerPlacement;if(r){const i=k(r);if(i){const s="CIMMarkerPlacementInsidePolygon"===r.type||"CIMMarkerPlacementPolygonCenter"===r.type&&r.clipAtBoundary;s&&this.pushClipPath(e);const o=i.execute(a.fromJSONCIM(e),r,this.geomUnitsPerPoint(),null,this._resourceManager.geometryEngine);if(o){let e=null;for(;(e=o.next())&&(this.drawMarker(t,e),!this._earlyReturn););}s&&this.popClipPath()}}else{const r=this._placementPool.acquire();if(_(e))r.tx=e.x,r.ty=e.y,this.drawMarker(t,r);else if(y(e)){const i=p(e);i&&([r.tx,r.ty]=i,this.drawMarker(t,r))}else for(const i of e.points)if(r.tx=i[0],r.ty=i[1],this.drawMarker(t,r),this._earlyReturn)break;this._placementPool.release(r)}}drawMarker(t,e){switch(t.type){case"CIMCharacterMarker":case"CIMPictureMarker":this.drawPictureMarker(t,e);break;case"CIMVectorMarker":this.drawVectorMarker(t,e)}}drawPictureMarker(t,e){if(!t)return;const r=this._resourceManager.getResource(t.url),i=A(t.size,v.CIMPictureMarker.size);if(null==r||i<=0)return;const s=r.width,o=r.height;if(!s||!o)return;const n=s/o,a=A(t.scaleX,1),l=lt.createIdentity(),h=t.anchorPoint;if(h){let e=h.x,r=h.y;"Absolute"!==t.anchorPointUnits&&(e*=i*n*a,r*=i),l.translate(-e,-r)}let c=A(t.rotation);t.rotateClockwise&&(c=-c),this._mapRotation&&(c+=this._mapRotation),c&&l.rotate(c*ot);let m=A(t.offsetX),f=A(t.offsetY);if(m||f){if(this._mapRotation){const t=ot*this._mapRotation,e=Math.cos(t),r=Math.sin(t),i=m*r+f*e;m=m*e-f*r,f=i}l.translate(m,f)}const u=this.geomUnitsPerPoint();1!==u&&l.scale(u,u);const d=e.getAngle();d&&l.rotate(d),l.translate(e.tx,e.ty),this.push(l,!1),this.drawImage(t,i),this.pop()}drawVectorMarker(t,e){if(!t)return;const r=t.markerGraphics;if(!r)return;const i=A(t.size,v.CIMVectorMarker.size),s=t.frame,o=s?s.ymax-s.ymin:0,n=i&&o?i/o:1,a=lt.createIdentity();s&&a.translate(.5*-(s.xmax+s.xmin),.5*-(s.ymax+s.ymin));const l=t.anchorPoint;if(l){let e=l.x,r=l.y;"Absolute"!==t.anchorPointUnits?s&&(e*=s.xmax-s.xmin,r*=s.ymax-s.ymin):(e/=n,r/=n),a.translate(-e,-r)}1!==n&&a.scale(n,n);let h=A(t.rotation);t.rotateClockwise&&(h=-h),this._mapRotation&&(h+=this._mapRotation),h&&a.rotate(h*ot);let c=A(t.offsetX),m=A(t.offsetY);if(c||m){if(this._mapRotation){const t=ot*this._mapRotation,e=Math.cos(t),r=Math.sin(t),i=c*r+m*e;c=c*e-m*r,m=i}a.translate(c,m)}const f=this.geomUnitsPerPoint();1!==f&&a.scale(f,f);const u=e.getAngle();u&&a.rotate(u),a.translate(e.tx,e.ty),this.push(a,t.scaleSymbolsProportionally);for(const d of r){d?.symbol&&d.geometry||at().error("Invalid marker graphic",d);let t=d.textString;if("number"==typeof t&&(t=t.toString()),this.drawSymbol(d.symbol,d.geometry,t),this._earlyReturn)break}this.pop()}drawTextSymbol(t,e,r){if(!t)return;if(!_(e))return;if(A(t.height,v.CIMTextSymbol.height)<=0)return;const i=lt.createIdentity();let s=A(t.angle);s=-s,s&&i.rotate(s*ot);const o=A(t.offsetX),n=A(t.offsetY);(o||n)&&i.translate(o,n);const a=this.geomUnitsPerPoint();1!==a&&i.scale(a,a),i.translate(e.x,e.y),this.push(i,!1),this.drawText(t,r),this.pop()}}class ct extends ht{constructor(t,e){super(t,e),this.reset()}reset(){this._xmin=this._ymin=1/0,this._xmax=this._ymax=-1/0,this._clipCount=0}envelope(){return new F(this._xmin,this._ymin,this._xmax-this._xmin,this._ymax-this._ymin)}bounds(){return l(this._xmin,this._ymin,this._xmax,this._ymax)}drawSolidFill(t){if(t&&!(this._clipCount>0))if(y(t))this._processPath(t.rings,0);else if(P(t))this._processPath(t.paths,0);else if(S(t)){const e=_t(t);e&&this._processPath(e.rings,0)}else console.error("drawSolidFill Unexpected geometry type!")}drawSolidStroke(t,e,r){if(!t||this._clipCount>0||null==r||r<=0)return;const i=Math.max(.5*this.transformSize(A(r,v.CIMSolidStroke.width)),.5*nt);if(y(t))this._processPath(t.rings,i);else if(P(t))this._processPath(t.paths,i);else if(S(t)){const e=_t(t);e&&this._processPath(e.rings,i)}else console.error("drawSolidStroke unexpected geometry type!")}drawMarkerLayer(t,e){y(e)&&t.markerPlacement&&("CIMMarkerPlacementInsidePolygon"===t.markerPlacement.type||"CIMMarkerPlacementPolygonCenter"===t.markerPlacement.type&&t.markerPlacement.clipAtBoundary)?this._processPath(e.rings,0):super.drawMarkerLayer(t,e)}drawHatchFill(t,e){this.drawSolidFill(t)}drawPictureFill(t,e){this.drawSolidFill(t)}drawGradientFill(t,e){this.drawSolidFill(t)}drawPictureStroke(t,e){this.drawSolidStroke(t,null,e.width)}drawGradientStroke(t,e){this.drawSolidStroke(t,null,e.width)}pushClipPath(t){this.drawSolidFill(t),this._clipCount++}popClipPath(){this._clipCount--}drawImage(t,e){const{url:r}=t,i=A(t.scaleX,1);let s=i*e,o=e;const n=this._resourceManager.getResource(r);if(null!=n){const t=n.height/n.width;s=i*(e?t>1?e:e/t:n.width),o=e?t>1?e*t:e:n.height}this._merge(this.transformPt([-s/2,-o/2]),0),this._merge(this.transformPt([-s/2,o/2]),0),this._merge(this.transformPt([s/2,-o/2]),0),this._merge(this.transformPt([s/2,o/2]),0)}drawText(t,e){if(!e||0===e.length)return;this._textRasterizer||(this._textRasterizer=new U);const r=Pt(t);let[i,s]=this._textRasterizer.computeTextSize(e,r);i=o(i),s=o(s);const n=this.transformSize(1)*this.reverseTransformScalar(1);i*=n,s*=n;let a=0;switch(t.horizontalAlignment){case"Left":a=i/2;break;case"Right":a=-i/2}let l=0;switch(t.verticalAlignment){case"Bottom":l=s/2;break;case"Top":l=-s/2;break;case"Baseline":l=s/6}this._merge(this.transformPt([-i/2+a,-s/2+l]),0),this._merge(this.transformPt([-i/2+a,s/2+l]),0),this._merge(this.transformPt([i/2+a,-s/2+l]),0),this._merge(this.transformPt([i/2+a,s/2+l]),0)}_processPath(t,e){if(t)for(const r of t){const t=r?r.length:0;if(t>1){this._merge(this.transformPt(r[0]),e);for(let i=1;i<t;i++)this._merge(this.transformPt(r[i]),e)}}}_merge(t,e){t[0]-e<this._xmin&&(this._xmin=t[0]-e),t[0]+e>this._xmax&&(this._xmax=t[0]+e),t[1]-e<this._ymin&&(this._ymin=t[1]-e),t[1]+e>this._ymax&&(this._ymax=t[1]+e)}}class mt extends ht{constructor(){super(...arguments),this._searchPoint=[0,0],this._searchDistPoint=0,this._textInfo=null,this._svg=null,this._path=null,this._canvas=null}destroy(){this._svg=Y(this._svg),this._path=null,this._canvas=null}hitTest(t,e,r,i,s,a){const l=a*n(1);this.setTransform(),this.setGeomUnitsPerPoint(l),this._searchPoint=[(t[0]+t[2])/2,(t[1]+t[3])/2],this._searchDistPoint=(t[2]-t[0])/2/l,this._textInfo=i;const h=e&&("CIMPointSymbol"===e.type&&"Map"!==e.angleAlignment||"CIMTextSymbol"===e.type);if(this._mapRotation=h?s:0,!has("esri-mobile")){const t=o(tt*window.devicePixelRatio),r=o(et);!(("CIMLineSymbol"===e?.type||"CIMPolygonSymbol"===e?.type)&&e.symbolLayers?.some(j))&&"CIMMeshSymbol"!==e?.type&&(G(e)??0)<r&&(this._searchDistPoint=t)}return this._earlyReturn=!1,this.drawSymbol(e,r),this._earlyReturn}executeEffects(t,e){return"CIMGeometricEffectDashes"===t.at(-1)?.type&&(t=t.slice(0,-1)),super.executeEffects(t,e)}drawSolidFill(t,e,r){null!=r?this._hittestSvgPath(t,r,!0):this._hitTestFill(t)}drawHatchFill(t,e){this._hitTestFill(t)}drawPictureFill(t,e){this._hitTestFill(t)}drawGradientFill(t,e){this._hitTestFill(t)}drawSolidStroke(t,e,r,i,s,o,n){null!=n?this._hittestSvgPath(t,n,!1,r):this._hitTestStroke(t,r)}drawPictureStroke(t,e){this._hitTestStroke(t,e.width)}drawGradientStroke(t,e){this._hitTestStroke(t,e.width)}drawMarkerLayer(t,e){t.markerPlacement&&("CIMMarkerPlacementInsidePolygon"===t.markerPlacement.type||"CIMMarkerPlacementPolygonCenter"===t.markerPlacement.type&&t.markerPlacement.clipAtBoundary)?this._hitTestFill(e):super.drawMarkerLayer(t,e)}pushClipPath(t){}popClipPath(){}drawImage(t,e){const{url:r}=t,i=A(t.scaleX,1),s=this._resourceManager.getResource(r);if(null==s||0===s.height||0===e)return;const o=e*this.geomUnitsPerPoint(),n=o*i*(s.width/s.height),a=this.reverseTransformPt(this._searchPoint),l=this._searchDistPoint;Math.abs(a[0])<n/2+l&&Math.abs(a[1])<o/2+l&&(this._earlyReturn=!0)}drawText(t,e){const r=this._textInfo;if(!r)return;const i=r.get(t);if(!i)return;if(!i.glyphMosaicItems.glyphs.length)return;const s=it(A(t.height,v.CIMTextSymbol.height)),{lineGapType:o,lineGap:n}=t,a=o?yt(o,A(n),s):0,l="CIMBackgroundCallout"===t.callout?.type,h=rt(i.glyphMosaicItems,{scale:s/Q,angle:0,xOffset:0,yOffset:0,horizontalAlignment:t.horizontalAlignment,verticalAlignment:t.verticalAlignment,maxLineWidth:st(t.lineWidth),lineHeight:Z*Math.max(.25,Math.min(a||1,4)),decoration:t.font.decoration||"none",useCIMAngleBehavior:!0,hasBackground:l}),c=this.reverseTransformPt(this._searchPoint),m=c[0],f=c[1];for(const u of h.glyphs)if(m>u.xTopLeft&&m<u.xBottomRight&&f>-u.yBottomRight&&f<-u.yTopLeft){this._earlyReturn=!0;break}}_hitTestFill(t){let e=null;if(S(t)){const r=t;e=[[[r.xmin,r.ymin],[r.xmin,r.ymax],[r.xmax,r.ymax],[r.xmax,r.ymin],[r.xmin,r.ymin]]]}else if(y(t))e=t.rings;else{if(!P(t))return;e=t.paths}const r=this.reverseTransformPt(this._searchPoint);if(dt(r,e)&&(this._earlyReturn=!0),!this._earlyReturn){gt(r,e,this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint())&&(this._earlyReturn=!0)}}_getSvgPath(){return null!=this._svg&&null!=this._path||(this._svg??=$(),this._path??=K("path"),this._svg.appendChild(this._path)),this._path}_getCanvas(){return this._canvas??=document.createElement("canvas"),this._canvas}_hittestSvgPath(t,e,r,i){const s=h();g(s,t);const o={x:s[0],y:s[1],width:s[2]-s[0],height:s[3]-s[1]},n=this._getSvgPath();n.setAttribute("d",e);const a=n.getBBox(),l=a.width/o.width,c=a.height/o.height,m=this._getCanvas();m.width=a.width,m.height=a.height;const f=m.getContext("2d",{willReadFrequently:!0});f.setTransform(1,0,0,1,a.x,-a.y);const u=new Path2D(e);r?f.fill(u):(f.lineWidth=i*l,f.stroke(u));const d=this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint(),p=this.reverseTransformPt(this._searchPoint),_=(p[0]-o.x-d)*l,y=(o.height-(p[1]-o.y)-d)*c,P=2*d*l,S=2*d*c,w=f.getImageData(_,y,P,S).data;for(let h=3;h<w.length;h+=4)if(w[h]>127.5)return void(this._earlyReturn=!0)}_hitTestStroke(t,e){let r=null;if(S(t)){const e=t;r=[[[e.xmin,e.ymin],[e.xmin,e.ymax],[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin]]]}else if(y(t))r=t.rings;else{if(!P(t))return;r=t.paths}gt(this.reverseTransformPt(this._searchPoint),r,A(e,v.CIMSolidStroke.width)*this.geomUnitsPerPoint()/2+this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint())&&(this._earlyReturn=!0)}}class ft extends ht{constructor(t,e,r,i){super(e,r),this._applyAdditionalRenderProps=i,this._colorSubstitutionHelper=new M,this._ctx=t}drawSolidFill(t,e){if(!t)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else if(S(t))this._buildPath(_t(t).rings,!0);else{if(!w(t))return;console.log("CanvasDrawHelper.drawSolidFill - No implementation!")}const r=this._ctx;r.fillStyle="string"==typeof e?e:"rgba("+Math.round(e[0])+","+Math.round(e[1])+","+Math.round(e[2])+","+(e[3]??255)/255+")",r.fill("evenodd")}drawSolidStroke(t,e,r,i,s,o){if(!t||!e||0===r)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!1);else{if(!S(t))return void console.log("CanvasDrawHelper.drawSolidStroke isn't implemented!");this._buildPath(_t(t).rings,!0)}const n=this._ctx;n.strokeStyle="string"==typeof e?e:"rgba("+Math.round(e[0])+","+Math.round(e[1])+","+Math.round(e[2])+","+(e[3]??255)/255+")",n.lineWidth=Math.max(this.transformSize(r),nt),this._setCapStyle(i),this._setJoinStyle(s),n.miterLimit=o,n.stroke()}pushClipPath(t){if(this._ctx.save(),y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else{if(!S(t))return;this._buildPath(_t(t).rings,!0)}this._ctx.clip("evenodd")}popClipPath(){this._ctx.restore()}drawImage(t,e){const{colorSubstitutions:r,url:i,tintColor:s}=t,o=A(t.scaleX,1),n=this._resourceManager.getResource(i);if(null==n)return;let a=e*(n.width/n.height),l=e;e||(a=n.width,l=n.height);const h=D(i)||"src"in n&&D(n.src);let c="getFrame"in n?R(n):n;r&&(c=this._colorSubstitutionHelper.applyColorSubstitution(c,r)),this._applyAdditionalRenderProps&&!h&&s&&(c=this._colorSubstitutionHelper.tintImageData(c,s));const m=this.transformPt([0,0]),[f,u]=this.getTransformAngle(),d=this.transformSize(1),g=this._ctx;g.save(),g.setTransform({m11:o*d*f,m12:o*d*u,m21:-d*u,m22:d*f,m41:m[0],m42:m[1]}),g.drawImage(c,-a/2,-l/2,a,l),g.restore()}drawText(t,e){if(!e||0===e.length)return;this._textRasterizer||(this._textRasterizer=new U);const r=Pt(t,this.transformSize(o(1))),i=this._textRasterizer.rasterizeText(e,r);if(!i)return;const{size:s,anchorX:n,anchorY:a,canvas:l}=i,h=s[0]*(n+.5),c=s[1]*(a-.5),m=this._ctx,f=this.transformPt([0,0]),[u,d]=this.getTransformAngle(),g=1;m.save(),m.setTransform({m11:g*u,m12:g*d,m21:-g*d,m22:g*u,m41:f[0]-g*h,m42:f[1]+g*c}),m.drawImage(l,0,0),m.restore()}drawPictureFill(t,e){if(!t)return;let{colorSubstitutions:r,height:i,offsetX:s,offsetY:o,rotation:n,scaleX:a,tintColor:l,url:h}=e;const c=this._resourceManager.getResource(h);if(null==c)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else if(S(t))this._buildPath(_t(t).rings,!0);else{if(!w(t))return;console.log("CanvasDrawHelper.drawPictureFill - No implementation!")}const m=this._ctx,f=D(h)||"src"in c&&D(c.src);let u,d="getFrame"in c?R(c):c;if(r&&(d=this._colorSubstitutionHelper.applyColorSubstitution(d,r)),this._applyAdditionalRenderProps){f||l&&(d=this._colorSubstitutionHelper.tintImageData(d,l)),u=m.createPattern(d,"repeat");const t=this.transformSize(1);n||(n=0),s?s*=t:s=0,o?o*=t:o=0,i&&(i*=t);const e=i?i/c.height:1,r=a&&i?a*i/c.width:1;if(0!==n||1!==e||1!==r||0!==s||0!==o){const t=new DOMMatrix;t.rotateSelf(0,0,-n).translateSelf(s,o).scaleSelf(r,e,1),u.setTransform(t)}}else u=m.createPattern(d,"repeat");m.save(),m.fillStyle=u,m.fill("evenodd"),m.restore()}drawPictureStroke(t,r){if(!t)return;let{colorSubstitutions:i,capStyle:s,joinStyle:o,miterLimit:a,tintColor:l,url:h,width:c}=r;const m=this._resourceManager.getResource(h);if(null==m)return;let f;if(y(t))f=t.rings;else if(P(t))f=t.paths;else{if(!S(t))return w(t)?void console.log("CanvasDrawHelper.drawPictureStroke - No implementation!"):void 0;f=_t(t).rings}c||(c=m.width);const u=D(h)||"src"in m&&D(m.src);let d="getFrame"in m?R(m):m;i&&(d=this._colorSubstitutionHelper.applyColorSubstitution(d,i)),this._applyAdditionalRenderProps&&(u||l&&(d=this._colorSubstitutionHelper.tintImageData(d,l)));const g=Math.max(this.transformSize(n(c)),.5),p=g/d.width,_=this._ctx,x=_.createPattern(d,"repeat-y");let M,b;_.save(),this._setCapStyle(s),this._setJoinStyle(o),void 0!==a&&(_.miterLimit=a),_.lineWidth=g;for(let n of f)if(n=e(n),wt(n),n&&!(n.length<=1)){M=this.transformPt(n[0]);for(let t=1;t<n.length;t++){b=this.transformPt(n[t]);const e=pt(M,b),r=new DOMMatrix;r.translateSelf(0,M[1]-g/2).scaleSelf(p,p,1).rotateSelf(0,0,90-e),x.setTransform(r),_.strokeStyle=x,_.beginPath(),_.moveTo(M[0],M[1]),_.lineTo(b[0],b[1]),_.stroke(),M=b}}_.restore()}drawGradientFill(t,e){if(!t)return;let r;if(y(t))r=t.rings;else if(P(t))r=t.paths;else{if(!S(t))return void at().error("Unable to draw gradient fill");r=_t(t).rings}this._buildPath(r,!0);const{angle:s,gradientMethod:o,gradientSize:a,gradientSizeUnits:l}=e,g=v.CIMGradientFill,p=e.gradientType??g.gradientType,_=-i(s??0),w=h();for(const i of r){const t=i?i.length:0;if(t>1)for(let e=0;e<t;e++){let t=this.transformPt(i[e]);"Linear"!==o&&"Rectangular"!==o||(t=z(t,-_)),c(w,t)}}const[x,M,b,k]=w,C=this._ctx;switch(C.save(),o){case"Buffered":at().error(`Gradient method "${o}" currently unsupported.`);break;case"Linear":{const t=(M+k)/2,r="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(b-x),[i,s]="Discrete"===p?[b,b-r]:[x+r,x],o=z([i,t],_),h=z([s,t],_),c=C.createLinearGradient(o[0],o[1],h[0],h[1]);L(c,e),C.fillStyle=c,C.fill("evenodd");break}case"Circular":{const t=m(w),r=d(w)/2,i="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*r,[s,o]="Discrete"===p?[r,r-i]:[i,0],h=C.createRadialGradient(t[0],t[1],s,t[0],t[1],o);L(h,e),C.fillStyle=h,C.fill("evenodd");break}case"Rectangular":{const r=m(w),i=r[0],s=r[1],o=z(r,_),h=(r,i,s,n,a,l,h,c)=>{C.save(),this.pushClipPath(t);const m=z([a,l],_),f=z([h,c],_);C.beginPath(),C.moveTo(o[0],o[1]),C.lineTo(m[0],m[1]),C.lineTo(f[0],f[1]),C.lineTo(o[0],o[1]),C.clip();const u=z([r,i],_),d=z([s,n],_),g=C.createLinearGradient(u[0],u[1],d[0],d[1]);L(g,e),C.fillStyle=g,C.fill("evenodd"),C.restore()};let c="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(f(w)/2),[d,y]="Discrete"===p?[b,b-c]:[i+c,i];h(d,s,y,s,b,M,b,k),[d,y]="Discrete"===p?[x,x+c]:[i-c,i],h(d,s,y,s,x,k,x,M),c="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(u(w)/2);let[P,S]="Discrete"===p?[k,k-c]:[s+c,s];h(i,P,i,S,b,k,x,k),[P,S]="Discrete"===p?[M,M+c]:[s-c,s],h(i,P,i,S,x,M,b,M);break}}C.restore()}drawGradientStroke(t,r){const{capStyle:i,gradientMethod:s,gradientSize:o,gradientSizeUnits:a,joinStyle:l,miterLimit:h,width:c}=r;if(!t||0===c)return;let m;if(y(t))m=t.rings;else if(P(t))m=t.paths;else{if(!S(t))return void at().error("Unable to draw gradient stroke");m=_t(t).rings}const f=r.gradientType??v.CIMGradientStroke.gradientType,u=Math.max(this.transformSize(n(c)),.5),d=this._ctx;let g,p;d.save(),this._setCapStyle(i),this._setJoinStyle(l),void 0!==h&&(d.miterLimit=h),d.lineWidth=u;for(let _ of m){if(_=e(_),wt(_),!_||_.length<=1)continue;let t=0;g=this.transformPt(_[0]);for(let e=1;e<_.length;e++){p=this.transformPt(_[e]);const r=p[0]-g[0],i=p[1]-g[1];t+=Math.sqrt(r*r+i*i),g=p}const i="Absolute"===a?this.transformSize(n(o)):H(o,v.CIMGradientStroke.gradientSize)*("AcrossLine"===s?u:t);let l=0;g=this.transformPt(_[0]);for(let e=1;e<_.length;e++){p=this.transformPt(_[e]);const o=p[0]-g[0],n=p[1]-g[1],a=Math.sqrt(o*o+n*n);let h,c,m,y;switch(s){case"AcrossLine":{const[t,e]=z([o/a,n/a],Math.PI/2),r=u/2,s="Discrete"===f?r:i-r;h=(g[0]+p[0])/2+t*s,c=(g[1]+p[1])/2+e*s,m=h-t*i,y=c-e*i;break}case"AlongLine":{const e=o/a,r=n/a;"Discrete"===f?(h=g[0]-e*l,c=g[1]-r*l,m=h+e*i,y=c+r*i):(m=g[0]+e*(t-l),y=g[1]+r*(t-l),h=m-e*i,c=y-r*i);break}default:return at().error("Unrecognized gradient method:",s),void d.restore()}const P=d.createLinearGradient(h,c,m,y);L(P,r),d.strokeStyle=P,d.beginPath(),d.moveTo(g[0],g[1]),d.lineTo(p[0],p[1]),d.stroke(),l+=a,g=p}}d.restore()}_buildPath(t,e){const r=this._ctx;if(r.beginPath(),t)for(const i of t){const t=i?i.length:0;if(t>1){let s=this.transformPt(i[0]);r.moveTo(s[0],s[1]);for(let e=1;e<t;e++)s=this.transformPt(i[e]),r.lineTo(s[0],s[1]);e&&r.closePath()}}}_setCapStyle(t){switch(t){case I.Butt:this._ctx.lineCap="butt";break;case I.Round:this._ctx.lineCap="round";break;case I.Square:this._ctx.lineCap="square"}}_setJoinStyle(t){switch(t){case T.Bevel:this._ctx.lineJoin="bevel";break;case T.Round:this._ctx.lineJoin="round";break;case T.Miter:this._ctx.lineJoin="miter"}}}function ut(t,e,r){let i=A(t.separation,v.CIMHatchFill.separation)*r,s=A(t.rotation);if(0===i)return null;i<0&&(i=-i);let o=0;const n=.5*i;for(;o>n;)o-=i;for(;o<-n;)o+=i;const a=h();g(a,e),a[0]-=n,a[1]-=n,a[2]+=n,a[3]+=n;const l=[[a[0],a[1]],[a[0],a[3]],[a[2],a[3]],[a[2],a[1]]];for(;s>180;)s-=180;for(;s<0;)s+=180;const c=Math.cos(s*ot),m=Math.sin(s*ot),f=-i*m,u=i*c;let d,p,_,y;o=A(t.offsetX)*r*m-A(t.offsetY)*r*c,d=_=Number.MAX_VALUE,p=y=-Number.MAX_VALUE;for(const h of l){const t=h[0],e=h[1],r=c*t+m*e,i=-m*t+c*e;d=Math.min(d,r),_=Math.min(_,i),p=Math.max(p,r),y=Math.max(y,i)}_=Math.floor(_/i)*i;let P=c*d-m*_-f*o/i,S=m*d+c*_-u*o/i,w=c*p-m*_-f*o/i,x=m*p+c*_-u*o/i;const M=1+Math.round((y-_)/i),b=[];for(let h=0;h<M;h++)P+=f,S+=u,w+=f,x+=u,b.push([[P,S],[w,x]]);return{paths:b}}function dt(t,e){let r=0;for(const i of e){const e=i.length;for(let s=1;s<e;s++){const e=i[s-1],o=i[s];if(e[1]>t[1]==o[1]>t[1])continue;(o[0]-e[0])*(t[1]-e[1])-(o[1]-e[1])*(t[0]-e[0])>0?r++:r--}}return 0!==r}function gt(t,e,r){for(const i of e){const e=i.length;for(let s=1;s<e;s++){const e=i[s-1],o=i[s];let n=(o[0]-e[0])*(o[0]-e[0])+(o[1]-e[1])*(o[1]-e[1]);if(0===n)continue;n=Math.sqrt(n);const a=((o[0]-e[0])*(t[1]-e[1])-(o[1]-e[1])*(t[0]-e[0]))/n;if(Math.abs(a)<r){const i=((o[0]-e[0])*(t[0]-e[0])+(o[1]-e[1])*(t[1]-e[1]))/n;if(i>-r&&i<n+r)return!0}}}return!1}function pt(t,e){const r=e[0]-t[0],i=e[1]-t[1];return 180/Math.PI*Math.atan2(i,r)}const _t=t=>t?{spatialReference:t.spatialReference,rings:[[[t.xmin,t.ymin],[t.xmin,t.ymax],[t.xmax,t.ymax],[t.xmax,t.ymin],[t.xmin,t.ymin]]]}:null,yt=(t,e,r)=>{switch(t){case"ExtraLeading":return 1+e/r;case"Multiple":return e;case"Exact":return e/r}};function Pt(e,r=1){const i=B(e),s=E(e.fontStyleName),o=e.fontFamilyName??t,{weight:n,style:a}=s,l=r*(e.height||5),h=X(e.horizontalAlignment),c=J(e.verticalAlignment),m=N(e),f=N(e.haloSymbol),u=null!=f?r*(e.haloSize??0):0,d=O(e.symbol),g=r*(q(e.symbol)||0),p="CIMBackgroundCallout"===e.callout?.type?e.callout.backgroundSymbol:null,_=N(p),y=q(p),P=O(p);return{color:m,size:l,horizontalAlignment:h,verticalAlignment:c,font:{family:o,style:V(a),weight:W(n),decoration:i},outline:{size:g||0,color:d},halo:{size:u||0,color:f,style:a},backgroundColor:_,borderLine:null!=y&&null!=P?{size:y,color:P}:null,pixelRatio:1,premultiplyColors:!0}}const St=1e-4;function wt(t){let e,r,i,s,o,n=t[0],a=1;for(;a<t.length;)e=t[a][0]-n[0],r=t[a][1]-n[1],s=0!==e?r/e:Math.PI/2,void 0!==i&&Math.abs(s-i)<=St?(t.splice(a-1,1),n=o):(o=n,n=t[a],a++),i=s}export{ht as CIMSymbolDrawHelper,ft as CanvasDrawHelper,ct as EnvDrawHelper,mt as HittestDrawHelper,lt as Transformation,ot as cDegToRad,yt as lineGapType2LineHeight};
5
+ import{defaultFontFamily as t}from"../../core/fontUtils.js";import has from"../../core/has.js";import{clone as e}from"../../core/lang.js";import r from"../../core/Logger.js";import{deg2rad as i}from"../../core/mathUtils.js";import s from"../../core/ObjectPool.js";import{px2pt as o,pt2px as n}from"../../core/screenUtils.js";import{GeometryCursor as a}from"../../geometry/GeometryCursor.js";import{fromValues as l,create as h,expandPointInPlace as c,center as m,width as f,height as u,diagonal as d}from"../../geometry/support/aaBoundingRect.js";import{getBoundsXY as g}from"../../geometry/support/boundsUtils.js";import{polygonCentroid as p}from"../../geometry/support/centroid.js";import{isPoint as _,isPolygon as y,isPolyline as P,isExtent as S,isMultipoint as w}from"../../geometry/support/jsonUtils.js";import{SimpleEffectCursor as x}from"./CIMEffects.js";import M from"./CIMImageColorSubstitutionHelper.js";import{getEffectOperator as b,getPlacementOperator as k}from"./CIMOperators.js";import{Placement as C}from"./CIMPlacements.js";import{defaultCIMValues as v}from"./defaultCIMValues.js";import{LineCapStyle as I,LineJoinStyle as T}from"./enums.js";import{getFirstFrame as R}from"./imageUtils.js";import{rotate as z}from"./mathUtils.js";import{addColorStops as L}from"./rasterizingUtils.js";import F from"./Rect.js";import U from"./TextRasterizer.js";import{getNumericValue as A,isCIMFill as j,getSize as G,isSVGImage as D,getRelativeGradientSize as H,fromCIMFontDecoration as B,fromCIMFontStyle as E,fromCIMHorizontalAlignment as X,fromCIMVerticalAlignment as J,getFillColor as N,getStrokeColor as O,getStrokeWidth as q,getFontStyle as V,getFontWeight as W}from"./utils.js";import{destroyHiddenSvg as Y,createHiddenSvg as $,createSvgElement as K}from"../../views/2d/engine/svgUtils.js";import{glyphSize as Q,magicLabelLineHeight as Z,hittestToleranceSmallSymbol as tt,hittestSmallSymbolThreshold as et}from"../../views/2d/engine/webgl/definitions.js";import{shapeGlyphs as rt}from"../../views/2d/engine/webgl/mesh/templates/shapingUtils.js";import{roundPtToWholePixel as it,getLineWidth as st}from"../../views/2d/layers/graphics/graphicsUtils.js";const ot=Math.PI/180,nt=.5,at=()=>r.getLogger("esri.symbols.cim.CIMSymbolDrawHelper");class lt{constructor(t){this._t=t}static createIdentity(){return new lt([1,0,0,0,1,0])}clone(){const t=this._t;return new lt(t.slice())}transform(t){const e=this._t;return[e[0]*t[0]+e[1]*t[1]+e[2],e[3]*t[0]+e[4]*t[1]+e[5]]}static createScale(t,e){return new lt([t,0,0,0,e,0])}scale(t,e){const r=this._t;return r[0]*=t,r[1]*=t,r[2]*=t,r[3]*=e,r[4]*=e,r[5]*=e,this}scaleRatio(){return Math.sqrt(this._t[0]*this._t[0]+this._t[1]*this._t[1])}static createTranslate(t,e){return new lt([0,0,t,0,0,e])}translate(t,e){const r=this._t;return r[2]+=t,r[5]+=e,this}static createRotate(t){const e=Math.cos(t),r=Math.sin(t);return new lt([e,-r,0,r,e,0])}rotate(t){return lt.multiply(this,lt.createRotate(t),this)}angle(){const t=this._t[0],e=this._t[3],r=Math.sqrt(t*t+e*e);return[t/r,e/r]}static multiply(t,e,r){const i=t._t,s=e._t,o=i[0]*s[0]+i[3]*s[1],n=i[1]*s[0]+i[4]*s[1],a=i[2]*s[0]+i[5]*s[1]+s[2],l=i[0]*s[3]+i[3]*s[4],h=i[1]*s[3]+i[4]*s[4],c=i[2]*s[3]+i[5]*s[4]+s[5],m=r._t;return m[0]=o,m[1]=n,m[2]=a,m[3]=l,m[4]=h,m[5]=c,r}invert(){const t=this._t;let e=t[0]*t[4]-t[1]*t[3];if(0===e)return new lt([0,0,0,0,0,0]);e=1/e;const r=(t[1]*t[5]-t[2]*t[4])*e,i=(t[2]*t[3]-t[0]*t[5])*e,s=t[4]*e,o=-t[1]*e,n=-t[3]*e,a=t[0]*e;return new lt([s,o,r,n,a,i])}}class ht{constructor(t,e){this._resourceManager=t,this._transfos=[],this._sizeTransfos=[],this._geomUnitsPerPoint=1,this._placementPool=new s(C,void 0,void 0,100),this._earlyReturn=!1,this._mapRotation=0,this._transfos.push(e||lt.createIdentity()),this._sizeTransfos.push(e?e.scaleRatio():1)}setTransform(t,e){this._transfos=[t||lt.createIdentity()],this._sizeTransfos=[e||(t?t.scaleRatio():1)]}setGeomUnitsPerPoint(t){this._geomUnitsPerPoint=t}transformPt(t){return this._transfos[this._transfos.length-1].transform(t)}transformSize(t){return t*this._sizeTransfos[this._sizeTransfos.length-1]}reverseTransformPt(t){return this._transfos[this._transfos.length-1].invert().transform(t)}reverseTransformSize(t){return t/this._sizeTransfos[this._sizeTransfos.length-1]}reverseTransformScalar(t){return t/this._transfos[this._transfos.length-1].scaleRatio()}getTransformAngle(){return this._transfos[this._transfos.length-1].angle()}geomUnitsPerPoint(){return this.isEmbedded()?1:this._geomUnitsPerPoint}prevGeomUnitsPerPoint(){return this._transfos.length>2?1:this._geomUnitsPerPoint}isEmbedded(){return this._transfos.length>1}back(){return this._transfos[this._transfos.length-1]}push(t,e){const r=e?t.scaleRatio():1;lt.multiply(t,this.back(),t),this._transfos.push(t),this._sizeTransfos.push(this._sizeTransfos[this._sizeTransfos.length-1]*r)}pop(){this._transfos.splice(-1,1),this._sizeTransfos.splice(-1,1)}drawSymbol(t,e,r){if(t)switch(t.type){case"CIMPointSymbol":case"CIMLineSymbol":case"CIMPolygonSymbol":this.drawMultiLayerSymbol(t,e);break;case"CIMTextSymbol":this.drawTextSymbol(t,e,r)}}drawMultiLayerSymbol(t,e){if(!t||!e)return;const r=t.symbolLayers;if(!r)return;const i=t.effects;if(i&&i.length>0){const t=this.executeEffects(i,e);if(t){let e=t.next();for(;e;)this.drawSymbolLayers(r,e.asJSON()),e=t.next()}}else this.drawSymbolLayers(r,e)}executeEffects(t,e){const r=this._resourceManager.geometryEngine;let i=new x(a.fromJSONCIM(e));for(const s of t){const t=b(s);t&&(i=t.execute(i,s,this.geomUnitsPerPoint(),null,r))}return i}drawSymbolLayers(t,e){let r=t.length;for(;r--;){const i=t[r];if(!i||!1===i.enable)continue;const s=i.effects;if(s&&s.length>0){const t=this.executeEffects(s,e);if(t){let e=null;for(;(e=t.next())&&(this.drawSymbolLayer(i,e.asJSON()),!this._earlyReturn););}}else this.drawSymbolLayer(i,e);if(this._earlyReturn)return}}drawSymbolLayer(t,e){switch(t.type){case"CIMSolidFill":this.drawSolidFill(e,t.color,t.path);break;case"CIMHatchFill":this.drawHatchFill(e,t);break;case"CIMPictureFill":this.drawPictureFill(e,t);break;case"CIMGradientFill":this.drawGradientFill(e,t);break;case"CIMSolidStroke":this.drawSolidStroke(e,t.color,t.width,t.capStyle,t.joinStyle,t.miterLimit,t.path);break;case"CIMPictureStroke":this.drawPictureStroke(e,t);break;case"CIMGradientStroke":this.drawGradientStroke(e,t);break;case"CIMCharacterMarker":case"CIMPictureMarker":case"CIMVectorMarker":this.drawMarkerLayer(t,e)}}drawHatchFill(t,e){const r=ut(e,t,this.geomUnitsPerPoint());r&&(this.pushClipPath(t),this.drawMultiLayerSymbol(e.lineSymbol,r),this.popClipPath())}drawPictureFill(t,e){}drawGradientFill(t,e){}drawPictureStroke(t,e){}drawGradientStroke(t,e){}drawMarkerLayer(t,e){const r=t.markerPlacement;if(r){const i=k(r);if(i){const s="CIMMarkerPlacementInsidePolygon"===r.type||"CIMMarkerPlacementPolygonCenter"===r.type&&r.clipAtBoundary;s&&this.pushClipPath(e);const o=i.execute(a.fromJSONCIM(e),r,this.geomUnitsPerPoint(),null,this._resourceManager.geometryEngine);if(o){let e=null;for(;(e=o.next())&&(this.drawMarker(t,e),!this._earlyReturn););}s&&this.popClipPath()}}else{const r=this._placementPool.acquire();if(_(e))r.tx=e.x,r.ty=e.y,this.drawMarker(t,r);else if(y(e)){const i=p(e);i&&([r.tx,r.ty]=i,this.drawMarker(t,r))}else for(const i of e.points)if(r.tx=i[0],r.ty=i[1],this.drawMarker(t,r),this._earlyReturn)break;this._placementPool.release(r)}}drawMarker(t,e){switch(t.type){case"CIMCharacterMarker":case"CIMPictureMarker":this.drawPictureMarker(t,e);break;case"CIMVectorMarker":this.drawVectorMarker(t,e)}}drawPictureMarker(t,e){if(!t)return;const r=this._resourceManager.getResource(t.url),i=A(t.size,v.CIMPictureMarker.size);if(null==r||i<=0)return;const s=r.width,o=r.height;if(!s||!o)return;const n=s/o,a=A(t.scaleX,1),l=lt.createIdentity(),h=t.anchorPoint;if(h){let e=h.x,r=h.y;"Absolute"!==t.anchorPointUnits&&(e*=i*n*a,r*=i),l.translate(-e,-r)}let c=A(t.rotation);t.rotateClockwise&&(c=-c),this._mapRotation&&(c+=this._mapRotation),c&&l.rotate(c*ot);let m=A(t.offsetX),f=A(t.offsetY);if(m||f){if(this._mapRotation){const t=ot*this._mapRotation,e=Math.cos(t),r=Math.sin(t),i=m*r+f*e;m=m*e-f*r,f=i}l.translate(m,f)}const u=this.geomUnitsPerPoint();1!==u&&l.scale(u,u);const d=e.getAngle();d&&l.rotate(d),l.translate(e.tx,e.ty),this.push(l,!1),this.drawImage(t,i),this.pop()}drawVectorMarker(t,e){if(!t)return;const r=t.markerGraphics;if(!r)return;const i=A(t.size,v.CIMVectorMarker.size),s=t.frame,o=s?s.ymax-s.ymin:0,n=i&&o?i/o:1,a=lt.createIdentity();s&&a.translate(.5*-(s.xmax+s.xmin),.5*-(s.ymax+s.ymin));const l=t.anchorPoint;if(l){let e=l.x,r=l.y;"Absolute"!==t.anchorPointUnits?s&&(e*=s.xmax-s.xmin,r*=s.ymax-s.ymin):(e/=n,r/=n),a.translate(-e,-r)}1!==n&&a.scale(n,n);let h=A(t.rotation);t.rotateClockwise&&(h=-h),this._mapRotation&&(h+=this._mapRotation),h&&a.rotate(h*ot);let c=A(t.offsetX),m=A(t.offsetY);if(c||m){if(this._mapRotation){const t=ot*this._mapRotation,e=Math.cos(t),r=Math.sin(t),i=c*r+m*e;c=c*e-m*r,m=i}a.translate(c,m)}const f=this.geomUnitsPerPoint();1!==f&&a.scale(f,f);const u=e.getAngle();u&&a.rotate(u),a.translate(e.tx,e.ty),this.push(a,t.scaleSymbolsProportionally);for(const d of r){d?.symbol&&d.geometry||at().error("Invalid marker graphic",d);let t=d.textString;if("number"==typeof t&&(t=t.toString()),this.drawSymbol(d.symbol,d.geometry,t),this._earlyReturn)break}this.pop()}drawTextSymbol(t,e,r){if(!t)return;if(!_(e))return;if(A(t.height,v.CIMTextSymbol.height)<=0)return;const i=lt.createIdentity();let s=A(t.angle);s=-s,s&&i.rotate(s*ot);const o=A(t.offsetX),n=A(t.offsetY);(o||n)&&i.translate(o,n);const a=this.geomUnitsPerPoint();1!==a&&i.scale(a,a),i.translate(e.x,e.y),this.push(i,!1),this.drawText(t,r),this.pop()}}class ct extends ht{constructor(t,e){super(t,e),this.reset()}reset(){this._xmin=this._ymin=1/0,this._xmax=this._ymax=-1/0,this._clipCount=0}envelope(){return new F(this._xmin,this._ymin,this._xmax-this._xmin,this._ymax-this._ymin)}bounds(){return l(this._xmin,this._ymin,this._xmax,this._ymax)}drawSolidFill(t){if(t&&!(this._clipCount>0))if(y(t))this._processPath(t.rings,0);else if(P(t))this._processPath(t.paths,0);else if(S(t)){const e=_t(t);e&&this._processPath(e.rings,0)}else console.error("drawSolidFill Unexpected geometry type!")}drawSolidStroke(t,e,r){if(!t||this._clipCount>0||null==r||r<=0)return;const i=Math.max(.5*this.transformSize(A(r,v.CIMSolidStroke.width)),.5*nt);if(y(t))this._processPath(t.rings,i);else if(P(t))this._processPath(t.paths,i);else if(S(t)){const e=_t(t);e&&this._processPath(e.rings,i)}else console.error("drawSolidStroke unexpected geometry type!")}drawMarkerLayer(t,e){y(e)&&t.markerPlacement&&("CIMMarkerPlacementInsidePolygon"===t.markerPlacement.type||"CIMMarkerPlacementPolygonCenter"===t.markerPlacement.type&&t.markerPlacement.clipAtBoundary)?this._processPath(e.rings,0):super.drawMarkerLayer(t,e)}drawHatchFill(t,e){this.drawSolidFill(t)}drawPictureFill(t,e){this.drawSolidFill(t)}drawGradientFill(t,e){this.drawSolidFill(t)}drawPictureStroke(t,e){this.drawSolidStroke(t,null,e.width)}drawGradientStroke(t,e){this.drawSolidStroke(t,null,e.width)}pushClipPath(t){this.drawSolidFill(t),this._clipCount++}popClipPath(){this._clipCount--}drawImage(t,e){const{url:r}=t,i=A(t.scaleX,1);let s=i*e,o=e;const n=this._resourceManager.getResource(r);if(null!=n){const t=n.height/n.width;s=i*(e?t>1?e:e/t:n.width),o=e?t>1?e*t:e:n.height}this._merge(this.transformPt([-s/2,-o/2]),0),this._merge(this.transformPt([-s/2,o/2]),0),this._merge(this.transformPt([s/2,-o/2]),0),this._merge(this.transformPt([s/2,o/2]),0)}drawText(t,e){if(!e||0===e.length)return;this._textRasterizer||(this._textRasterizer=new U);const r=Pt(t);let[i,s]=this._textRasterizer.computeTextSize(e,r);i=o(i),s=o(s);const n=this.transformSize(1)*this.reverseTransformScalar(1);i*=n,s*=n;let a=0;switch(t.horizontalAlignment){case"Left":a=i/2;break;case"Right":a=-i/2}let l=0;switch(t.verticalAlignment){case"Bottom":l=s/2;break;case"Top":l=-s/2;break;case"Baseline":l=s/6}this._merge(this.transformPt([-i/2+a,-s/2+l]),0),this._merge(this.transformPt([-i/2+a,s/2+l]),0),this._merge(this.transformPt([i/2+a,-s/2+l]),0),this._merge(this.transformPt([i/2+a,s/2+l]),0)}_processPath(t,e){if(t)for(const r of t){const t=r?r.length:0;if(t>1){this._merge(this.transformPt(r[0]),e);for(let i=1;i<t;i++)this._merge(this.transformPt(r[i]),e)}}}_merge(t,e){t[0]-e<this._xmin&&(this._xmin=t[0]-e),t[0]+e>this._xmax&&(this._xmax=t[0]+e),t[1]-e<this._ymin&&(this._ymin=t[1]-e),t[1]+e>this._ymax&&(this._ymax=t[1]+e)}}class mt extends ht{constructor(){super(...arguments),this._searchPoint=[0,0],this._searchDistPoint=0,this._textInfo=null,this._svg=null,this._path=null,this._canvas=null}destroy(){this._svg=Y(this._svg),this._path=null,this._canvas=null}hitTest(t,e,r,i,s,a){const l=a*n(1);this.setTransform(),this.setGeomUnitsPerPoint(l),this._searchPoint=[(t[0]+t[2])/2,(t[1]+t[3])/2],this._searchDistPoint=(t[2]-t[0])/2/l,this._textInfo=i;const h=e&&("CIMPointSymbol"===e.type&&"Map"!==e.angleAlignment||"CIMTextSymbol"===e.type);if(this._mapRotation=h?s:0,!has("esri-mobile")){const t=o(tt*window.devicePixelRatio),r=o(et);!(("CIMLineSymbol"===e?.type||"CIMPolygonSymbol"===e?.type)&&e.symbolLayers?.some(j))&&"CIMMeshSymbol"!==e?.type&&(G(e)??0)<r&&(this._searchDistPoint=t)}return this._earlyReturn=!1,this.drawSymbol(e,r),this._earlyReturn}executeEffects(t,e){return"CIMGeometricEffectDashes"===t.at(-1)?.type&&(t=t.slice(0,-1)),super.executeEffects(t,e)}drawSolidFill(t,e,r){null!=r?this._hittestSvgPath(t,r,!0):this._hitTestFill(t)}drawHatchFill(t,e){this._hitTestFill(t)}drawPictureFill(t,e){this._hitTestFill(t)}drawGradientFill(t,e){this._hitTestFill(t)}drawSolidStroke(t,e,r,i,s,o,n){null!=n?this._hittestSvgPath(t,n,!1,r):this._hitTestStroke(t,r)}drawPictureStroke(t,e){this._hitTestStroke(t,e.width)}drawGradientStroke(t,e){this._hitTestStroke(t,e.width)}drawMarkerLayer(t,e){t.markerPlacement&&("CIMMarkerPlacementInsidePolygon"===t.markerPlacement.type||"CIMMarkerPlacementPolygonCenter"===t.markerPlacement.type&&t.markerPlacement.clipAtBoundary)?this._hitTestFill(e):super.drawMarkerLayer(t,e)}pushClipPath(t){}popClipPath(){}drawImage(t,e){const{url:r}=t,i=A(t.scaleX,1),s=this._resourceManager.getResource(r);if(null==s||0===s.height||0===e)return;const o=e*this.geomUnitsPerPoint(),n=o*i*(s.width/s.height),a=this.reverseTransformPt(this._searchPoint),l=this._searchDistPoint;Math.abs(a[0])<n/2+l&&Math.abs(a[1])<o/2+l&&(this._earlyReturn=!0)}drawText(t,e){const r=this._textInfo;if(!r)return;const i=r.get(t);if(!i)return;if(!i.glyphMosaicItems.glyphs.length)return;const s=it(A(t.height,v.CIMTextSymbol.height)),{lineGapType:o,lineGap:n}=t,a=o?yt(o,A(n),s):0,l="CIMBackgroundCallout"===t.callout?.type,h=rt(i.glyphMosaicItems,{scale:s/Q,angle:0,xOffset:0,yOffset:0,horizontalAlignment:t.horizontalAlignment,verticalAlignment:t.verticalAlignment,maxLineWidth:st(t.lineWidth),lineHeight:Z*Math.max(.25,Math.min(a||1,4)),decoration:t.font.decoration||"none",useCIMAngleBehavior:!0,hasBackground:l}),c=this.reverseTransformPt(this._searchPoint),m=c[0],f=c[1];for(const u of h.glyphs)if(m>u.xTopLeft&&m<u.xBottomRight&&f>-u.yBottomRight&&f<-u.yTopLeft){this._earlyReturn=!0;break}}_hitTestFill(t){let e=null;if(S(t)){const r=t;e=[[[r.xmin,r.ymin],[r.xmin,r.ymax],[r.xmax,r.ymax],[r.xmax,r.ymin],[r.xmin,r.ymin]]]}else if(y(t))e=t.rings;else{if(!P(t))return;e=t.paths}const r=this.reverseTransformPt(this._searchPoint);if(dt(r,e)&&(this._earlyReturn=!0),!this._earlyReturn){gt(r,e,this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint())&&(this._earlyReturn=!0)}}_getSvgPath(){return null!=this._svg&&null!=this._path||(this._svg??=$(),this._path??=K("path"),this._svg.appendChild(this._path)),this._path}_getCanvasContext(t,e){return this._canvas??=document.createElement("canvas"),this._canvas.width=t,this._canvas.height=e,this._canvas.getContext("2d",{willReadFrequently:!0})}_hittestSvgPath(t,e,r,i=0){const s=this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint(),o=this.reverseTransformPt(this._searchPoint),n=h();g(n,t);const a={x:n[0],y:n[1],width:n[2]-n[0],height:n[3]-n[1]},l=this._getSvgPath();l.setAttribute("d",e);const c=l.getBBox();let m=Math.max(c.width/a.width,c.height/a.height),f=1;const u=2*s*m;u<1&&(f=2/u,m*=f,c.x*=f,c.y*=f,c.width*=f,c.height*=f);const d=1+i*m/2,p=this._getCanvasContext(c.width+2*d,c.height+2*d);p.setTransform(f,0,0,f,-c.x+d,-c.y+d);const _=new Path2D(e);r?p.fill(_):(p.lineWidth=i*(m/f),p.stroke(_));const y=(a.width*m-c.width)/2,P=(a.height*m-c.height)/2,S=Math.floor((o[0]-a.x-s)*m-y+d),w=Math.floor((a.height-(o[1]-a.y)-s)*m+P+d),x=Math.ceil(2*s*m),M=Math.ceil(2*s*m),b=p.getImageData(S,w,x,M).data;for(let h=3;h<b.length;h+=4)if(b[h]>127.5)return void(this._earlyReturn=!0)}_hitTestStroke(t,e){let r=null;if(S(t)){const e=t;r=[[[e.xmin,e.ymin],[e.xmin,e.ymax],[e.xmax,e.ymax],[e.xmax,e.ymin],[e.xmin,e.ymin]]]}else if(y(t))r=t.rings;else{if(!P(t))return;r=t.paths}gt(this.reverseTransformPt(this._searchPoint),r,A(e,v.CIMSolidStroke.width)*this.geomUnitsPerPoint()/2+this.reverseTransformScalar(this._searchDistPoint)*this.prevGeomUnitsPerPoint())&&(this._earlyReturn=!0)}}class ft extends ht{constructor(t,e,r,i){super(e,r),this._applyAdditionalRenderProps=i,this._colorSubstitutionHelper=new M,this._ctx=t}drawSolidFill(t,e){if(!t)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else if(S(t))this._buildPath(_t(t).rings,!0);else{if(!w(t))return;console.log("CanvasDrawHelper.drawSolidFill - No implementation!")}const r=this._ctx;r.fillStyle="string"==typeof e?e:"rgba("+Math.round(e[0])+","+Math.round(e[1])+","+Math.round(e[2])+","+(e[3]??255)/255+")",r.fill("evenodd")}drawSolidStroke(t,e,r,i,s,o){if(!t||!e||0===r)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!1);else{if(!S(t))return void console.log("CanvasDrawHelper.drawSolidStroke isn't implemented!");this._buildPath(_t(t).rings,!0)}const n=this._ctx;n.strokeStyle="string"==typeof e?e:"rgba("+Math.round(e[0])+","+Math.round(e[1])+","+Math.round(e[2])+","+(e[3]??255)/255+")",n.lineWidth=Math.max(this.transformSize(r),nt),this._setCapStyle(i),this._setJoinStyle(s),n.miterLimit=o,n.stroke()}pushClipPath(t){if(this._ctx.save(),y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else{if(!S(t))return;this._buildPath(_t(t).rings,!0)}this._ctx.clip("evenodd")}popClipPath(){this._ctx.restore()}drawImage(t,e){const{colorSubstitutions:r,url:i,tintColor:s}=t,o=A(t.scaleX,1),n=this._resourceManager.getResource(i);if(null==n)return;let a=e*(n.width/n.height),l=e;e||(a=n.width,l=n.height);const h=D(i)||"src"in n&&D(n.src);let c="getFrame"in n?R(n):n;r&&(c=this._colorSubstitutionHelper.applyColorSubstitution(c,r)),this._applyAdditionalRenderProps&&!h&&s&&(c=this._colorSubstitutionHelper.tintImageData(c,s));const m=this.transformPt([0,0]),[f,u]=this.getTransformAngle(),d=this.transformSize(1),g=this._ctx;g.save(),g.setTransform({m11:o*d*f,m12:o*d*u,m21:-d*u,m22:d*f,m41:m[0],m42:m[1]}),g.drawImage(c,-a/2,-l/2,a,l),g.restore()}drawText(t,e){if(!e||0===e.length)return;this._textRasterizer||(this._textRasterizer=new U);const r=Pt(t,this.transformSize(o(1))),i=this._textRasterizer.rasterizeText(e,r);if(!i)return;const{size:s,anchorX:n,anchorY:a,canvas:l}=i,h=s[0]*(n+.5),c=s[1]*(a-.5),m=this._ctx,f=this.transformPt([0,0]),[u,d]=this.getTransformAngle(),g=1;m.save(),m.setTransform({m11:g*u,m12:g*d,m21:-g*d,m22:g*u,m41:f[0]-g*h,m42:f[1]+g*c}),m.drawImage(l,0,0),m.restore()}drawPictureFill(t,e){if(!t)return;let{colorSubstitutions:r,height:i,offsetX:s,offsetY:o,rotation:n,scaleX:a,tintColor:l,url:h}=e;const c=this._resourceManager.getResource(h);if(null==c)return;if(y(t))this._buildPath(t.rings,!0);else if(P(t))this._buildPath(t.paths,!0);else if(S(t))this._buildPath(_t(t).rings,!0);else{if(!w(t))return;console.log("CanvasDrawHelper.drawPictureFill - No implementation!")}const m=this._ctx,f=D(h)||"src"in c&&D(c.src);let u,d="getFrame"in c?R(c):c;if(r&&(d=this._colorSubstitutionHelper.applyColorSubstitution(d,r)),this._applyAdditionalRenderProps){f||l&&(d=this._colorSubstitutionHelper.tintImageData(d,l)),u=m.createPattern(d,"repeat");const t=this.transformSize(1);n||(n=0),s?s*=t:s=0,o?o*=t:o=0,i&&(i*=t);const e=i?i/c.height:1,r=a&&i?a*i/c.width:1;if(0!==n||1!==e||1!==r||0!==s||0!==o){const t=new DOMMatrix;t.rotateSelf(0,0,-n).translateSelf(s,o).scaleSelf(r,e,1),u.setTransform(t)}}else u=m.createPattern(d,"repeat");m.save(),m.fillStyle=u,m.fill("evenodd"),m.restore()}drawPictureStroke(t,r){if(!t)return;let{colorSubstitutions:i,capStyle:s,joinStyle:o,miterLimit:a,tintColor:l,url:h,width:c}=r;const m=this._resourceManager.getResource(h);if(null==m)return;let f;if(y(t))f=t.rings;else if(P(t))f=t.paths;else{if(!S(t))return w(t)?void console.log("CanvasDrawHelper.drawPictureStroke - No implementation!"):void 0;f=_t(t).rings}c||(c=m.width);const u=D(h)||"src"in m&&D(m.src);let d="getFrame"in m?R(m):m;i&&(d=this._colorSubstitutionHelper.applyColorSubstitution(d,i)),this._applyAdditionalRenderProps&&(u||l&&(d=this._colorSubstitutionHelper.tintImageData(d,l)));const g=Math.max(this.transformSize(n(c)),.5),p=g/d.width,_=this._ctx,x=_.createPattern(d,"repeat-y");let M,b;_.save(),this._setCapStyle(s),this._setJoinStyle(o),void 0!==a&&(_.miterLimit=a),_.lineWidth=g;for(let n of f)if(n=e(n),wt(n),n&&!(n.length<=1)){M=this.transformPt(n[0]);for(let t=1;t<n.length;t++){b=this.transformPt(n[t]);const e=pt(M,b),r=new DOMMatrix;r.translateSelf(0,M[1]-g/2).scaleSelf(p,p,1).rotateSelf(0,0,90-e),x.setTransform(r),_.strokeStyle=x,_.beginPath(),_.moveTo(M[0],M[1]),_.lineTo(b[0],b[1]),_.stroke(),M=b}}_.restore()}drawGradientFill(t,e){if(!t)return;let r;if(y(t))r=t.rings;else if(P(t))r=t.paths;else{if(!S(t))return void at().error("Unable to draw gradient fill");r=_t(t).rings}this._buildPath(r,!0);const{angle:s,gradientMethod:o,gradientSize:a,gradientSizeUnits:l}=e,g=v.CIMGradientFill,p=e.gradientType??g.gradientType,_=-i(s??0),w=h();for(const i of r){const t=i?i.length:0;if(t>1)for(let e=0;e<t;e++){let t=this.transformPt(i[e]);"Linear"!==o&&"Rectangular"!==o||(t=z(t,-_)),c(w,t)}}const[x,M,b,k]=w,C=this._ctx;switch(C.save(),o){case"Buffered":at().error(`Gradient method "${o}" currently unsupported.`);break;case"Linear":{const t=(M+k)/2,r="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(b-x),[i,s]="Discrete"===p?[b,b-r]:[x+r,x],o=z([i,t],_),h=z([s,t],_),c=C.createLinearGradient(o[0],o[1],h[0],h[1]);L(c,e),C.fillStyle=c,C.fill("evenodd");break}case"Circular":{const t=m(w),r=d(w)/2,i="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*r,[s,o]="Discrete"===p?[r,r-i]:[i,0],h=C.createRadialGradient(t[0],t[1],s,t[0],t[1],o);L(h,e),C.fillStyle=h,C.fill("evenodd");break}case"Rectangular":{const r=m(w),i=r[0],s=r[1],o=z(r,_),h=(r,i,s,n,a,l,h,c)=>{C.save(),this.pushClipPath(t);const m=z([a,l],_),f=z([h,c],_);C.beginPath(),C.moveTo(o[0],o[1]),C.lineTo(m[0],m[1]),C.lineTo(f[0],f[1]),C.lineTo(o[0],o[1]),C.clip();const u=z([r,i],_),d=z([s,n],_),g=C.createLinearGradient(u[0],u[1],d[0],d[1]);L(g,e),C.fillStyle=g,C.fill("evenodd"),C.restore()};let c="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(f(w)/2),[d,y]="Discrete"===p?[b,b-c]:[i+c,i];h(d,s,y,s,b,M,b,k),[d,y]="Discrete"===p?[x,x+c]:[i-c,i],h(d,s,y,s,x,k,x,M),c="Absolute"===l?this.transformSize(n(a)):H(a,g.gradientSize)*(u(w)/2);let[P,S]="Discrete"===p?[k,k-c]:[s+c,s];h(i,P,i,S,b,k,x,k),[P,S]="Discrete"===p?[M,M+c]:[s-c,s],h(i,P,i,S,x,M,b,M);break}}C.restore()}drawGradientStroke(t,r){const{capStyle:i,gradientMethod:s,gradientSize:o,gradientSizeUnits:a,joinStyle:l,miterLimit:h,width:c}=r;if(!t||0===c)return;let m;if(y(t))m=t.rings;else if(P(t))m=t.paths;else{if(!S(t))return void at().error("Unable to draw gradient stroke");m=_t(t).rings}const f=r.gradientType??v.CIMGradientStroke.gradientType,u=Math.max(this.transformSize(n(c)),.5),d=this._ctx;let g,p;d.save(),this._setCapStyle(i),this._setJoinStyle(l),void 0!==h&&(d.miterLimit=h),d.lineWidth=u;for(let _ of m){if(_=e(_),wt(_),!_||_.length<=1)continue;let t=0;g=this.transformPt(_[0]);for(let e=1;e<_.length;e++){p=this.transformPt(_[e]);const r=p[0]-g[0],i=p[1]-g[1];t+=Math.sqrt(r*r+i*i),g=p}const i="Absolute"===a?this.transformSize(n(o)):H(o,v.CIMGradientStroke.gradientSize)*("AcrossLine"===s?u:t);let l=0;g=this.transformPt(_[0]);for(let e=1;e<_.length;e++){p=this.transformPt(_[e]);const o=p[0]-g[0],n=p[1]-g[1],a=Math.sqrt(o*o+n*n);let h,c,m,y;switch(s){case"AcrossLine":{const[t,e]=z([o/a,n/a],Math.PI/2),r=u/2,s="Discrete"===f?r:i-r;h=(g[0]+p[0])/2+t*s,c=(g[1]+p[1])/2+e*s,m=h-t*i,y=c-e*i;break}case"AlongLine":{const e=o/a,r=n/a;"Discrete"===f?(h=g[0]-e*l,c=g[1]-r*l,m=h+e*i,y=c+r*i):(m=g[0]+e*(t-l),y=g[1]+r*(t-l),h=m-e*i,c=y-r*i);break}default:return at().error("Unrecognized gradient method:",s),void d.restore()}const P=d.createLinearGradient(h,c,m,y);L(P,r),d.strokeStyle=P,d.beginPath(),d.moveTo(g[0],g[1]),d.lineTo(p[0],p[1]),d.stroke(),l+=a,g=p}}d.restore()}_buildPath(t,e){const r=this._ctx;if(r.beginPath(),t)for(const i of t){const t=i?i.length:0;if(t>1){let s=this.transformPt(i[0]);r.moveTo(s[0],s[1]);for(let e=1;e<t;e++)s=this.transformPt(i[e]),r.lineTo(s[0],s[1]);e&&r.closePath()}}}_setCapStyle(t){switch(t){case I.Butt:this._ctx.lineCap="butt";break;case I.Round:this._ctx.lineCap="round";break;case I.Square:this._ctx.lineCap="square"}}_setJoinStyle(t){switch(t){case T.Bevel:this._ctx.lineJoin="bevel";break;case T.Round:this._ctx.lineJoin="round";break;case T.Miter:this._ctx.lineJoin="miter"}}}function ut(t,e,r){let i=A(t.separation,v.CIMHatchFill.separation)*r,s=A(t.rotation);if(0===i)return null;i<0&&(i=-i);let o=0;const n=.5*i;for(;o>n;)o-=i;for(;o<-n;)o+=i;const a=h();g(a,e),a[0]-=n,a[1]-=n,a[2]+=n,a[3]+=n;const l=[[a[0],a[1]],[a[0],a[3]],[a[2],a[3]],[a[2],a[1]]];for(;s>180;)s-=180;for(;s<0;)s+=180;const c=Math.cos(s*ot),m=Math.sin(s*ot),f=-i*m,u=i*c;let d,p,_,y;o=A(t.offsetX)*r*m-A(t.offsetY)*r*c,d=_=Number.MAX_VALUE,p=y=-Number.MAX_VALUE;for(const h of l){const t=h[0],e=h[1],r=c*t+m*e,i=-m*t+c*e;d=Math.min(d,r),_=Math.min(_,i),p=Math.max(p,r),y=Math.max(y,i)}_=Math.floor(_/i)*i;let P=c*d-m*_-f*o/i,S=m*d+c*_-u*o/i,w=c*p-m*_-f*o/i,x=m*p+c*_-u*o/i;const M=1+Math.round((y-_)/i),b=[];for(let h=0;h<M;h++)P+=f,S+=u,w+=f,x+=u,b.push([[P,S],[w,x]]);return{paths:b}}function dt(t,e){let r=0;for(const i of e){const e=i.length;for(let s=1;s<e;s++){const e=i[s-1],o=i[s];if(e[1]>t[1]==o[1]>t[1])continue;(o[0]-e[0])*(t[1]-e[1])-(o[1]-e[1])*(t[0]-e[0])>0?r++:r--}}return 0!==r}function gt(t,e,r){for(const i of e){const e=i.length;for(let s=1;s<e;s++){const e=i[s-1],o=i[s];let n=(o[0]-e[0])*(o[0]-e[0])+(o[1]-e[1])*(o[1]-e[1]);if(0===n)continue;n=Math.sqrt(n);const a=((o[0]-e[0])*(t[1]-e[1])-(o[1]-e[1])*(t[0]-e[0]))/n;if(Math.abs(a)<r){const i=((o[0]-e[0])*(t[0]-e[0])+(o[1]-e[1])*(t[1]-e[1]))/n;if(i>-r&&i<n+r)return!0}}}return!1}function pt(t,e){const r=e[0]-t[0],i=e[1]-t[1];return 180/Math.PI*Math.atan2(i,r)}const _t=t=>t?{spatialReference:t.spatialReference,rings:[[[t.xmin,t.ymin],[t.xmin,t.ymax],[t.xmax,t.ymax],[t.xmax,t.ymin],[t.xmin,t.ymin]]]}:null,yt=(t,e,r)=>{switch(t){case"ExtraLeading":return 1+e/r;case"Multiple":return e;case"Exact":return e/r}};function Pt(e,r=1){const i=B(e),s=E(e.fontStyleName),o=e.fontFamilyName??t,{weight:n,style:a}=s,l=r*(e.height||5),h=X(e.horizontalAlignment),c=J(e.verticalAlignment),m=N(e),f=N(e.haloSymbol),u=null!=f?r*(e.haloSize??0):0,d=O(e.symbol),g=r*(q(e.symbol)||0),p="CIMBackgroundCallout"===e.callout?.type?e.callout.backgroundSymbol:null,_=N(p),y=q(p),P=O(p);return{color:m,size:l,horizontalAlignment:h,verticalAlignment:c,font:{family:o,style:V(a),weight:W(n),decoration:i},outline:{size:g||0,color:d},halo:{size:u||0,color:f,style:a},backgroundColor:_,borderLine:null!=y&&null!=P?{size:y,color:P}:null,pixelRatio:1,premultiplyColors:!0}}const St=1e-4;function wt(t){let e,r,i,s,o,n=t[0],a=1;for(;a<t.length;)e=t[a][0]-n[0],r=t[a][1]-n[1],s=0!==e?r/e:Math.PI/2,void 0!==i&&Math.abs(s-i)<=St?(t.splice(a-1,1),n=o):(o=n,n=t[a],a++),i=s}export{ht as CIMSymbolDrawHelper,ft as CanvasDrawHelper,ct as EnvDrawHelper,mt as HittestDrawHelper,lt as Transformation,ot as cDegToRad,yt as lineGapType2LineHeight};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../../chunks/tslib.es6.js";import{property as r}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as o}from"../../../../../core/accessorSupport/decorators/subclass.js";import{ZEROS as t}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{ColorFormat as n}from"../../../webgl/formats.js";import i from"../../../webgl/RenderNode.js";import{alphaCutoff as s}from"../../core/shaderLibrary/util/AlphaCutoff.js";import{If as a,glsl as c}from"../../core/shaderModules/interfaces.js";import{Default3D as l}from"../../lib/DefaultVertexAttributeLocations.js";import{FramebufferBit as u,ColorAttachment as p,BlendFactor as d,SizedPixelFormat as f,PixelFormat as h,DataType as m}from"../../../../webgl/enums.js";let T=class extends i{constructor(e){super(e),this.destroyedCB=null,this.produces="final-color",this.consumes={required:["final-color"]},this.clearColor=t,this._focusedFBOType=0,this._program=new Map}destroy(){this._program.forEach((e=>e.dispose())),this._program.clear(),this.destroyedCB()}render(e){const r=e.find((({name:e})=>"final-color"===e));if(!this._focusedFBO)return r;const o=this.renderingContext;o.bindFramebuffer(r.fbo),o.setClearColor(0,0,0,0),o.clear(u.COLOR);const t=this._ensureShader(o,!1,0);return o.useProgram(t),o.bindTexture(this._focusedFBO.getTexture(),0),t.setUniform1i("colorTex",0),t.setUniform1i("inputType",this._focusedFBOType),3===this._focusedFBOType&&t.setUniform2fv("nearFar",this.camera.nearFar),o.screen.draw(),r}getDownscaledFBO(e,r,o,t,i,s){o===v.ON&&(i=e.width,s=e.height);const a=this.renderingContext,{colorTexture:c,depthStencilTexture:l}=e,h=c?.descriptor,m=this._ensureShader(a,null!=l,r),T=this.fboCache.acquire(i,s,"fbo visualizer"),g=!h?.hasMipmap&&!h?.isImmutable;g&&c?.generateMipmap(),a.useProgram(m),a.bindFramebuffer(T.fbo);let F=0;const x=[p.COLOR_ATTACHMENT0],C=null!=l;if(a.bindTexture(c,F),m.setUniform1i("colorTex",F),l){F++,a.bindTexture(l,F),m.setUniform1i("depthTex",F);const e=p.COLOR_ATTACHMENT0+F;T.acquireColor(e,n.RGBA,"depth to color"),x.push(e)}for(let u=0;u<r;u++){F++;const r=p.COLOR_ATTACHMENT0+F,o=C?1:0;a.bindTexture(e.getColorTexture(r-o),F),m.setUniform1i("colorTex"+(F-o-1),F),T.acquireColor(r,n.RGBA),x.push(r)}a.gl.drawBuffers(x);const b=a.getViewport();a.setViewport(0,0,i,s),a.setClearColor(0,0,0,0),a.clear(u.COLOR),a.setBlendingEnabled(!0),a.setBlendFunction(d.ONE,d.ONE_MINUS_SRC_ALPHA);const O="linear-depth"===t||t.includes("shadow"),_=h?.internalFormat,y=O?3:_===f.R16F||_===f.R32F||_===f.R8?1:_===f.RG8?2:_===f.RGBA16F?4:0;return m.setUniform1i("inputType",y),O&&m.setUniform2fv("nearFar",this.camera.nearFar),a.screen.draw(),a.bindFramebuffer(null),a.setViewport(b.x,b.y,b.width,b.height),o===v.ON&&(this._focusedFBO=T,this._focusedFBOType=y),g&&e.colorTexture?.clearMipmap(),T}clearFocusedFBO(){this._focusedFBO=null}getPreviewContent(e,r,o,t){if(!o)return null;const n=this.renderingContext,i=this.fboCache.acquire(e,r,"fbo visualizer");n.bindFramebuffer(i?.fbo),n.setClearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(u.COLOR),n.setBlendingEnabled(!0),n.setBlendFunction(d.ONE,d.ONE_MINUS_SRC_ALPHA),n.setViewport(0,0,e,r);const s=this._ensureShader(n,!1,0);n.useProgram(s),n.bindTexture(o.getColorTexture(t),0),s.setUniform1i("colorTex",0),s.setUniform1i("inputType",0),n.screen.draw();const a=new ImageData(new Uint8ClampedArray(e*r*4),e,r);return n.gl.readPixels(0,0,e,r,h.RGBA,m.UNSIGNED_BYTE,new Uint8Array(a.data.buffer)),n.bindFramebuffer(null),i?.release(),a}_ensureShader(e,r,o){const t={hasDepth:r,attachments:o},n=this._program.get(t);if(n)return n;const i="#version 300 es\n in vec2 position;\n out vec2 uv;\n\n void main() {\n gl_Position = vec4(position, 0.0, 1.0);\n uv = position * 0.5 + vec2(0.5);\n }",u=(e,r)=>{let o="";const t=e?2:1;for(let n=0;n<r;n++)o+=`layout(location = ${c.int(t+n)}) out vec4 fragColor${c.int(n)};\n uniform sampler2D colorTex${c.int(n)};`;return o},p=e=>{let r="";for(let o=0;o<e;o++)r+=`fragColor${c.int(o)} = texture(colorTex${c.int(o)}, uv);`;return r},d=`#version 300 es\n precision highp float;\n\n in vec2 uv;\n uniform sampler2D colorTex;\n layout(location = 0) out vec4 fragColor;\n ${a(r,"layout(location = 1) out vec4 fragDepth;\n uniform sampler2D depthTex;")}\n ${u(r,o)}\n uniform int inputType;\n uniform vec2 nearFar;\n\n // Factors to convert rgba back to float\n const vec4 RGBA_2_FLOAT_FACTORS = vec4(\n 255.0 / (256.0),\n 255.0 / (256.0 * 256.0),\n 255.0 / (256.0 * 256.0 * 256.0),\n 255.0 / (256.0 * 256.0 * 256.0 * 256.0)\n );\n\n\n float rgbaTofloat(vec4 rgba) {\n // Convert components from 0->1 back to 0->255 and then add the components together with their corresponding\n // fixed point factors, i.e. (256^1, 256^2, 256^3, 256^4)\n return dot(rgba, RGBA_2_FLOAT_FACTORS);\n }\n\n float linearDepthFromFloat(float depth) {\n depth = pow(depth, 0.2);\n return -(depth * (nearFar[1] - nearFar[0]) + nearFar[0]);\n }\n\n float linearDepthFromRGBA(vec4 depth) {\n return linearDepthFromFloat(rgbaTofloat(depth));\n }\n\n float linearDepthFromTexture(sampler2D depthTex, vec2 uv) {\n ivec2 iuv = ivec2(uv * vec2(textureSize(depthTex, 0)));\n return linearDepthFromRGBA(texelFetch(depthTex, iuv, 0));\n }\n\n void main() {\n vec4 color;\n if(inputType == 1) {\n color = vec4(vec3(texture(colorTex, uv).r), 1.0);\n } else if(inputType == 2) {\n color = vec4(texture(colorTex, uv).rg, 0.0, 1.0);\n } else if(inputType == 3) {\n float depth = 1.0 - (-linearDepthFromTexture(colorTex, uv) / (nearFar[1] - nearFar[0]));\n color = vec4(vec3(depth), depth >= 0.999 ? 0.0 : 1.0);\n } else if(inputType == 4) {\n color = texture(colorTex, uv);\n color = vec4(color.rgb / color.a, color.a);\n } else {\n color = texture(colorTex, uv);\n }\n\n\n if(color.a < ${c.float(s)})\n discard;\n else {\n fragColor = color;\n ${a(r,"float depth = 1.0 - pow(texture(depthTex, uv).r, 10.0);\n fragDepth = vec4(vec3(depth), depth < 0.000001 ? 0.0 : 1.0);")}\n ${a(o>0,p(o))}\n }\n }`;return this._program.set(t,e.programCache.acquire(i,d,l)),this._program.get(t)}};var v;e([r()],T.prototype,"destroyedCB",void 0),e([r()],T.prototype,"produces",void 0),e([r()],T.prototype,"consumes",void 0),e([r()],T.prototype,"clearColor",void 0),T=e([o("esri.views.3d.webgl-engine.effects.debug.RenderNodeVisualizerNode")],T),function(e){e[e.ON=0]="ON",e[e.OFF=1]="OFF"}(v||(v={}));export{v as FocusState,T as RenderNodeVisualizerNode};
5
+ import{_ as e}from"../../../../../chunks/tslib.es6.js";import{property as r}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as o}from"../../../../../core/accessorSupport/decorators/subclass.js";import{ZEROS as t}from"../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{RenderCategory as n}from"../../../webgl.js";import{ColorFormat as i}from"../../../webgl/formats.js";import s from"../../../webgl/RenderNode.js";import{alphaCutoff as a}from"../../core/shaderLibrary/util/AlphaCutoff.js";import{If as c,glsl as l}from"../../core/shaderModules/interfaces.js";import{Default3D as u}from"../../lib/DefaultVertexAttributeLocations.js";import{FramebufferBit as p,ColorAttachment as d,BlendFactor as f,SizedPixelFormat as h,PixelFormat as m,DataType as T}from"../../../../webgl/enums.js";let v=class extends s{constructor(e){super(e),this.destroyedCB=null,this.produces=n.FINAL,this.consumes={required:[n.FINAL]},this.clearColor=t,this._focusedFBOType=0,this._program=new Map}destroy(){this._program.forEach((e=>e.dispose())),this._program.clear(),this.destroyedCB()}render(e){const r=e.find((({name:e})=>e===n.FINAL));if(!this._focusedFBO)return r;const o=this.renderingContext;o.bindFramebuffer(r.fbo),o.setClearColor(0,0,0,0),o.clear(p.COLOR);const t=this._ensureShader(o,!1,0);return o.useProgram(t),o.bindTexture(this._focusedFBO.getTexture(),0),t.setUniform1i("colorTex",0),t.setUniform1i("inputType",this._focusedFBOType),3===this._focusedFBOType&&t.setUniform2fv("nearFar",this.camera.nearFar),o.screen.draw(),r}getDownscaledFBO(e,r,o,t,n,s){o===g.ON&&(n=e.width,s=e.height);const a=this.renderingContext,{colorTexture:c,depthStencilTexture:l}=e,u=c?.descriptor,m=this._ensureShader(a,null!=l,r),T=this.fboCache.acquire(n,s,"fbo visualizer"),v=!u?.hasMipmap&&!u?.isImmutable;v&&c?.generateMipmap(),a.useProgram(m),a.bindFramebuffer(T.fbo);let F=0;const x=[d.COLOR_ATTACHMENT0],C=null!=l;if(a.bindTexture(c,F),m.setUniform1i("colorTex",F),l){F++,a.bindTexture(l,F),m.setUniform1i("depthTex",F);const e=d.COLOR_ATTACHMENT0+F;T.acquireColor(e,i.RGBA,"depth to color"),x.push(e)}for(let p=0;p<r;p++){F++;const r=d.COLOR_ATTACHMENT0+F,o=C?1:0;a.bindTexture(e.getColorTexture(r-o),F),m.setUniform1i("colorTex"+(F-o-1),F),T.acquireColor(r,i.RGBA),x.push(r)}a.gl.drawBuffers(x);const b=a.getViewport();a.setViewport(0,0,n,s),a.setClearColor(0,0,0,0),a.clear(p.COLOR),a.setBlendingEnabled(!0),a.setBlendFunction(f.ONE,f.ONE_MINUS_SRC_ALPHA);const O="linear-depth"===t||t.includes("shadow"),_=u?.internalFormat,A=O?3:_===h.R16F||_===h.R32F||_===h.R8?1:_===h.RG8?2:_===h.RGBA16F?4:0;return m.setUniform1i("inputType",A),O&&m.setUniform2fv("nearFar",this.camera.nearFar),a.screen.draw(),a.bindFramebuffer(null),a.setViewport(b.x,b.y,b.width,b.height),o===g.ON&&(this._focusedFBO=T,this._focusedFBOType=A),v&&e.colorTexture?.clearMipmap(),T}clearFocusedFBO(){this._focusedFBO=null}getPreviewContent(e,r,o,t){if(!o)return null;const n=this.renderingContext,i=this.fboCache.acquire(e,r,"fbo visualizer");n.bindFramebuffer(i?.fbo),n.setClearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(p.COLOR),n.setBlendingEnabled(!0),n.setBlendFunction(f.ONE,f.ONE_MINUS_SRC_ALPHA),n.setViewport(0,0,e,r);const s=this._ensureShader(n,!1,0);n.useProgram(s),n.bindTexture(o.getColorTexture(t),0),s.setUniform1i("colorTex",0),s.setUniform1i("inputType",0),n.screen.draw();const a=new ImageData(new Uint8ClampedArray(e*r*4),e,r);return n.gl.readPixels(0,0,e,r,m.RGBA,T.UNSIGNED_BYTE,new Uint8Array(a.data.buffer)),n.bindFramebuffer(null),i?.release(),a}_ensureShader(e,r,o){const t={hasDepth:r,attachments:o},n=this._program.get(t);if(n)return n;const i="#version 300 es\n in vec2 position;\n out vec2 uv;\n\n void main() {\n gl_Position = vec4(position, 0.0, 1.0);\n uv = position * 0.5 + vec2(0.5);\n }",s=(e,r)=>{let o="";const t=e?2:1;for(let n=0;n<r;n++)o+=`layout(location = ${l.int(t+n)}) out vec4 fragColor${l.int(n)};\n uniform sampler2D colorTex${l.int(n)};`;return o},p=e=>{let r="";for(let o=0;o<e;o++)r+=`fragColor${l.int(o)} = texture(colorTex${l.int(o)}, uv);`;return r},d=`#version 300 es\n precision highp float;\n\n in vec2 uv;\n uniform sampler2D colorTex;\n layout(location = 0) out vec4 fragColor;\n ${c(r,"layout(location = 1) out vec4 fragDepth;\n uniform sampler2D depthTex;")}\n ${s(r,o)}\n uniform int inputType;\n uniform vec2 nearFar;\n\n // Factors to convert rgba back to float\n const vec4 RGBA_2_FLOAT_FACTORS = vec4(\n 255.0 / (256.0),\n 255.0 / (256.0 * 256.0),\n 255.0 / (256.0 * 256.0 * 256.0),\n 255.0 / (256.0 * 256.0 * 256.0 * 256.0)\n );\n\n\n float rgbaTofloat(vec4 rgba) {\n // Convert components from 0->1 back to 0->255 and then add the components together with their corresponding\n // fixed point factors, i.e. (256^1, 256^2, 256^3, 256^4)\n return dot(rgba, RGBA_2_FLOAT_FACTORS);\n }\n\n float linearDepthFromFloat(float depth) {\n depth = pow(depth, 0.2);\n return -(depth * (nearFar[1] - nearFar[0]) + nearFar[0]);\n }\n\n float linearDepthFromRGBA(vec4 depth) {\n return linearDepthFromFloat(rgbaTofloat(depth));\n }\n\n float linearDepthFromTexture(sampler2D depthTex, vec2 uv) {\n ivec2 iuv = ivec2(uv * vec2(textureSize(depthTex, 0)));\n return linearDepthFromRGBA(texelFetch(depthTex, iuv, 0));\n }\n\n void main() {\n vec4 color;\n if(inputType == 1) {\n color = vec4(vec3(texture(colorTex, uv).r), 1.0);\n } else if(inputType == 2) {\n color = vec4(texture(colorTex, uv).rg, 0.0, 1.0);\n } else if(inputType == 3) {\n float depth = 1.0 - (-linearDepthFromTexture(colorTex, uv) / (nearFar[1] - nearFar[0]));\n color = vec4(vec3(depth), depth >= 0.999 ? 0.0 : 1.0);\n } else if(inputType == 4) {\n color = texture(colorTex, uv);\n color = vec4(color.rgb / color.a, color.a);\n } else {\n color = texture(colorTex, uv);\n }\n\n\n if(color.a < ${l.float(a)})\n discard;\n else {\n fragColor = color;\n ${c(r,"float depth = 1.0 - pow(texture(depthTex, uv).r, 10.0);\n fragDepth = vec4(vec3(depth), depth < 0.000001 ? 0.0 : 1.0);")}\n ${c(o>0,p(o))}\n }\n }`;return this._program.set(t,e.programCache.acquire(i,d,u)),this._program.get(t)}};var g;e([r()],v.prototype,"destroyedCB",void 0),e([r()],v.prototype,"produces",void 0),e([r()],v.prototype,"consumes",void 0),e([r()],v.prototype,"clearColor",void 0),v=e([o("esri.views.3d.webgl-engine.effects.debug.RenderNodeVisualizerNode")],v),function(e){e[e.ON=0]="ON",e[e.OFF=1]="OFF"}(g||(g={}));export{g as FocusState,v as RenderNodeVisualizerNode};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../../chunks/tslib.es6.js";import{property as t}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as s}from"../../../../../core/accessorSupport/decorators/subclass.js";import{ColorFormat as r}from"../../../webgl/formats.js";import o from"../../../webgl/RenderNode.js";import{FocusAreaColorTechnique as i}from"./FocusAreaColorTechnique.js";import{FocusAreaMaskTechnique as a}from"./FocusAreaMaskTechnique.js";import{Default3D as n}from"../../lib/DefaultVertexAttributeLocations.js";import{Pos3 as c}from"../../lib/DefaultVertexBufferLayouts.js";import{VertexArrayObject as l}from"../../lib/VertexArrayObject.js";import{F as h}from"../../../../../chunks/FocusAreaColor.glsl.js";import{F as u}from"../../../../../chunks/FocusAreaMask.glsl.js";import{BufferObject as p}from"../../../../webgl/BufferObject.js";import{FramebufferBit as m,CompareFunction as f,Face as d,StencilOperation as g,PrimitiveType as A,Usage as _}from"../../../../webgl/enums.js";let E=class extends o{constructor(e){super(e),this.consumes={required:["final-color"]},this.produces="final-color",this.focusAreaGeometries=new Array,this._vaos=Array(),this._count=new Array,this._origins=new Array,this._colorParameters=new h,this._maskParameters=new u,e.techniques.precompile(a),e.techniques.precompile(i)}initialize(){this.setExtrudedVolume()}destroy(){this._vaos.forEach((e=>e.dispose())),this._vaos=[],this._count=[],this._origins=[]}render(e){const t=this.techniques.acquire(a),s=this.techniques.acquire(i),o=this.bindParameters,n=e.find((({name:e})=>"final-color"===e)),c=n?.getTexture(),l=o.camera,h=l.fullViewport[2],u=l.fullViewport[3],p=this.fboCache.acquire(h,u,"focusArea",r.RGBA),_=this.fboCache.acquire(h,u,this.produces);if(!t.compiled||!s.compiled||!this._vaos||this.effect===b.NONE)return this.requestRender(),t.release(),s.release(),_.release(),p.release(),n;const E=this.renderingContext;p.attachDepth(n.getAttachment(this.gl.DEPTH_STENCIL_ATTACHMENT)),E.bindFramebuffer(p.fbo),E.clear(m.COLOR|m.STENCIL),E.setViewport(0,0,h,u),E.gl.clearStencil(0),E.gl.clear(E.gl.STENCIL_BUFFER_BIT),E.setClearStencil(0);for(let r=0;r<this._vaos.length;r++){const e=this._vaos[r],s=this._count[r];e&&(this._maskParameters.origin=this._origins[r],E.bindTechnique(t,o,this._maskParameters),E.setFaceCullingEnabled(!1),E.setStencilTestEnabled(!0),E.setStencilWriteMask(255),E.setStencilFunction(f.ALWAYS,0,255),E.setStencilOpSeparate(d.FRONT,g.KEEP,g.INCR_WRAP,g.KEEP),E.setStencilOpSeparate(d.BACK,g.KEEP,g.DECR_WRAP,g.KEEP),E.setDepthWriteEnabled(!1),E.setColorMask(!1,!1,!1,!1),E.bindVAO(e),E.drawArrays(A.TRIANGLES,0,s),E.setFaceCullingEnabled(!1),E.setDepthTestEnabled(!1),E.setStencilFunction(f.NOTEQUAL,0,255),E.setStencilWriteMask(0),E.setColorMask(!0,!0,!0,!0),E.drawArrays(A.TRIANGLES,0,s))}return t.release(),E.gl.clear(E.gl.STENCIL_BUFFER_BIT),E.bindFramebuffer(_.fbo),this._colorParameters.color=c,this._colorParameters.focusArea=p.getTexture(),this._colorParameters.effect=this.effect,E.bindTechnique(s,o,this._colorParameters),E.screen.draw(),p.release(),s.release(),_.attachDepth(n.getAttachment(this.gl.DEPTH_STENCIL_ATTACHMENT)),_}setExtrudedVolume(){const e=this.focusAreaGeometries;this._vaos=[],this._count=[],this._origins=[];for(let t=0;t<e.length;t++){const s=e[t],r=new Array,o=s.indicesBottom;this._origins.push(s.origin);for(let e=0;e<o.length;e++)r.push(s.positions[3*(o[e]-1)]),r.push(s.positions[3*(o[e]-1)+1]),r.push(s.positions[3*(o[e]-1)+2]);const i=s.indicesExtruded;for(let e=0;e<i.length;e++)r.push(s.positions[3*i[e]]),r.push(s.positions[3*i[e]+1]),r.push(s.positions[3*i[e]+2]);const a=new Float32Array(r),h=new l(this.renderingContext,n,new Map([["geometry",c]]),new Map([["geometry",p.createVertex(this.renderingContext,_.STATIC_DRAW,a)]]));this._vaos?.push(h),this._count.push(o.length+i.length)}}};e([t()],E.prototype,"consumes",void 0),e([t()],E.prototype,"produces",void 0),e([t({constructOnly:!0})],E.prototype,"techniques",void 0),e([t()],E.prototype,"focusAreaGeometries",void 0),e([t()],E.prototype,"effect",void 0),E=e([s("esri.views.3d.webgl-engine.effects.focusArea.FocusAreaRenderNode")],E);class T{constructor(e,t,s,r,o){this.positions=e,this.indicesBottom=t,this.indicesExtruded=s,this.height=r,this.origin=o}}var b;!function(e){e[e.NONE=0]="NONE",e[e.BRIGHT=1]="BRIGHT",e[e.DARK=2]="DARK"}(b||(b={}));export{b as FocusAreaEffect,T as FocusAreaGeometry,E as FocusAreaRenderNode};
5
+ import{_ as e}from"../../../../../chunks/tslib.es6.js";import{property as t}from"../../../../../core/accessorSupport/decorators/property.js";import"../../../../../core/has.js";import"../../../../../core/Logger.js";import"../../../../../core/RandomLCG.js";import{subclass as s}from"../../../../../core/accessorSupport/decorators/subclass.js";import{RenderCategory as r}from"../../../webgl.js";import{ColorFormat as o}from"../../../webgl/formats.js";import i from"../../../webgl/RenderNode.js";import{FocusAreaColorTechnique as a}from"./FocusAreaColorTechnique.js";import{FocusAreaMaskTechnique as n}from"./FocusAreaMaskTechnique.js";import{Default3D as c}from"../../lib/DefaultVertexAttributeLocations.js";import{Pos3 as h}from"../../lib/DefaultVertexBufferLayouts.js";import{VertexArrayObject as l}from"../../lib/VertexArrayObject.js";import{F as u}from"../../../../../chunks/FocusAreaColor.glsl.js";import{F as p}from"../../../../../chunks/FocusAreaMask.glsl.js";import{BufferObject as m}from"../../../../webgl/BufferObject.js";import{FramebufferBit as f,CompareFunction as d,Face as g,StencilOperation as A,PrimitiveType as _,Usage as E}from"../../../../webgl/enums.js";let b=class extends i{constructor(e){super(e),this.consumes={required:[r.FINAL]},this.produces=r.FINAL,this.focusAreaGeometries=new Array,this._vaos=Array(),this._count=new Array,this._origins=new Array,this._colorParameters=new u,this._maskParameters=new p,e.techniques.precompile(n),e.techniques.precompile(a)}initialize(){this.setExtrudedVolume()}destroy(){this._vaos.forEach((e=>e.dispose())),this._vaos=[],this._count=[],this._origins=[]}render(e){const t=this.techniques.acquire(n),s=this.techniques.acquire(a),i=this.bindParameters,c=e.find((({name:e})=>e===r.FINAL)),h=c?.getTexture(),l=i.camera,u=l.fullViewport[2],p=l.fullViewport[3],m=this.fboCache.acquire(u,p,"focusArea",o.RGBA),E=this.fboCache.acquire(u,p,this.produces);if(!t.compiled||!s.compiled||!this._vaos||this.effect===C.NONE)return this.requestRender(),t.release(),s.release(),E.release(),m.release(),c;const b=this.renderingContext;m.attachDepth(c.getAttachment(this.gl.DEPTH_STENCIL_ATTACHMENT)),b.bindFramebuffer(m.fbo),b.clear(f.COLOR|f.STENCIL),b.setViewport(0,0,u,p),b.gl.clearStencil(0),b.gl.clear(b.gl.STENCIL_BUFFER_BIT),b.setClearStencil(0);for(let r=0;r<this._vaos.length;r++){const e=this._vaos[r],s=this._count[r];e&&(this._maskParameters.origin=this._origins[r],b.bindTechnique(t,i,this._maskParameters),b.setFaceCullingEnabled(!1),b.setStencilTestEnabled(!0),b.setStencilWriteMask(255),b.setStencilFunction(d.ALWAYS,0,255),b.setStencilOpSeparate(g.FRONT,A.KEEP,A.INCR_WRAP,A.KEEP),b.setStencilOpSeparate(g.BACK,A.KEEP,A.DECR_WRAP,A.KEEP),b.setDepthWriteEnabled(!1),b.setColorMask(!1,!1,!1,!1),b.bindVAO(e),b.drawArrays(_.TRIANGLES,0,s),b.setFaceCullingEnabled(!1),b.setDepthTestEnabled(!1),b.setStencilFunction(d.NOTEQUAL,0,255),b.setStencilWriteMask(0),b.setColorMask(!0,!0,!0,!0),b.drawArrays(_.TRIANGLES,0,s))}return t.release(),b.gl.clear(b.gl.STENCIL_BUFFER_BIT),b.bindFramebuffer(E.fbo),this._colorParameters.color=h,this._colorParameters.focusArea=m.getTexture(),this._colorParameters.effect=this.effect,b.bindTechnique(s,i,this._colorParameters),b.screen.draw(),m.release(),s.release(),E.attachDepth(c.getAttachment(this.gl.DEPTH_STENCIL_ATTACHMENT)),E}setExtrudedVolume(){const e=this.focusAreaGeometries;this._vaos=[],this._count=[],this._origins=[];for(let t=0;t<e.length;t++){const s=e[t],r=new Array,o=s.indicesBottom;this._origins.push(s.origin);for(let e=0;e<o.length;e++)r.push(s.positions[3*(o[e]-1)]),r.push(s.positions[3*(o[e]-1)+1]),r.push(s.positions[3*(o[e]-1)+2]);const i=s.indicesExtruded;for(let e=0;e<i.length;e++)r.push(s.positions[3*i[e]]),r.push(s.positions[3*i[e]+1]),r.push(s.positions[3*i[e]+2]);const a=new Float32Array(r),n=new l(this.renderingContext,c,new Map([["geometry",h]]),new Map([["geometry",m.createVertex(this.renderingContext,E.STATIC_DRAW,a)]]));this._vaos?.push(n),this._count.push(o.length+i.length)}}};e([t()],b.prototype,"consumes",void 0),e([t()],b.prototype,"produces",void 0),e([t({constructOnly:!0})],b.prototype,"techniques",void 0),e([t()],b.prototype,"focusAreaGeometries",void 0),e([t()],b.prototype,"effect",void 0),b=e([s("esri.views.3d.webgl-engine.effects.focusArea.FocusAreaRenderNode")],b);class T{constructor(e,t,s,r,o){this.positions=e,this.indicesBottom=t,this.indicesExtruded=s,this.height=r,this.origin=o}}var C;!function(e){e[e.NONE=0]="NONE",e[e.BRIGHT=1]="BRIGHT",e[e.DARK=2]="DARK"}(C||(C={}));export{C as FocusAreaEffect,T as FocusAreaGeometry,b as FocusAreaRenderNode};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.32/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../../chunks/tslib.es6.js";import{update as t}from"../../../../core/arrayUtils.js";import{createTask as r}from"../../../../core/asyncUtils.js";import{unitRGBAFromColor as i}from"../../../../core/colorUtils.js";import has from"../../../../core/has.js";import{removeMaybe as s,abortMaybe as a,destroyMaybe as n,releaseMaybe as h}from"../../../../core/maybe.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{watch as d,syncAndInitial as _,initial as l,sync as p}from"../../../../core/reactiveUtils.js";import{signal as u}from"../../../../core/signal.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/accessorSupport/interfaces.js";import"../../../../core/accessorSupport/tracking/Flags.js";import"../../../../core/Warning.js";import"../../../../core/Error.js";import{equals as c,invert as f,multiply as g}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as b,create as T}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{s as E}from"../../../../chunks/vec42.js";import{fromValues as A,ZEROS as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{pruneIndexArrays as R}from"../../../../geometry/support/Indices.js";import{InternalRenderCategory as S,RenderCategory as w}from"../../webgl.js";import{debugFlags as C}from"../../support/debugFlags.js";import{DepthFormat as I,ColorFormat as D}from"../../webgl/formats.js";import{FBOCache as N,defaultWebGLFBO as O}from"../core/FBOCache.js";import{RenderPassManager as y}from"../core/renderPasses/RenderPassManager.js";import{ShaderOutput as H,isColorOrColorEmission as x}from"../core/shaderLibrary/ShaderOutput.js";import{HUDRenderStyle as M}from"../core/shaderLibrary/hud/HUDRenderStyle.js";import{distanceFadeEnd as L}from"../core/shaderLibrary/shading/ScreenSpaceConstants.js";import{RenderNodes as U}from"../effects/RenderNodes.js";import{releaseTechniques as v}from"../effects/RenderPlugin.js";import{RenderPluginManager as F}from"../effects/RenderPluginManager.js";import{Blit as G}from"../effects/blit/Blit.js";import{renderHighlightBuffer as q}from"../effects/highlight/Highlight.js";import{OITBlend as V}from"../effects/transparency/OITBlend.js";import{AnimationTimer as j}from"./AnimationTimer.js";import{AnimationTimeStep as B}from"./AnimationTimeStep.js";import{RenderRequestType as Q}from"./basicInterfaces.js";import{BoundingInfo as W}from"./BoundingInfo.js";import{DepthRange as k}from"./DepthRange.js";import{depthRangeFromScene as z}from"./depthRangeUtils.js";import{MainFramebuffer as X}from"./MainFramebuffer.js";import{RenderOccludedFlag as Y}from"./Material.js";import{OITPass as K}from"./OITPass.js";import{RenderContext as J,defaultRenderOccludedMask as $}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as Z,RendererTarget as ee}from"./rendererUtils.js";import{setupFeatureDefaults as te,RenderFeature as re}from"./RenderFeature.js";import{RenderPluginInput as ie}from"./RenderPluginInput.js";import{RenderSlot as se}from"./RenderSlot.js";import{ShadowAccumulator as ae}from"./ShadowAccumulator.js";import{ShadowMap as ne,SnapshotSlot as he}from"./ShadowMap.js";import oe from"./SliceHelper.js";import{Transparency as de}from"./edgeRendering/interfaces.js";import{MergedRenderer as _e}from"../materials/renderers/MergedRenderer.js";import{RenderSceneResult as le}from"../parts/renderUtils.js";import{RendererPerformanceInfo as pe,PerformanceCategory as ue}from"../statistics/RendererPerformanceInfo.js";import{RenderState as me}from"../../../support/RenderState.js";import{PixelFormat as ce,PixelType as fe,DepthStencilAttachment as ge,FramebufferBit as be,ColorAttachment as Te}from"../../../webgl/enums.js";class Ee{constructor(e,t,r,s,a,n){this._stage=e,this._techniques=r,this._rctx=s,this._compositingHelper=a,this._requestRender=n,this._pluginsHas={hudElements:!1,water:!1},this._renderers=new Map,this.renderPassManager=new y,this._isRendering=!1,this._inGlobeView=!1,this._backgroundColor=A(0,0,0,1),this._sliceHelper=new oe,this._blit=null,this._oitblend=null,this._state=u(me.IDLE),this._highQualityTransparencyEnabled=!0,this._ssrEnabled=!1,this._hasAnimations=!1,this._animationTimestep=new B,this._loadEdgeViewTask=null,this._edgeViewCallbacks=[],this._reprojectionMatrixVersion=u(0),this._renderHiddenTransparentEdges=()=>{},this._pluginInput=new ie,this._releaseNormals=e=>{e.some((({name:e})=>"normals"===e))&&this._pluginInput.release("normals")},this._debugNeedsDepth=!1,this.fboCache=new N(s),this._renderStateFeatures=u(te(!has("disable-feature:high-quality-idle"),e.view.qualityProfile)),this._framebuffer=new X(this.fboCache),this.performanceInfo=new pe(this._rctx),this._shadowMap=new ne(this.fboCache,e.viewingMode),this._shadowAccumulator=new ae(this.fboCache,r,e,(e=>{const t=this.shadowsEnabled;this._shadowMap.enabled=!0,this._ensureBindParametersCamera(e.camera,e.contentCamera),this._plugins.prepareRender(),this._shadowMap.enabled=t}),((e,t,r)=>{const i=this._stage.view.qualitySettings.maximumPixelRatio;e.shadowMap.start(e.camera,t,r,!0,i),this._renderShadowCascades(H.Shadow,e.shadowMap),e.shadowMap.finish(),e.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(e.camera,e.contentCamera)}),n),this._renderContext=new J(this._rctx,this._shadowMap,r),this._nodes=new U(this._renderContext),this._plugins=new F({renderContext:this._renderContext,techniques:r,materials:t,requestRender:n,controller:e,fbos:this.fboCache,isFeatureEnabled:e=>this.isFeatureEnabled(e)}),this._plugins.add(this.renderPassManager),this._handles=[d((()=>this._stage.view.state.camera),(()=>n()),_),d((()=>C.EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES),(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(de.TRANSPARENT):()=>{},n()}),l),d((()=>this._stage.view.environment.background?.color),(e=>{const t=e?i(e):P;E(this._backgroundColor,t[0]*t[3],t[1]*t[3],t[2]*t[3],t[3]),n()}),_),d((()=>this._stage.view.state.camera.relativeElevation),(e=>this._inGlobeView=(e??1/0)>=L),_),d((()=>this._bindParameters.clouds.fadeFactor),(()=>this._bindParameters.fadeLighting()),p),d((()=>this._bindParameters.clouds.data?.state),(()=>n()),p),d((()=>this._stage.view.state.highlights),(e=>{this._bindParameters.highlights=e,this._updateHighlights(),n()}),l)]}destroy(){this._handles.forEach((e=>e.remove())),this._gpuTimerHandle=s(this._gpuTimerHandle),this._nodes.destroy(),this._framebuffer.dispose(),this._shadowMap.dispose(),this._shadowAccumulator.dispose(),this._loadEdgeViewTask=a(this._loadEdgeViewTask),this._edgeView=n(this._edgeView),this.renderPassManager.dispose(),this._releaseFBOs(),this._disposeOffscreenBuffers(),this.fboCache.destroy(),this._plugins.destroy(),this._renderers.clear(),this._blit=null,this._oitblend=null,W.prune(),_e.prune(),R()}get renderContext(){return this._renderContext}get _bindParameters(){return this._renderContext.bind}get _framebufferSize(){return this._framebuffer.size}updateRenderFeatures(e=null,t=!has("disable-feature:high-quality-idle")){this._renderStateFeatures.value=te(t,e),this._requestRender()}isFeatureEnabled(e,t=this._state.value){return this._renderStateFeatures.value.get(t,e)??!1}setFeatureEnabled(e,t,r){this._renderStateFeatures.mutate((i=>i.set(t,e,r))),this._requestRender()}get _highQualityTransparency(){return this._highQualityTransparencyEnabled||this.isFeatureEnabled(re.HighQualityTransparency)}get hasReflections(){return this._pluginsHas.water&&(this._ssrEnabled||this.isFeatureEnabled(re.WaterReflection))}get _hasHighlights(){return this._plugins.produces(H.Highlight,se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL,se.DRAPED_MATERIAL,se.HUD_MATERIAL,se.LABEL_MATERIAL)}get _hasHUDHighlights(){return this._plugins.produces(H.Highlight,se.HUD_MATERIAL,se.LABEL_MATERIAL)}get hasSSAO(){return(this._stage.view.qualitySettings.ambientOcclusion||this.isFeatureEnabled(re.SSAO))&&!this._inGlobeView}get hasSMAA(){return this._stage.view.qualitySettings.antialiasingEnabled||this.isFeatureEnabled(re.Antialiasing)}get fullResolutionAtmosphere(){return this._stage.view.qualitySettings.highResolutionAtmosphere||this.isFeatureEnabled(re.HighResolutionAtmosphere)}_releaseFBOs(){this._bindParameters.ssr.lastFrameColor=h(this._bindParameters.ssr.lastFrameColor),this._bindParameters.terrainDepth=h(this._bindParameters.terrainDepth),this._bindParameters.geometryDepth=h(this._bindParameters.geometryDepth)}_disposeOffscreenBuffers(){this._framebuffer.dispose(),this._disposeBindBuffers()}_disposeBindBuffers(){this._shadowMap.disposeOffscreenBuffers(),this._bindParameters.depth=h(this._bindParameters.depth),this._bindParameters.hudVisibility=h(this._bindParameters.hudVisibility)}get updating(){return null!=this._edgeView&&this._edgeView.updating||this._shadowAccumulator.running||this._plugins.updating||!this.isCameraFinal}loadEdgeView(){return this._loadEdgeViewTask||(this._loadEdgeViewTask=r((async e=>{const{EdgeView:t}=await import("./edgeRendering/EdgeView.js");o(e);const r=this._edgeView=new t({rctx:this._rctx,renderSR:this._stage.view.renderSpatialReference,viewingMode:this._stage.viewingMode,techniques:this._techniques,setNeedsRender:()=>this._requestRender(),schedule:xe(this._stage.view.resourceController)});return this._handles.push(d((()=>r.updating),(()=>this._requestRender()),p)),this._requestRender(),this._edgeViewCallbacks.forEach((e=>e(r))),this._edgeViewCallbacks.length=0,r}))),this._loadEdgeViewTask.promise}withEdgeView(e){this.loadEdgeView(),null==this._edgeView?this._edgeViewCallbacks.push(e):e(this._edgeView)}get edgeView(){return this._edgeView}get isCameraFinal(){return this._reprojectionMatrixVersion.value>=0&&c(this._bindParameters.ssr.reprojectionMatrix,b)}set _reprojectionMatrix(e){t(this._bindParameters.ssr.reprojectionMatrix,e)&&this._reprojectionMatrixVersion.value++}get shadowsEnabled(){return!!this._shadowMap?.enabled}setParameters(e){const{_shadowMap:t,_bindParameters:r}=this;if(void 0!==e.qualitySettings?.reflections&&this._ssrEnabled!==e.qualitySettings.reflections&&(this._ssrEnabled=e.qualitySettings.reflections,this._requestRender()),void 0!==e.shadowMap&&this._shadowMap.enabled!==e.shadowMap&&(this._shadowMap.enabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&t.maxCascades!==e.shadowMapMaxCascades&&(t.maxCascades=e.shadowMapMaxCascades,this._requestRender()),null!=e.environment){null!=e.environment.weather&&(this._bindParameters.weather=e.environment.weather,this._bindParameters.weatherVisible=!!e.weatherVisible);const t="virtual"!==e.environment.lighting.type;r.enableFillLights!==t&&(r.enableFillLights=t,this._requestRender())}void 0!==e.highQualityTransparency&&this._highQualityTransparencyEnabled!==e.highQualityTransparency&&(this._highQualityTransparencyEnabled=e.highQualityTransparency,this._requestRender()),void 0!==e.shadowCast&&this._shadowAccumulator.setOptions(e.shadowCast)}set slicePlane(e){this._sliceHelper.plane!==e&&(this._sliceHelper.plane=e,this._requestRender())}get plugins(){return this._plugins}getMaterialRenderer(e){return this._renderers.get(e)}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlend.result}get _oitEnabled(){return this._highQualityTransparency&&this._hasOITSupport}modify(e,t){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:r,removes:i,updates:s}=e;if(0===r.length&&0===i.length&&0===s.length)return;Z(e).forEach(((r,i)=>{if(t.done)return;let s=this._renderers.get(i);null==s&&r.adds.length>0&&(s=new _e({material:i,highlightOrderMap:this._stage.view.state.highlightOrderMap}),s.initializeRenderContext(this._plugins.context),this._plugins.add(s),this._renderers.set(i,s)),s&&(s.modify(r),0===s.numGeometries&&(this._renderers.delete(s.material),this._plugins.remove(s),s.destroy())),r.removes.forEach((t=>e.removes.removeUnordered(t))),r.adds.forEach((t=>e.adds.removeUnordered(t))),r.updates.forEach((t=>e.updates.removeUnordered(t))),t.madeProgress()})),this.updateHasFlags()}updateHasFlags(){const has=this._pluginsHas;has.hudElements=this._plugins.produces(H.Color,...Ie),has.water=this._plugins.produces(H.Normal,se.DRAPED_WATER),this._bindParameters.hasOccludees=this._plugins.hasOccludees,this._requestRender()}updateAnimation(e,t){this._animationTimer??=new j(e.camera,t),this._animationTimer.advance(e.camera,t,this._animationTimeDilation),null!=e.forcedAnimationTime&&this._animationTimer.forceTime(e.forcedAnimationTime);const r=this._hasAnimations;return this._hasAnimations=this._plugins.updateAnimation(this._animationTimer),this._hasAnimations=this._nodes.updateAnimation(this._animationTimer)||this._hasAnimations,this._hasAnimations=this.overlay?.updateAnimation(this._animationTimer)||this._hasAnimations,this._hasAnimations!==r&&(this._gpuTimerHandle=r?s(this._gpuTimerHandle):this.performanceInfo.enableGPUPerformanceInfo()),this._hasAnimations}get animationTimestep(){return this._animationTimestep.value}get _animationTimeDilation(){return this._animationTimestep.timeDilation}resetAnimation(){this._animationTimestep.clear()}tick(){this.fboCache.clean()}render(e,t,r=ee.Default,i=!1){try{return this._isRendering=!0,this._render(e,t,r,i)}catch(s){console.error(`Exception during rendering: ${s}`)}finally{this._isRendering=!1}return new le(this._pluginInput.get("final-color"),null)}_render(e,t,r=ee.Default,i){this.performanceInfo.startFrame(),this.fboCache.frameStart(),this.fboCache.interactive=r===ee.Default,this._disposeBindBuffers();const s=this._framebuffer,{camera:a,contentCamera:n,mode:o,alignPixelEnabled:d}=e;this._state.value=o,this._bindParameters.overlay=this.overlay?.render(t),this._bindParameters.overlay&&this.performanceInfo.advance(ue.OVERLAY),this._renderContext.time=t,this._bindParameters.oitPass=K.NONE,this._bindParameters.alignPixelEnabled=d,this._bindParameters.decorations=!i,this._bindParameters.mainDepth=null,this._bindParameters.viewshedEnabled=this._nodes.produces(S.VIEWSHED);const _=this._nodes.produces("magnifier-color"),l=this._nodes.produces("final-color");this._bindParameters.slicePlane=this._sliceHelper.plane,a.setGLViewport(this._rctx);const p=this._nodes.require("emissive")>0&&this._plugins.hasEmissions,u=p?H.ColorEmission:H.Color,m=s.initialize(a.fullWidth,a.fullHeight,this._backgroundColor,p);this.hasReflections?(m?.setName("last frame color"),this._bindParameters.ssr.lastFrameColor=m):m?.release(),this._ensureBindParametersCamera(a,n),this._plugins.prepareRender(),this._bindParameters.shadowHighlightsVisible=this._needsShadowHighlight&&!i;const c=this._highQualityTransparency&&this._hasTransparentTerrain,f=this._plugins.produces(H.Color,...we);this._precompilePrepasses(),this.performanceInfo.advance(ue.PREPARE);const g=this._computeDepthRange(a);this._renderShadowMap(a,this._bindParameters.lighting.mainLight.direction,g),this._ensureBindParametersCamera(a,n),this._pluginInput.set("normals",this._renderNormals()),this._renderRemainingGeometryDepth(),this._renderShadowAccumulation(g,a,n),this._ensureBindParametersSSR(t),this._precompileShaders(c,f,u),this._renderContext.output=u,s.bind(),this._bindParameters.mainDepth=s.depth.attachment;const b=this.plugins.produces(H.Color,...Se);b&&this._renderOpaqueGeometry(),s.update((e=>this._renderNodes(w.OPAQUE,e,b))),this.fboCache.debugCallback?.("opaque-color",s.color.fbo),s.update((e=>this._renderNodes(S.OPAQUE_ENVIRONMENT,e))),this.fboCache.debugCallback?.(S.OPAQUE_ENVIRONMENT,s.color.fbo),this._renderTerrainDepth(c),this._renderEdges(de.OPAQUE),s.bind(),this._renderPlugins(se.VOXEL,ue.VOXEL),this._renderHiddenTransparentEdges(),f&&(this._oitEnabled?this._renderOIT(Ae.Geometry,u):this._renderTransparentGeometry()),s.update((e=>this._renderNodes(w.TRANSPARENT,e,f))),this.fboCache.debugCallback?.("transparent-color",s.color.fbo),this._renderGeometryDepth(c),this._renderHUDVisibility(),c||this._plugins.render(this._pluginInput,se.LINE_CALLOUTS);const T=r===ee.ObjectAndLayerID?this._renderObjectAndLayerIdColor():null;this._renderEdges(de.TRANSPARENT);const E=this._hasTransparentTerrain?this._renderTransparentTerrain():null;E&&(this.performanceInfo.advance(ue.TRANSPARENT_TERRAIN),this._bindParameters.hudVisibility&&(c?this._renderLineCallouts(M.Occluded):(this._rctx.bindFramebuffer(this._bindParameters.hudVisibility?.fbo),this._compositingHelper.compositeHUD(this._bindParameters,E.getTexture())),this._renderHUD(M.Occluded,s.color,u))),this._bindParameters.cullAboveTerrain=!1,E&&(s.bind(),this._compositingHelper.compositePreMultipliedAlpha(this._bindParameters,E.getTexture()),E.release(),c&&(this._renderEdges(de.OPAQUE),f&&(this._oitEnabled?this._renderOIT(Ae.Geometry,u):this._renderTransparentGeometry(),this.performanceInfo.advance(ue.TRANSPARENT)),this._renderEdges(de.TRANSPARENT))),this._bindParameters.ssao=h(this._bindParameters.ssao),c&&this._renderLineCallouts(M.NotOccluded),this._bindParameters.terrainDepthTest=!1,this._renderTransparentEnvironment(),this._pluginInput.set("focusArea",this._renderFocusAreaGeometry()),s.update((e=>this._renderNodes(S.TRANSPARENT_ENVIRONMENT,e))),s.update((e=>this._renderNodes(S.VIEWSHED,e))),s.update((e=>this._renderNodes(S.LASERLINES,e))),s.update((e=>this._renderNodes(S.OCCLUDED,e))),this._pluginInput.set("highlights",this._renderHighlightPrepass()),s.update((e=>this._renderNodes(w.COMPOSITE,e)));const A=!(r!==ee.Default||l||_&&!i&&r===ee.Default),P=this._pluginInput.get(w.COMPOSITE),R=A?O:this.fboCache.acquire(P.fbo.width,P.fbo.height,S.ANTIALIASING),C=this._nodes.produces(S.ANTIALIASING)?this._renderNodes(S.ANTIALIASING,R):this._blitFBO(P,R,!1);let I;this._pluginInput.set(S.ANTIALIASING,C),this._hasHUDHighlights?(this._renderHUD(M.NotOccluded,C,u),I=this._renderNodes(S.HIGHLIGHTS,C)):(I=this._renderNodes(S.HIGHLIGHTS,C),this._renderHUD(M.NotOccluded,I,u));const D=this._renderNodes(S.MAGNIFIER,I);return _&&!i&&r===ee.Default&&!l&&this._blitFBO(D),l?(D.attachDepth(s.depth),this._blitFBO(this._renderNodes(w.FINAL,D)),D.detachDepth()):this._pluginInput.set(w.FINAL,D),this._pluginInput.release("highlights"),this.onPostRender&&this.onPostRender(),this._releaseFBOs(),s.releaseDepth(),this._renderContext.lastFrameCamera.copyFrom(this._bindParameters.camera),this.fboCache.frameEnd(),this.performanceInfo.finishFrame(),r!==ee.Default&&(this._releaseFBOs(),this._disposeOffscreenBuffers()),new le(this._pluginInput.get("final-color"),T)}_precompileShaders(e,t,r){if(++this._plugins.context.techniques.precompiling,this._renderContext.output=r,this._precompileOpaqueGeometry(),this._bindParameters.terrainDepthTest=e,this._bindParameters.cullAboveTerrain=e,this._renderContext.output=H.Depth,this._plugins.precompile(se.TRANSPARENT_TERRAIN),e&&(this._precompileOpaqueGeometry(),this._precompileTransparentGeometry()),this._renderContext.output=r,this._plugins.precompile(se.TRANSPARENT_TERRAIN),t&&(this._precompileTransparentGeometry(),this._hasTransparentTerrain&&(this._bindParameters.cullAboveTerrain=!1,this._precompileTransparentGeometry(),this._bindParameters.cullAboveTerrain=e)),this._needsHUDVisibility&&this._plugins.precompile(se.OCCLUSION_PIXELS),this._plugins.precompile(se.LINE_CALLOUTS),this._precompileHUD(M.Occluded),this._bindParameters.terrainDepthTest=!1,this._bindParameters.cullAboveTerrain=!1,this._nodes.precompile(S.VIEWSHED,S.LASERLINES,S.OCCLUDED),this._precompileHUD(M.NotOccluded),this._hasHighlights){const e=this._bindParameters;e.highlights.forEach(((t,r)=>{e.highlightLevel=r,this._precompileAllGeometry(H.Highlight)})),e.highlightLevel=null}this._nodes.precompile(w.COMPOSITE,S.MAGNIFIER),this._shadowAccumulator.precompile(),this._plugins.precompile(se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH),--this._plugins.context.techniques.precompiling}_updateHighlights(){const e=this._stage.view.state;this._renderers.forEach((t=>t.updateHighlights(e.highlightOrderMap)))}_renderFocusAreaGeometry(){if(this._nodes.produces("focusArea")){const e=this._framebufferSize;let t=this.fboCache.acquire(e.width,e.height,"focusArea");return t=this._nodes.render(t,this._pluginInput),this.performanceInfo.advance(ue.FOCUS_AREA_MASK),t}return null}_renderObjectAndLayerIdColor(){if(!this._nodes.produces("olid"))return null;++this._techniques.precompiling;const e=this._framebufferSize;let t=this.fboCache.acquire(e.width,e.height,"olid");return t.acquireDepth(I.DEPTH_STENCIL_TEXTURE),t=this._nodes.render(t,this._pluginInput),--this._techniques.precompiling,this.performanceInfo.advance(ue.OBJECT_AND_LAYER_ID_COLOR),t}finish(e){this._hasAnimations||this._animationTimestep.clear();const t=this.performanceInfo.gpuSamplingEnabled,r=e===Q.BACKGROUND;if(r||t){const e=r?this.performanceInfo.elapsedTime:0;let i=0;t?i=this.performanceInfo.totalGPUTimeSampler.last:this._rctx.gl.finish();const s=Math.max(e,i);this._animationTimestep.frame(s,r)}}readMainDepth(e,t){const{mainDepth:r,camera:i}=this._bindParameters;if(!r)return;const s=this.fboCache.acquire(this._framebufferSize.width,this._framebufferSize.height,"linear-depth");this._rctx.bindFramebuffer(s.fbo),i.setGLViewport(this._rctx),this._rctx.setScissorRect(e[0],e[1],e[2],e[3]),this._rctx.setScissorTestEnabled(!0),this._rctx.clearFramebuffer(P),this._compositingHelper.blitDepthToLinearDepth(this._bindParameters,r),this._rctx.setScissorTestEnabled(!1),this._rctx.setScissorRect(0,0,this._rctx.gl.canvas.width,this._rctx.gl.canvas.width),s.fbo?.readPixels(e[0],e[1],e[2],e[3],ce.RGBA,fe.UNSIGNED_BYTE,t),s.release()}readHUDVisibility(e,t,r,i,s){this._bindParameters.hudVisibility?.fbo?.readPixels(e,t,r,i,ce.RGBA,fe.UNSIGNED_BYTE,s)}readAccumulatedShadow(e){return this._shadowAccumulator.readAccumulatedShadow(e[0],e[1])}_renderEdges(e){const t=this._edgeView;if(!t?.shouldRender())return;const r=this._framebufferSize,i=this.fboCache.acquire(r.width,r.height,"edges"),s=()=>t.render(this._bindParameters,e),a=this._bindParameters.geometryDepth;this.renderToTargets(s,i,a??this._framebuffer.depth,P),this._framebuffer.bind(),this._compositingHelper.composite(this._bindParameters,i.getTexture()),i.release(),this.performanceInfo.advance(e===de.OPAQUE?ue.OPAQUE_EDGES:ue.TRANSPARENT_EDGES)}_renderShadowMap(e,t,r){if(!this.shadowsEnabled)return;const i=this._shadowMap;i.start(e,t,r,this.isFeatureEnabled(re.HighResolutionShadows),this._stage.view.qualitySettings.maximumPixelRatio),this._needsShadowHighlight?(this._renderShadowCascades(H.ShadowHighlight,this._shadowMap),i.moveSnapshot(he.Highlight),this._renderShadowCascades(H.ShadowExcludeHighlight,this._shadowMap),i.copySnapshot(he.ExcludeHighlight),this._renderShadowCascades(H.ShadowHighlight,this._shadowMap)):this._renderShadowCascades(H.Shadow),i.finish(),e.setGLViewport(this._rctx),this.performanceInfo.advance(ue.SHADOW_MAP)}_precompileShadowCascades(e){for(const t of this._shadowMap.cascades)t.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(t.camera,t.camera),this._precompileAllGeometry(e)}_renderShadowCascades(e,t=this._shadowMap){for(const r of t.cascades)r.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(r.camera,r.camera),this.renderAllGeometry(e)}get _needsDepth(){return this._plugins.consumes(H.Depth)||this._nodes.requireGeometryDepth()||this.hasReflections||this._needsShadowHighlight||this._needsShadowAccumulation||this._debugNeedsDepth}_renderRemainingGeometryDepth(){const e=this._pluginInput.get("normals");if(e){const t=this._needsDepth?e.getAttachment(ge):null;t?.retain(),this._pluginInput.set(S.SSAO,this._renderSSAO()),this._renderGeometryWithoutNormalsDepth(t)}else this._renderAllGeometryDepth()}_renderGeometryWithoutNormalsDepth(e){if(!this._needsDepth||!e)return void(this._bindParameters.depth=h(this._bindParameters.depth));const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"depth");r.attachDepth(e),e.release(),this._rctx.bindFramebuffer(r.fbo),this._rctx.clear(be.STENCIL),this._renderGeometryWithoutNormals(H.Depth),h(this._bindParameters.depth),this._bindParameters.depth=r.obtainDepthTexture(),r.release(),this.performanceInfo.advance(ue.DEPTH)}_renderAllGeometryDepth(){if(!this._needsDepth)return void(this._bindParameters.depth=h(this._bindParameters.depth));const e=this._framebufferSize,t=this.fboCache.acquire(e.width,e.height,"depth").acquireDepth(I.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(t.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this.renderAllGeometry(H.Depth),h(this._bindParameters.depth),this._bindParameters.depth=t.obtainDepthTexture(),t.release(),this.performanceInfo.advance(ue.DEPTH)}_renderTerrainDepth(e){if(this._bindParameters.terrainDepthTest=e,this._bindParameters.cullAboveTerrain=e,!e)return void(this._bindParameters.terrainDepth=h(this._bindParameters.terrainDepth));const t=this._renderContext.output;this._renderContext.output=H.Depth;const r=this._framebufferSize,i=this.fboCache.acquire(r.width,r.height,"terrain depth").acquireDepth(I.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(i.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this._renderTransparentTerrain(),h(this._bindParameters.terrainDepth),this._bindParameters.terrainDepth=i.obtainDepthTexture(),this._renderContext.output=t,i.release()}_renderGeometryDepth(e){if(!e)return void(this._bindParameters.geometryDepth=h(this._bindParameters.geometryDepth));const t=this._renderContext.output,{width:r,height:i}=this._framebufferSize,s=this.fboCache.acquire(r,i,"geometry depth").acquireDepth(I.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(s.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this._renderOpaqueAndTransparentGeometry(H.Depth),this._renderContext.output=t,h(this._bindParameters.geometryDepth),this._bindParameters.geometryDepth=s.obtainDepthTexture(),s.release()}get _needsDepthRange(){return this._shadowMap.enabled||this._needsShadowAccumulation}_computeDepthRange(e){if(!this._needsDepthRange)return k.zero;const t=z(e,this._plugins.plugins,this._stage.layers);return t.union(this._plugins.queryDepthRange(e)),t.near=Math.max(e.near,t.near),t.far=Math.min(e.far,t.far),t}get _normalsRequired(){const e=this._nodes.require("normals","final-color",w.COMPOSITE,"opaque-color","transparent-color","laserline-color");return(this.hasSSAO?1:0)+e}_precompilePrepasses(){this._normalsRequired&&this._precompileAllGeometry(H.Normal),this._needsDepth&&this._precompileAllGeometry(H.Depth),this.shadowsEnabled&&(this._needsShadowHighlight?(this._precompileShadowCascades(H.ShadowHighlight),this._precompileShadowCascades(H.ShadowExcludeHighlight),this._precompileShadowCascades(H.ShadowHighlight)):this._precompileShadowCascades(H.Shadow)),this._needsShadowAccumulation&&this._precompileAllGeometry(H.Shadow)}_renderNormals(){const e=this._normalsRequired;if(0===e)return;const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"normals",D.RGBA);r.acquireDepth(I.DEPTH_STENCIL_TEXTURE),this._rctx.bindFramebuffer(r.fbo),this._rctx.clearFramebuffer(P,!0,!0),this._renderGeometryWithNormals(H.Normal);const i=this._nodes.optional("normals","final-color",w.COMPOSITE,"opaque-color","transparent-color","viewshed-color");return r.retain(e+i-1),this.performanceInfo.advance(ue.NORMALS),r}_renderSSAO(){const e=this._pluginInput.get("normals");if(!this.hasSSAO||!e)return void e?.detachDepth();O.setName(S.SSAO);const t=this._nodes.render(O,this._pluginInput);return this._bindParameters.ssao=t,e.detachDepth(),this._pluginInput.release("normals"),this.performanceInfo.advance(ue.SSAO),t}_precompileAllGeometry(e){const t=this._renderContext.output;this._renderContext.output=e,this._precompileOpaqueGeometry(),this._precompileTransparentGeometry(),this._plugins.precompile(se.TRANSPARENT_TERRAIN),this._renderContext.output=t}renderAllGeometry(e){this._renderContext.output=e,this._renderOpaqueAndTransparentGeometry(e),this._renderTransparentTerrain()}precompileSlots(e,...t){for(const r of t)this._bindParameters.slot=r,e.precompile(this._renderContext)}precompileOccludedSlots(e,t){for(const r of t)this._renderContext.renderOccludedMask=r,this.precompileSlots(e,...Ce);this._renderContext.renderOccludedMask=$}renderSlots(e,...t){for(const r of t)this._bindParameters.slot=r,e.forAll((e=>{const t=e.acquireTechniques(this._renderContext);t&&(e.render(this._renderContext,t,this._pluginInput),v(t))}))}renderOccludedSlots(e,t){this._renderContext.renderOccludedMask=t,this.plugins.renderOccludedFlags>Y.Occlude&&this._plugins.render(this._pluginInput,se.OCCLUDED_TERRAIN),this.renderSlots(e,...Ce),this._renderContext.renderOccludedMask=$}renderHUD(e){this._bindParameters.hudRenderStyle=e,this._plugins.render(this._pluginInput,se.HUD_MATERIAL)}precompileViewshedShadowMap(){this._precompileAllGeometry(H.ViewshedShadow)}renderViewshedShadowMap(e){const{camera:t,contentCamera:r}=this._bindParameters,i=this._renderContext.output;e.setGLViewport(this._rctx),this._ensureBindParametersCamera(e,e),this.renderAllGeometry(H.ViewshedShadow),this._ensureBindParametersCamera(t,r),this._bindParameters.camera.setGLViewport(this._rctx),this._renderContext.output=i}_renderOpaqueAndTransparentGeometry(e){this._renderContext.output=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderGeometryWithNormals(e){this._renderContext.output=e,this._plugins.render(this._pluginInput,...Pe),this._renderTransparentTerrain()}_renderGeometryWithoutNormals(e){this._renderContext.output=e,this._plugins.render(this._pluginInput,...Re)}_precompileOpaqueGeometry(){this._plugins.precompile(...Se)}_renderOpaqueGeometry(){this._plugins.render(this._pluginInput,...Se)}_renderTransparentGeometry(){this._plugins.render(this._pluginInput,...we)}get _hasTransparentTerrain(){return this._plugins.produces(H.Color,se.TRANSPARENT_TERRAIN)}_renderTransparentTerrain(){const e=()=>this._plugins.render(this._pluginInput,se.TRANSPARENT_TERRAIN);if(!x(this._renderContext.output))return void e();const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"transparent terrain");return this.renderToTargets(e,r,this._framebuffer.depth,P),r}get _needsHUDVisibility(){return this._plugins.produces(this._renderContext.output,se.OCCLUSION_PIXELS)}_renderHUDVisibility(){if(!this._needsHUDVisibility)return void(this._bindParameters.hudVisibility=h(this._bindParameters.hudVisibility));const{width:e,height:t}=this._framebufferSize;let r=this._bindParameters.hudVisibility;r?.fbo?.width===e&&r?.fbo?.height===t||(r?.release(),r=this.fboCache.acquire(e,t,"hud visibility",D.RGBA4),this._bindParameters.hudVisibility=r);const i=this._bindParameters.geometryDepth;r.attachDepth(i||this._framebuffer.depth),this._rctx.bindFramebuffer(r.fbo),this._rctx.clearFramebuffer([0,1,0,1]),this._plugins.render(this._pluginInput,se.OCCLUSION_PIXELS),r.detachDepth(),this._framebuffer.bind(),this.performanceInfo.advance(ue.HUD_VISIBILITY)}_renderLineCallouts(e){if(this._bindParameters.hudRenderStyle=e,e===M.Occluded){const e=()=>this._plugins.render(this._pluginInput,se.LINE_CALLOUTS),t=this._framebufferSize,r=this.fboCache.acquireDepth(I.DEPTH16_BUFFER,t.width,t.height,"line callouts");this.renderToTargets(e,this._framebuffer.color,r,void 0,!0,!0),r.release()}else this._plugins.render(this._pluginInput,se.LINE_CALLOUTS)}_precompileHUD(e){if(this._precompileHUDOutput(e),this._hasHighlights){const t=this._renderContext.output;this._renderContext.output=H.Highlight,this._precompileHUDOutput(e),this._renderContext.output=t}}_precompileHUDOutput(e){const t=this._bindParameters.hudRenderStyle;this._bindParameters.hudRenderStyle=e,this._oitEnabled&&x(this._renderContext.output)?(this._bindParameters.oitPass=K.ColorAlpha,this._plugins.precompile(...Ie),this._bindParameters.oitPass=K.FrontFace,this._plugins.precompile(...Ie),this._bindParameters.oitPass=K.NONE):this._plugins.precompile(...Ie),this._bindParameters.hudRenderStyle=t}_renderHUD(e,t,r){if(this._pluginsHas.hudElements){if(this._oitEnabled){const i=this._renderOIT(Ae.HUD,r,e);this._rctx.bindFramebuffer(t.fbo),this._compositingHelper.compositePreMultipliedAlpha(this._bindParameters,i.getTexture()),i.release()}else if(this._renderContext.output=r,e===M.Occluded){const t=()=>this._renderHUDElements(e),r=this._framebufferSize,i=this.fboCache.acquireDepth(I.DEPTH16_BUFFER,r.width,r.height,"hud");this.renderToTargets(t,this._framebuffer.color,i,void 0,!0,!0),i.release()}else t.acquireDepth(I.DEPTH16_BUFFER),this._rctx.bindFramebuffer(t.fbo),this._renderHUDElements(e),t.detachDepth();this.performanceInfo.advance(e===M.Occluded?ue.HUD_OCCLUDED:ue.HUD)}}_renderHUDElements(e){this._bindParameters.hudRenderStyle=e,this._plugins.render(this._pluginInput,...Ie)}get _needsShadowHighlight(){return this.shadowsEnabled&&this._plugins.produces(H.ShadowHighlight,se.OPAQUE_MATERIAL)}_renderHighlightPrepass(){if(!this._hasHighlights)return;const{fboCache:e,_rctx:t,_bindParameters:r}=this,i=this._framebufferSize,s=e.acquire(i.width,i.height,"highlights",D.RG);return s.acquireDepth(I.DEPTH_STENCIL_TEXTURE),t.bindFramebuffer(s.fbo),t.clearFramebuffer(P,!0),this._renderContext.output=H.Highlight,t.bindFramebuffer(s.fbo),q(t,e,i,r,(()=>this._renderHighlightGeometries()),0),this.performanceInfo.advance(ue.HIGHLIGHTS),s}_renderHighlightGeometries(){const e=0===this._bindParameters.highlightLevel?Ne:De;this._plugins.render(this._pluginInput,...e),this._rctx.clear(be.DEPTH),this._renderHUDElements(M.Both)}get _needsShadowAccumulation(){return this._shadowAccumulator.isAccumulating}_renderShadowAccumulation(e,t,r){this._needsShadowAccumulation&&this._bindParameters.depth&&this._shadowAccumulator.renderAccumulation(this._bindParameters.depth,e,t,r)&&this.performanceInfo.advance(ue.ACCUMULATED_SHADOWS)}_precompileTransparentGeometry(){this._oitEnabled&&x(this._renderContext.output)?(this._bindParameters.oitPass=K.ColorAlpha,this._plugins.precompile(...we),this._bindParameters.oitPass=K.FrontFace,this._plugins.precompile(...we),this._bindParameters.oitPass=K.NONE):this._plugins.precompile(...we)}_renderOIT(e,t,r=M.Both){const i=e===Ae.HUD,s=this._framebufferSize,a=i?this.fboCache.acquire(s.width,s.height,"oit hud composite"):null,n=i?()=>this._renderHUDElements(r):()=>this._renderTransparentGeometry(),h=this._bindParameters,o=this._renderContext.output;this._renderContext.output=t,h.oitPass=K.ColorAlpha;const d=a?"oit hud color alpha":"oit color alpha",_=this.fboCache.acquire(s.width,s.height,d,D.RGBA16F),l=t===H.ColorEmission;_.acquireColor(Te.COLOR_ATTACHMENT1,D.R16F),a||_.attachDepth(this._framebuffer.depth),this._rctx.bindFramebuffer(_.fbo),this._rctx.clearFramebuffer([0,0,0,1]),n(),_.detachDepth(),h.oitPass=K.FrontFace;const p=this.fboCache.acquire(s.width,s.height,a?"oit hud front":"oit front");return a?p.acquireDepth(I.DEPTH16_BUFFER):p.attachDepth(this._framebuffer.depth),this._rctx.bindFramebuffer(p.fbo),this._rctx.clearFramebuffer(P,!!a),n(),p.detachDepth(),h.oitPass=K.NONE,a?(this._rctx.bindFramebuffer(a.fbo),this._rctx.setClearColor(0,0,0,1e-13),this._rctx.clear(be.COLOR)):this._framebuffer.bind(),this._oitblend??=new V(this._techniques),this._oitblend.blend(this._rctx,_,p,h,l),a?.detachDepth(),p.release(),_.release(),this._renderContext.output=o,a}_renderTransparentEnvironment(){this._shadowAccumulator.render(this._bindParameters),this.performanceInfo.advance(ue.APPLY_ACCUMULATED_SHADOWS),this._framebuffer.bind(),this._plugins.render(this._pluginInput,se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH),this.performanceInfo.advance(ue.TRANSPARENT_MATERIAL_WITHOUT_DEPTH)}_renderPlugins(e,t){this._plugins.produces(this._renderContext.output,e)&&(this._plugins.render(this._pluginInput,e),this.performanceInfo.advance(t))}_renderNodes(e,t,r=!1){if(t.setName(e),this._pluginInput.set(e,t),!this._nodes.produces(e))return r&&this.performanceInfo.advance(e),t;const i=this._nodes.render(t,this._pluginInput,this._releaseNormals);return this.performanceInfo.advance(e),i}_blitFBO(e,t=O,r=!0){return this._blit??=new G(this._techniques),this._blit.blit(this._rctx,e,t,this._bindParameters),this._pluginInput.set(e.name,t),r&&e.release(),t}_ensureBindParametersCamera(e,t){this._bindParameters.camera=e,this._bindParameters.contentCamera=t}_ensureBindParametersSSR(e){if(this._bindParameters.ssr.lastFrameColor){null==this._ssrEnableTime&&(this._ssrEnableTime=e),this._renderContext.lastFrameCamera.equals(this._bindParameters.camera)?this._reprojectionMatrix=b:(f(ye,this._bindParameters.camera.viewMatrix),f(Oe,this._bindParameters.camera.projectionMatrix),g(He,ye,Oe),g(He,this._renderContext.lastFrameCamera.viewMatrix,He),g(He,this._renderContext.lastFrameCamera.projectionMatrix,He),this._reprojectionMatrix=He);const t=this._stage.view.qualitySettings.fadeDuration;this._bindParameters.ssr.fadeFactor=t>0?Math.min(t,e-this._ssrEnableTime)/t:1,this._bindParameters.ssr.fadeFactor<1&&this._requestRender()}else this._reprojectionMatrix=b,this._ssrEnableTime=null}addRenderNode(e){this._nodes.add(e),this._requestRender()}removeRenderNode(e){this._nodes.remove(e),this._requestRender()}updateLighting(e,t,r,i){this._bindParameters.updateLighting(e,t,r,i),this._requestRender(Q.UPDATE)}get usedMemory(){return{fbos:this.fboCache.usedMemory,plugins:this._plugins.usedMemory,edges:this.edgeView?.usedMemory??0}}renderToTargets(e,t,r,i,s=!1,a=!1){t.attachDepth(r),this._rctx.bindFramebuffer(t.fbo),this._rctx.clearFramebuffer(i,s,a),e(),t.detachDepth()}get test(){}}var Ae;e([m({readOnly:!0})],Ee.prototype,"fullResolutionAtmosphere",null),e([m()],Ee.prototype,"_edgeView",void 0),e([m()],Ee.prototype,"updating",null),function(e){e[e.Geometry=0]="Geometry",e[e.HUD=1]="HUD"}(Ae||(Ae={}));const Pe=[se.INTEGRATED_MESH,se.OPAQUE_TERRAIN,se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL],Re=[se.OPAQUE_MATERIAL_WITHOUT_NORMALS,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS],Se=[se.INTEGRATED_MESH,se.OPAQUE_TERRAIN,se.OPAQUE_MATERIAL,se.OPAQUE_MATERIAL_WITHOUT_NORMALS],we=[se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS],Ce=[se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH],Ie=[se.LINE_CALLOUTS_HUD_DEPTH,se.HUD_MATERIAL,se.LABEL_MATERIAL],De=[se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS,se.OPAQUE_MATERIAL,se.OPAQUE_MATERIAL_WITHOUT_NORMALS],Ne=[...De,se.TRANSPARENT_TERRAIN,se.INTEGRATED_MESH,se.OPAQUE_TERRAIN],Oe=T(),ye=T(),He=T();function xe(e){return t=>e.immediate.schedule(t)}export{Ee as Renderer};
5
+ import{_ as e}from"../../../../chunks/tslib.es6.js";import{update as t}from"../../../../core/arrayUtils.js";import{createTask as r}from"../../../../core/asyncUtils.js";import{unitRGBAFromColor as i}from"../../../../core/colorUtils.js";import has from"../../../../core/has.js";import{removeMaybe as s,abortMaybe as a,destroyMaybe as n,releaseMaybe as h}from"../../../../core/maybe.js";import{throwIfAborted as o}from"../../../../core/promiseUtils.js";import{watch as d,syncAndInitial as _,initial as l,sync as p}from"../../../../core/reactiveUtils.js";import{signal as u}from"../../../../core/signal.js";import{property as m}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/Logger.js";import"../../../../core/accessorSupport/interfaces.js";import"../../../../core/accessorSupport/tracking/Flags.js";import"../../../../core/Warning.js";import"../../../../core/Error.js";import{equals as c,invert as g,multiply as f}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as b,create as T}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{s as A}from"../../../../chunks/vec42.js";import{fromValues as E,ZEROS as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{pruneIndexArrays as R}from"../../../../geometry/support/Indices.js";import{RenderCategory as S,InternalRenderCategory as I}from"../../webgl.js";import{debugFlags as w}from"../../support/debugFlags.js";import{DepthFormat as C,ColorFormat as D}from"../../webgl/formats.js";import{FBOCache as N,defaultWebGLFBO as O}from"../core/FBOCache.js";import{RenderPassManager as y}from"../core/renderPasses/RenderPassManager.js";import{ShaderOutput as H,isColorOrColorEmission as x}from"../core/shaderLibrary/ShaderOutput.js";import{HUDRenderStyle as L}from"../core/shaderLibrary/hud/HUDRenderStyle.js";import{distanceFadeEnd as M}from"../core/shaderLibrary/shading/ScreenSpaceConstants.js";import{RenderNodes as v}from"../effects/RenderNodes.js";import{releaseTechniques as U}from"../effects/RenderPlugin.js";import{RenderPluginManager as F}from"../effects/RenderPluginManager.js";import{Blit as G}from"../effects/blit/Blit.js";import{renderHighlightBuffer as q}from"../effects/highlight/Highlight.js";import{OITBlend as V}from"../effects/transparency/OITBlend.js";import{AnimationTimer as j}from"./AnimationTimer.js";import{AnimationTimeStep as B}from"./AnimationTimeStep.js";import{RenderRequestType as Q}from"./basicInterfaces.js";import{BoundingInfo as W}from"./BoundingInfo.js";import{DepthRange as k}from"./DepthRange.js";import{depthRangeFromScene as z}from"./depthRangeUtils.js";import{MainFramebuffer as X}from"./MainFramebuffer.js";import{RenderOccludedFlag as Y}from"./Material.js";import{OITPass as K}from"./OITPass.js";import{RenderContext as J,defaultRenderOccludedMask as $}from"./RenderContext.js";import{splitRenderGeometryChangeSetByMaterial as Z,RendererTarget as ee}from"./rendererUtils.js";import{setupFeatureDefaults as te,RenderFeature as re}from"./RenderFeature.js";import{RenderPluginInput as ie}from"./RenderPluginInput.js";import{RenderSlot as se}from"./RenderSlot.js";import{ShadowAccumulator as ae}from"./ShadowAccumulator.js";import{ShadowMap as ne,SnapshotSlot as he}from"./ShadowMap.js";import oe from"./SliceHelper.js";import{Transparency as de}from"./edgeRendering/interfaces.js";import{MergedRenderer as _e}from"../materials/renderers/MergedRenderer.js";import{RenderSceneResult as le}from"../parts/renderUtils.js";import{RendererPerformanceInfo as pe,PerformanceCategory as ue}from"../statistics/RendererPerformanceInfo.js";import{RenderState as me}from"../../../support/RenderState.js";import{PixelFormat as ce,PixelType as ge,DepthStencilAttachment as fe,FramebufferBit as be,ColorAttachment as Te}from"../../../webgl/enums.js";class Ae{constructor(e,t,r,s,a,n){this._stage=e,this._techniques=r,this._rctx=s,this._compositingHelper=a,this._requestRender=n,this._pluginsHas={hudElements:!1,water:!1},this._renderers=new Map,this.renderPassManager=new y,this._isRendering=!1,this._inGlobeView=!1,this._backgroundColor=E(0,0,0,1),this._sliceHelper=new oe,this._blit=null,this._oitblend=null,this._state=u(me.IDLE),this._highQualityTransparencyEnabled=!0,this._ssrEnabled=!1,this._hasAnimations=!1,this._animationTimestep=new B,this._loadEdgeViewTask=null,this._edgeViewCallbacks=[],this._reprojectionMatrixVersion=u(0),this._renderHiddenTransparentEdges=()=>{},this._pluginInput=new ie,this._releaseNormals=e=>{e.some((({name:e})=>"normals"===e))&&this._pluginInput.release("normals")},this._debugNeedsDepth=!1,this.fboCache=new N(s),this._renderStateFeatures=u(te(!has("disable-feature:high-quality-idle"),e.view.qualityProfile)),this._framebuffer=new X(this.fboCache),this.performanceInfo=new pe(this._rctx),this._shadowMap=new ne(this.fboCache,e.viewingMode),this._shadowAccumulator=new ae(this.fboCache,r,e,(e=>{const t=this.shadowsEnabled;this._shadowMap.enabled=!0,this._ensureBindParametersCamera(e.camera,e.contentCamera),this._plugins.prepareRender(),this._shadowMap.enabled=t}),((e,t,r)=>{const i=this._stage.view.qualitySettings.maximumPixelRatio;e.shadowMap.start(e.camera,t,r,!0,i),this._renderShadowCascades(H.Shadow,e.shadowMap),e.shadowMap.finish(),e.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(e.camera,e.contentCamera)}),n),this._renderContext=new J(this._rctx,this._shadowMap,r),this._nodes=new v(this._renderContext),this._plugins=new F({renderContext:this._renderContext,techniques:r,materials:t,requestRender:n,controller:e,fbos:this.fboCache,isFeatureEnabled:e=>this.isFeatureEnabled(e)}),this._plugins.add(this.renderPassManager),this._handles=[d((()=>this._stage.view.state.camera),(()=>n()),_),d((()=>w.EDGES_SHOW_HIDDEN_TRANSPARENT_EDGES),(e=>{this._renderHiddenTransparentEdges=e?()=>this._renderEdges(de.TRANSPARENT):()=>{},n()}),l),d((()=>this._stage.view.environment.background?.color),(e=>{const t=e?i(e):P;A(this._backgroundColor,t[0]*t[3],t[1]*t[3],t[2]*t[3],t[3]),n()}),_),d((()=>this._stage.view.state.camera.relativeElevation),(e=>this._inGlobeView=(e??1/0)>=M),_),d((()=>this._bindParameters.clouds.fadeFactor),(()=>this._bindParameters.fadeLighting()),p),d((()=>this._bindParameters.clouds.data?.state),(()=>n()),p),d((()=>this._stage.view.state.highlights),(e=>{this._bindParameters.highlights=e,this._updateHighlights(),n()}),l)]}destroy(){this._handles.forEach((e=>e.remove())),this._gpuTimerHandle=s(this._gpuTimerHandle),this._nodes.destroy(),this._framebuffer.dispose(),this._shadowMap.dispose(),this._shadowAccumulator.dispose(),this._loadEdgeViewTask=a(this._loadEdgeViewTask),this._edgeView=n(this._edgeView),this.renderPassManager.dispose(),this._releaseFBOs(),this._disposeOffscreenBuffers(),this.fboCache.destroy(),this._plugins.destroy(),this._renderers.clear(),this._blit=null,this._oitblend=null,W.prune(),_e.prune(),R()}get renderContext(){return this._renderContext}get _bindParameters(){return this._renderContext.bind}get _framebufferSize(){return this._framebuffer.size}updateRenderFeatures(e=null,t=!has("disable-feature:high-quality-idle")){this._renderStateFeatures.value=te(t,e),this._requestRender()}isFeatureEnabled(e,t=this._state.value){return this._renderStateFeatures.value.get(t,e)??!1}setFeatureEnabled(e,t,r){this._renderStateFeatures.mutate((i=>i.set(t,e,r))),this._requestRender()}get _highQualityTransparency(){return this._highQualityTransparencyEnabled||this.isFeatureEnabled(re.HighQualityTransparency)}get hasReflections(){return this._pluginsHas.water&&(this._ssrEnabled||this.isFeatureEnabled(re.WaterReflection))}get _hasHighlights(){return this._plugins.produces(H.Highlight,se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL,se.DRAPED_MATERIAL,se.HUD_MATERIAL,se.LABEL_MATERIAL)}get _hasHUDHighlights(){return this._plugins.produces(H.Highlight,se.HUD_MATERIAL,se.LABEL_MATERIAL)}get hasSSAO(){return(this._stage.view.qualitySettings.ambientOcclusion||this.isFeatureEnabled(re.SSAO))&&!this._inGlobeView}get hasSMAA(){return this._stage.view.qualitySettings.antialiasingEnabled||this.isFeatureEnabled(re.Antialiasing)}get fullResolutionAtmosphere(){return this._stage.view.qualitySettings.highResolutionAtmosphere||this.isFeatureEnabled(re.HighResolutionAtmosphere)}_releaseFBOs(){this._bindParameters.ssr.lastFrameColor=h(this._bindParameters.ssr.lastFrameColor),this._bindParameters.terrainDepth=h(this._bindParameters.terrainDepth),this._bindParameters.geometryDepth=h(this._bindParameters.geometryDepth)}_disposeOffscreenBuffers(){this._framebuffer.dispose(),this._disposeBindBuffers()}_disposeBindBuffers(){this._shadowMap.disposeOffscreenBuffers(),this._bindParameters.depth=h(this._bindParameters.depth),this._bindParameters.hudVisibility=h(this._bindParameters.hudVisibility)}get updating(){return null!=this._edgeView&&this._edgeView.updating||this._shadowAccumulator.running||this._plugins.updating||!this.isCameraFinal}loadEdgeView(){return this._loadEdgeViewTask||(this._loadEdgeViewTask=r((async e=>{const{EdgeView:t}=await import("./edgeRendering/EdgeView.js");o(e);const r=this._edgeView=new t({rctx:this._rctx,renderSR:this._stage.view.renderSpatialReference,viewingMode:this._stage.viewingMode,techniques:this._techniques,setNeedsRender:()=>this._requestRender(),schedule:xe(this._stage.view.resourceController)});return this._handles.push(d((()=>r.updating),(()=>this._requestRender()),p)),this._requestRender(),this._edgeViewCallbacks.forEach((e=>e(r))),this._edgeViewCallbacks.length=0,r}))),this._loadEdgeViewTask.promise}withEdgeView(e){this.loadEdgeView(),null==this._edgeView?this._edgeViewCallbacks.push(e):e(this._edgeView)}get edgeView(){return this._edgeView}get isCameraFinal(){return this._reprojectionMatrixVersion.value>=0&&c(this._bindParameters.ssr.reprojectionMatrix,b)}set _reprojectionMatrix(e){t(this._bindParameters.ssr.reprojectionMatrix,e)&&this._reprojectionMatrixVersion.value++}get shadowsEnabled(){return!!this._shadowMap?.enabled}setParameters(e){const{_shadowMap:t,_bindParameters:r}=this;if(void 0!==e.qualitySettings?.reflections&&this._ssrEnabled!==e.qualitySettings.reflections&&(this._ssrEnabled=e.qualitySettings.reflections,this._requestRender()),void 0!==e.shadowMap&&this._shadowMap.enabled!==e.shadowMap&&(this._shadowMap.enabled=e.shadowMap,this._requestRender()),void 0!==e.shadowMapMaxCascades&&t.maxCascades!==e.shadowMapMaxCascades&&(t.maxCascades=e.shadowMapMaxCascades,this._requestRender()),null!=e.environment){null!=e.environment.weather&&(this._bindParameters.weather=e.environment.weather,this._bindParameters.weatherVisible=!!e.weatherVisible);const t="virtual"!==e.environment.lighting.type;r.enableFillLights!==t&&(r.enableFillLights=t,this._requestRender())}void 0!==e.highQualityTransparency&&this._highQualityTransparencyEnabled!==e.highQualityTransparency&&(this._highQualityTransparencyEnabled=e.highQualityTransparency,this._requestRender()),void 0!==e.shadowCast&&this._shadowAccumulator.setOptions(e.shadowCast)}set slicePlane(e){this._sliceHelper.plane!==e&&(this._sliceHelper.plane=e,this._requestRender())}get plugins(){return this._plugins}getMaterialRenderer(e){return this._renderers.get(e)}get _hasOITSupport(){return this._rctx.driverTest.floatBufferBlend.result}get _oitEnabled(){return this._highQualityTransparency&&this._hasOITSupport}modify(e,t){this._isRendering&&console.warn("Renderer.modify called while rendering");const{adds:r,removes:i,updates:s}=e;if(0===r.length&&0===i.length&&0===s.length)return;Z(e).forEach(((r,i)=>{if(t.done)return;let s=this._renderers.get(i);null==s&&r.adds.length>0&&(s=new _e({material:i,highlightOrderMap:this._stage.view.state.highlightOrderMap}),s.initializeRenderContext(this._plugins.context),this._plugins.add(s),this._renderers.set(i,s)),s&&(s.modify(r),0===s.numGeometries&&(this._renderers.delete(s.material),this._plugins.remove(s),s.destroy())),r.removes.forEach((t=>e.removes.removeUnordered(t))),r.adds.forEach((t=>e.adds.removeUnordered(t))),r.updates.forEach((t=>e.updates.removeUnordered(t))),t.madeProgress()})),this.updateHasFlags()}updateHasFlags(){const has=this._pluginsHas;has.hudElements=this._plugins.produces(H.Color,...Ce),has.water=this._plugins.produces(H.Normal,se.DRAPED_WATER),this._bindParameters.hasOccludees=this._plugins.hasOccludees,this._requestRender()}updateAnimation(e,t){this._animationTimer??=new j(e.camera,t),this._animationTimer.advance(e.camera,t,this._animationTimeDilation),null!=e.forcedAnimationTime&&this._animationTimer.forceTime(e.forcedAnimationTime);const r=this._hasAnimations;return this._hasAnimations=this._plugins.updateAnimation(this._animationTimer),this._hasAnimations=this._nodes.updateAnimation(this._animationTimer)||this._hasAnimations,this._hasAnimations=this.overlay?.updateAnimation(this._animationTimer)||this._hasAnimations,this._hasAnimations!==r&&(this._gpuTimerHandle=r?s(this._gpuTimerHandle):this.performanceInfo.enableGPUPerformanceInfo()),this._hasAnimations}get animationTimestep(){return this._animationTimestep.value}get _animationTimeDilation(){return this._animationTimestep.timeDilation}resetAnimation(){this._animationTimestep.clear()}tick(){this.fboCache.clean()}render(e,t,r=ee.Default,i=!1){try{return this._isRendering=!0,this._render(e,t,r,i)}catch(s){console.error(`Exception during rendering: ${s}`)}finally{this._isRendering=!1}return new le(this._pluginInput.get(S.FINAL),null)}_render(e,t,r=ee.Default,i){this.performanceInfo.startFrame(),this.fboCache.frameStart(),this.fboCache.interactive=r===ee.Default,this._disposeBindBuffers();const s=this._framebuffer,{camera:a,contentCamera:n,mode:o,alignPixelEnabled:d}=e;this._state.value=o,this._bindParameters.overlay=this.overlay?.render(t),this._bindParameters.overlay&&this.performanceInfo.advance(ue.OVERLAY),this._renderContext.time=t,this._bindParameters.oitPass=K.NONE,this._bindParameters.alignPixelEnabled=d,this._bindParameters.decorations=!i,this._bindParameters.mainDepth=null,this._bindParameters.viewshedEnabled=this._nodes.produces(I.VIEWSHED);const _=this._nodes.produces("magnifier-color"),l=this._nodes.produces(S.FINAL);this._bindParameters.slicePlane=this._sliceHelper.plane,a.setGLViewport(this._rctx);const p=this._emissiveRequired,u=p?H.ColorEmission:H.Color,m=s.initialize(a.fullWidth,a.fullHeight,this._backgroundColor,p);this.hasReflections?(m?.setName("last frame color"),this._bindParameters.ssr.lastFrameColor=m):m?.release(),this._ensureBindParametersCamera(a,n),this._plugins.prepareRender(),this._bindParameters.shadowHighlightsVisible=this._needsShadowHighlight&&!i;const c=this._highQualityTransparency&&this._hasTransparentTerrain,g=this._plugins.produces(H.Color,...Ie);this._precompilePrepasses(),this.performanceInfo.advance(ue.PREPARE);const f=this._computeDepthRange(a);this._renderShadowMap(a,this._bindParameters.lighting.mainLight.direction,f),this._ensureBindParametersCamera(a,n),this._pluginInput.set("normals",this._renderNormals()),this._renderRemainingGeometryDepth(),this._renderShadowAccumulation(f,a,n),this._ensureBindParametersSSR(t),this._precompileShaders(c,g,u),this._renderContext.output=u,s.bind(),this._bindParameters.mainDepth=s.depth.attachment;const b=this.plugins.produces(H.Color,...Se);b&&this._renderOpaqueGeometry(),s.update((e=>this._renderNodes(S.OPAQUE,e,b))),this.fboCache.debugCallback?.("opaque-color",s.color.fbo),s.update((e=>this._renderNodes(I.OPAQUE_ENVIRONMENT,e))),this.fboCache.debugCallback?.(I.OPAQUE_ENVIRONMENT,s.color.fbo),this._renderTerrainDepth(c),this._renderEdges(de.OPAQUE),s.bind(),this._renderPlugins(se.VOXEL,ue.VOXEL),this._renderHiddenTransparentEdges(),g&&(this._oitEnabled?this._renderOIT(Ee.Geometry,u):this._renderTransparentGeometry()),s.update((e=>this._renderNodes(S.TRANSPARENT,e,g))),this.fboCache.debugCallback?.("transparent-color",s.color.fbo),this._renderGeometryDepth(c),this._renderHUDVisibility(),c||this._plugins.render(this._pluginInput,se.LINE_CALLOUTS);const T=r===ee.ObjectAndLayerID?this._renderObjectAndLayerIdColor():null;this._renderEdges(de.TRANSPARENT);const A=this._hasTransparentTerrain?this._renderTransparentTerrain():null;A&&(this.performanceInfo.advance(ue.TRANSPARENT_TERRAIN),this._bindParameters.hudVisibility&&(c?this._renderLineCallouts(L.Occluded):(this._rctx.bindFramebuffer(this._bindParameters.hudVisibility?.fbo),this._compositingHelper.compositeHUD(this._bindParameters,A.getTexture())),this._renderHUD(L.Occluded,s.color,u))),this._bindParameters.cullAboveTerrain=!1,A&&(s.bind(),this._compositingHelper.compositePreMultipliedAlpha(this._bindParameters,A.getTexture()),A.release(),c&&(this._renderEdges(de.OPAQUE),g&&(this._oitEnabled?this._renderOIT(Ee.Geometry,u):this._renderTransparentGeometry(),this.performanceInfo.advance(ue.TRANSPARENT)),this._renderEdges(de.TRANSPARENT))),this._bindParameters.ssao=h(this._bindParameters.ssao),c&&this._renderLineCallouts(L.NotOccluded),this._bindParameters.terrainDepthTest=!1,this._renderTransparentEnvironment(),this._pluginInput.set("focusArea",this._renderFocusAreaGeometry()),s.update((e=>this._renderNodes(I.TRANSPARENT_ENVIRONMENT,e))),s.update((e=>this._renderNodes(I.VIEWSHED,e))),s.update((e=>this._renderNodes(I.LASERLINES,e))),s.update((e=>this._renderNodes(I.OCCLUDED,e))),this._pluginInput.set("highlights",this._renderHighlightPrepass()),s.update((e=>this._renderNodes(S.COMPOSITE,e)));const E=!(r!==ee.Default||l||_&&!i&&r===ee.Default),P=this._pluginInput.get(S.COMPOSITE),R=E?O:this.fboCache.acquire(P.fbo.width,P.fbo.height,I.ANTIALIASING),w=this._nodes.produces(I.ANTIALIASING)?this._renderNodes(I.ANTIALIASING,R):this._blitFBO(P,R,!1);let C;this._pluginInput.set(I.ANTIALIASING,w),this._hasHUDHighlights?(this._renderHUD(L.NotOccluded,w,u),C=this._renderNodes(I.HIGHLIGHTS,w)):(C=this._renderNodes(I.HIGHLIGHTS,w),this._renderHUD(L.NotOccluded,C,u));const D=this._renderNodes(I.MAGNIFIER,C);return _&&!i&&r===ee.Default&&!l&&this._blitFBO(D),l?(D.attachDepth(s.depth),this._blitFBO(this._renderNodes(S.FINAL,D)),D.detachDepth()):this._pluginInput.set(S.FINAL,D),this._pluginInput.release("highlights"),this.onPostRender&&this.onPostRender(),this._releaseFBOs(),s.releaseDepth(),this._renderContext.lastFrameCamera.copyFrom(this._bindParameters.camera),this.fboCache.frameEnd(),this.performanceInfo.finishFrame(),r!==ee.Default&&(this._releaseFBOs(),this._disposeOffscreenBuffers()),new le(this._pluginInput.get(S.FINAL),T)}_precompileShaders(e,t,r){if(++this._plugins.context.techniques.precompiling,this._renderContext.output=r,this._precompileOpaqueGeometry(),this._bindParameters.terrainDepthTest=e,this._bindParameters.cullAboveTerrain=e,this._renderContext.output=H.Depth,this._plugins.precompile(se.TRANSPARENT_TERRAIN),e&&(this._precompileOpaqueGeometry(),this._precompileTransparentGeometry()),this._renderContext.output=r,this._plugins.precompile(se.TRANSPARENT_TERRAIN),t&&(this._precompileTransparentGeometry(),this._hasTransparentTerrain&&(this._bindParameters.cullAboveTerrain=!1,this._precompileTransparentGeometry(),this._bindParameters.cullAboveTerrain=e)),this._needsHUDVisibility&&this._plugins.precompile(se.OCCLUSION_PIXELS),this._plugins.precompile(se.LINE_CALLOUTS),this._precompileHUD(L.Occluded),this._bindParameters.terrainDepthTest=!1,this._bindParameters.cullAboveTerrain=!1,this._nodes.precompile(I.VIEWSHED,I.LASERLINES,I.OCCLUDED),this._precompileHUD(L.NotOccluded),this._hasHighlights){const e=this._bindParameters;e.highlights.forEach(((t,r)=>{e.highlightLevel=r,this._precompileAllGeometry(H.Highlight)})),e.highlightLevel=null}this._nodes.precompile(S.COMPOSITE,I.MAGNIFIER),this._shadowAccumulator.precompile(),this._plugins.precompile(se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH),--this._plugins.context.techniques.precompiling}_updateHighlights(){const e=this._stage.view.state;this._renderers.forEach((t=>t.updateHighlights(e.highlightOrderMap)))}_renderFocusAreaGeometry(){if(this._nodes.produces("focusArea")){const e=this._framebufferSize;let t=this.fboCache.acquire(e.width,e.height,"focusArea");return t=this._nodes.render(t,this._pluginInput),this.performanceInfo.advance(ue.FOCUS_AREA_MASK),t}return null}_renderObjectAndLayerIdColor(){if(!this._nodes.produces("olid"))return null;++this._techniques.precompiling;const e=this._framebufferSize;let t=this.fboCache.acquire(e.width,e.height,"olid");return t.acquireDepth(C.DEPTH_STENCIL_TEXTURE),t=this._nodes.render(t,this._pluginInput),--this._techniques.precompiling,this.performanceInfo.advance(ue.OBJECT_AND_LAYER_ID_COLOR),t}finish(e){this._hasAnimations||this._animationTimestep.clear();const t=this.performanceInfo.gpuSamplingEnabled,r=e===Q.BACKGROUND;if(r||t){const e=r?this.performanceInfo.elapsedTime:0;let i=0;t?i=this.performanceInfo.totalGPUTimeSampler.last:this._rctx.gl.finish();const s=Math.max(e,i);this._animationTimestep.frame(s,r)}}readMainDepth(e,t){const{mainDepth:r,camera:i}=this._bindParameters;if(!r)return;const s=this.fboCache.acquire(this._framebufferSize.width,this._framebufferSize.height,"linear-depth");this._rctx.bindFramebuffer(s.fbo),i.setGLViewport(this._rctx),this._rctx.setScissorRect(e[0],e[1],e[2],e[3]),this._rctx.setScissorTestEnabled(!0),this._rctx.clearFramebuffer(P),this._compositingHelper.blitDepthToLinearDepth(this._bindParameters,r),this._rctx.setScissorTestEnabled(!1),this._rctx.setScissorRect(0,0,this._rctx.gl.canvas.width,this._rctx.gl.canvas.width),s.fbo?.readPixels(e[0],e[1],e[2],e[3],ce.RGBA,ge.UNSIGNED_BYTE,t),s.release()}readHUDVisibility(e,t,r,i,s){this._bindParameters.hudVisibility?.fbo?.readPixels(e,t,r,i,ce.RGBA,ge.UNSIGNED_BYTE,s)}readAccumulatedShadow(e){return this._shadowAccumulator.readAccumulatedShadow(e[0],e[1])}_renderEdges(e){const t=this._edgeView;if(!t?.shouldRender())return;const r=this._framebufferSize,i=this.fboCache.acquire(r.width,r.height,"edges"),s=()=>t.render(this._bindParameters,e),a=this._bindParameters.geometryDepth;this.renderToTargets(s,i,a??this._framebuffer.depth,P),this._framebuffer.bind(),this._compositingHelper.composite(this._bindParameters,i.getTexture()),i.release(),this.performanceInfo.advance(e===de.OPAQUE?ue.OPAQUE_EDGES:ue.TRANSPARENT_EDGES)}_renderShadowMap(e,t,r){if(!this.shadowsEnabled)return;const i=this._shadowMap;i.start(e,t,r,this.isFeatureEnabled(re.HighResolutionShadows),this._stage.view.qualitySettings.maximumPixelRatio),this._needsShadowHighlight?(this._renderShadowCascades(H.ShadowHighlight,this._shadowMap),i.moveSnapshot(he.Highlight),this._renderShadowCascades(H.ShadowExcludeHighlight,this._shadowMap),i.copySnapshot(he.ExcludeHighlight),this._renderShadowCascades(H.ShadowHighlight,this._shadowMap)):this._renderShadowCascades(H.Shadow),i.finish(),e.setGLViewport(this._rctx),this.performanceInfo.advance(ue.SHADOW_MAP)}_precompileShadowCascades(e){for(const t of this._shadowMap.cascades)t.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(t.camera,t.camera),this._precompileAllGeometry(e)}_renderShadowCascades(e,t=this._shadowMap){for(const r of t.cascades)r.camera.setGLViewport(this._rctx),this._ensureBindParametersCamera(r.camera,r.camera),this.renderAllGeometry(e)}get _needsDepth(){return this._plugins.consumes(H.Depth)||this._nodes.requireGeometryDepth()||this.hasReflections||this._needsShadowHighlight||this._needsShadowAccumulation||this._debugNeedsDepth}_renderRemainingGeometryDepth(){const e=this._pluginInput.get("normals");if(e){const t=this._needsDepth?e.getAttachment(fe):null;t?.retain(),this._pluginInput.set(I.SSAO,this._renderSSAO()),this._renderGeometryWithoutNormalsDepth(t)}else this._renderAllGeometryDepth()}_renderGeometryWithoutNormalsDepth(e){if(!this._needsDepth||!e)return void(this._bindParameters.depth=h(this._bindParameters.depth));const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"depth");r.attachDepth(e),e.release(),this._rctx.bindFramebuffer(r.fbo),this._rctx.clear(be.STENCIL),this._renderGeometryWithoutNormals(H.Depth),h(this._bindParameters.depth),this._bindParameters.depth=r.obtainDepthTexture(),r.release(),this.performanceInfo.advance(ue.DEPTH)}_renderAllGeometryDepth(){if(!this._needsDepth)return void(this._bindParameters.depth=h(this._bindParameters.depth));const e=this._framebufferSize,t=this.fboCache.acquire(e.width,e.height,"depth").acquireDepth(C.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(t.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this.renderAllGeometry(H.Depth),h(this._bindParameters.depth),this._bindParameters.depth=t.obtainDepthTexture(),t.release(),this.performanceInfo.advance(ue.DEPTH)}_renderTerrainDepth(e){if(this._bindParameters.terrainDepthTest=e,this._bindParameters.cullAboveTerrain=e,!e)return void(this._bindParameters.terrainDepth=h(this._bindParameters.terrainDepth));const t=this._renderContext.output;this._renderContext.output=H.Depth;const r=this._framebufferSize,i=this.fboCache.acquire(r.width,r.height,"terrain depth").acquireDepth(C.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(i.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this._renderTransparentTerrain(),h(this._bindParameters.terrainDepth),this._bindParameters.terrainDepth=i.obtainDepthTexture(),this._renderContext.output=t,i.release()}_renderGeometryDepth(e){if(!e)return void(this._bindParameters.geometryDepth=h(this._bindParameters.geometryDepth));const t=this._renderContext.output,{width:r,height:i}=this._framebufferSize,s=this.fboCache.acquire(r,i,"geometry depth").acquireDepth(C.DEPTH_STENCIL_TEXTURE);this._rctx.bindFramebuffer(s.fbo),this._rctx.clear(be.DEPTH|be.STENCIL),this._renderOpaqueAndTransparentGeometry(H.Depth),this._renderContext.output=t,h(this._bindParameters.geometryDepth),this._bindParameters.geometryDepth=s.obtainDepthTexture(),s.release()}get _needsDepthRange(){return this._shadowMap.enabled||this._needsShadowAccumulation}_computeDepthRange(e){if(!this._needsDepthRange)return k.zero;const t=z(e,this._plugins.plugins,this._stage.layers);return t.union(this._plugins.queryDepthRange(e)),t.near=Math.max(e.near,t.near),t.far=Math.min(e.far,t.far),t}get _emissiveRequired(){return this._nodes.require("emissive",S.FINAL,S.COMPOSITE)>0&&this._plugins.hasEmissions}get _normalsRequired(){const e=this._nodes.require("normals",S.FINAL,S.COMPOSITE,"opaque-color","transparent-color","laserline-color");return(this.hasSSAO?1:0)+e}_precompilePrepasses(){this._normalsRequired&&this._precompileAllGeometry(H.Normal),this._needsDepth&&this._precompileAllGeometry(H.Depth),this.shadowsEnabled&&(this._needsShadowHighlight?(this._precompileShadowCascades(H.ShadowHighlight),this._precompileShadowCascades(H.ShadowExcludeHighlight),this._precompileShadowCascades(H.ShadowHighlight)):this._precompileShadowCascades(H.Shadow)),this._needsShadowAccumulation&&this._precompileAllGeometry(H.Shadow)}_renderNormals(){const e=this._normalsRequired;if(0===e)return;const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"normals",D.RGBA);r.acquireDepth(C.DEPTH_STENCIL_TEXTURE),this._rctx.bindFramebuffer(r.fbo),this._rctx.clearFramebuffer(P,!0,!0),this._renderGeometryWithNormals(H.Normal);const i=this._nodes.optional("normals",S.FINAL,S.COMPOSITE,"opaque-color","transparent-color","viewshed-color");return r.retain(e+i-1),this.performanceInfo.advance(ue.NORMALS),r}_renderSSAO(){const e=this._pluginInput.get("normals");if(!this.hasSSAO||!e)return void e?.detachDepth();O.setName(I.SSAO);const t=this._nodes.render(O,this._pluginInput);return this._bindParameters.ssao=t,e.detachDepth(),this._pluginInput.release("normals"),this.performanceInfo.advance(ue.SSAO),t}_precompileAllGeometry(e){const t=this._renderContext.output;this._renderContext.output=e,this._precompileOpaqueGeometry(),this._precompileTransparentGeometry(),this._plugins.precompile(se.TRANSPARENT_TERRAIN),this._renderContext.output=t}renderAllGeometry(e){this._renderContext.output=e,this._renderOpaqueAndTransparentGeometry(e),this._renderTransparentTerrain()}precompileSlots(e,...t){for(const r of t)this._bindParameters.slot=r,e.precompile(this._renderContext)}precompileOccludedSlots(e,t){for(const r of t)this._renderContext.renderOccludedMask=r,this.precompileSlots(e,...we);this._renderContext.renderOccludedMask=$}renderSlots(e,...t){for(const r of t)this._bindParameters.slot=r,e.forAll((e=>{const t=e.acquireTechniques(this._renderContext);t&&(e.render(this._renderContext,t,this._pluginInput),U(t))}))}renderOccludedSlots(e,t){this._renderContext.renderOccludedMask=t,this.plugins.renderOccludedFlags>Y.Occlude&&this._plugins.render(this._pluginInput,se.OCCLUDED_TERRAIN),this.renderSlots(e,...we),this._renderContext.renderOccludedMask=$}renderHUD(e){this._bindParameters.hudRenderStyle=e,this._plugins.render(this._pluginInput,se.HUD_MATERIAL)}precompileViewshedShadowMap(){this._precompileAllGeometry(H.ViewshedShadow)}renderViewshedShadowMap(e){const{camera:t,contentCamera:r}=this._bindParameters,i=this._renderContext.output;e.setGLViewport(this._rctx),this._ensureBindParametersCamera(e,e),this.renderAllGeometry(H.ViewshedShadow),this._ensureBindParametersCamera(t,r),this._bindParameters.camera.setGLViewport(this._rctx),this._renderContext.output=i}_renderOpaqueAndTransparentGeometry(e){this._renderContext.output=e,this._renderOpaqueGeometry(),this._renderTransparentGeometry()}_renderGeometryWithNormals(e){this._renderContext.output=e,this._plugins.render(this._pluginInput,...Pe),this._renderTransparentTerrain()}_renderGeometryWithoutNormals(e){this._renderContext.output=e,this._plugins.render(this._pluginInput,...Re)}_precompileOpaqueGeometry(){this._plugins.precompile(...Se)}_renderOpaqueGeometry(){this._plugins.render(this._pluginInput,...Se)}_renderTransparentGeometry(){this._plugins.render(this._pluginInput,...Ie)}get _hasTransparentTerrain(){return this._plugins.produces(H.Color,se.TRANSPARENT_TERRAIN)}_renderTransparentTerrain(){const e=()=>this._plugins.render(this._pluginInput,se.TRANSPARENT_TERRAIN);if(!x(this._renderContext.output))return void e();const t=this._framebufferSize,r=this.fboCache.acquire(t.width,t.height,"transparent terrain");return this.renderToTargets(e,r,this._framebuffer.depth,P),r}get _needsHUDVisibility(){return this._plugins.produces(this._renderContext.output,se.OCCLUSION_PIXELS)}_renderHUDVisibility(){if(!this._needsHUDVisibility)return void(this._bindParameters.hudVisibility=h(this._bindParameters.hudVisibility));const{width:e,height:t}=this._framebufferSize;let r=this._bindParameters.hudVisibility;r?.fbo?.width===e&&r?.fbo?.height===t||(r?.release(),r=this.fboCache.acquire(e,t,"hud visibility",D.RGBA4),this._bindParameters.hudVisibility=r);const i=this._bindParameters.geometryDepth;r.attachDepth(i||this._framebuffer.depth),this._rctx.bindFramebuffer(r.fbo),this._rctx.clearFramebuffer([0,1,0,1]),this._plugins.render(this._pluginInput,se.OCCLUSION_PIXELS),r.detachDepth(),this._framebuffer.bind(),this.performanceInfo.advance(ue.HUD_VISIBILITY)}_renderLineCallouts(e){if(this._bindParameters.hudRenderStyle=e,e===L.Occluded){const e=()=>this._plugins.render(this._pluginInput,se.LINE_CALLOUTS),t=this._framebufferSize,r=this.fboCache.acquireDepth(C.DEPTH16_BUFFER,t.width,t.height,"line callouts");this.renderToTargets(e,this._framebuffer.color,r,void 0,!0,!0),r.release()}else this._plugins.render(this._pluginInput,se.LINE_CALLOUTS)}_precompileHUD(e){if(this._precompileHUDOutput(e),this._hasHighlights){const t=this._renderContext.output;this._renderContext.output=H.Highlight,this._precompileHUDOutput(e),this._renderContext.output=t}}_precompileHUDOutput(e){const t=this._bindParameters.hudRenderStyle;this._bindParameters.hudRenderStyle=e,this._oitEnabled&&x(this._renderContext.output)?(this._bindParameters.oitPass=K.ColorAlpha,this._plugins.precompile(...Ce),this._bindParameters.oitPass=K.FrontFace,this._plugins.precompile(...Ce),this._bindParameters.oitPass=K.NONE):this._plugins.precompile(...Ce),this._bindParameters.hudRenderStyle=t}_renderHUD(e,t,r){if(this._pluginsHas.hudElements){if(this._oitEnabled){const i=this._renderOIT(Ee.HUD,r,e);this._rctx.bindFramebuffer(t.fbo),this._compositingHelper.compositePreMultipliedAlpha(this._bindParameters,i.getTexture()),i.release()}else if(this._renderContext.output=r,e===L.Occluded){const t=()=>this._renderHUDElements(e),r=this._framebufferSize,i=this.fboCache.acquireDepth(C.DEPTH16_BUFFER,r.width,r.height,"hud");this.renderToTargets(t,this._framebuffer.color,i,void 0,!0,!0),i.release()}else t.acquireDepth(C.DEPTH16_BUFFER),this._rctx.bindFramebuffer(t.fbo),this._renderHUDElements(e),t.detachDepth();this.performanceInfo.advance(e===L.Occluded?ue.HUD_OCCLUDED:ue.HUD)}}_renderHUDElements(e){this._bindParameters.hudRenderStyle=e,this._plugins.render(this._pluginInput,...Ce)}get _needsShadowHighlight(){return this.shadowsEnabled&&this._plugins.produces(H.ShadowHighlight,se.OPAQUE_MATERIAL)}_renderHighlightPrepass(){if(!this._hasHighlights)return;const{fboCache:e,_rctx:t,_bindParameters:r}=this,i=this._framebufferSize,s=e.acquire(i.width,i.height,"highlights",D.RG);return s.acquireDepth(C.DEPTH_STENCIL_TEXTURE),t.bindFramebuffer(s.fbo),t.clearFramebuffer(P,!0),this._renderContext.output=H.Highlight,t.bindFramebuffer(s.fbo),q(t,e,i,r,(()=>this._renderHighlightGeometries()),0),this.performanceInfo.advance(ue.HIGHLIGHTS),s}_renderHighlightGeometries(){const e=0===this._bindParameters.highlightLevel?Ne:De;this._plugins.render(this._pluginInput,...e),this._rctx.clear(be.DEPTH),this._renderHUDElements(L.Both)}get _needsShadowAccumulation(){return this._shadowAccumulator.isAccumulating}_renderShadowAccumulation(e,t,r){this._needsShadowAccumulation&&this._bindParameters.depth&&this._shadowAccumulator.renderAccumulation(this._bindParameters.depth,e,t,r)&&this.performanceInfo.advance(ue.ACCUMULATED_SHADOWS)}_precompileTransparentGeometry(){this._oitEnabled&&x(this._renderContext.output)?(this._bindParameters.oitPass=K.ColorAlpha,this._plugins.precompile(...Ie),this._bindParameters.oitPass=K.FrontFace,this._plugins.precompile(...Ie),this._bindParameters.oitPass=K.NONE):this._plugins.precompile(...Ie)}_renderOIT(e,t,r=L.Both){const i=e===Ee.HUD,s=this._framebufferSize,a=i?this.fboCache.acquire(s.width,s.height,"oit hud composite"):null,n=i?()=>this._renderHUDElements(r):()=>this._renderTransparentGeometry(),h=this._bindParameters,o=this._renderContext.output;this._renderContext.output=t,h.oitPass=K.ColorAlpha;const d=a?"oit hud color alpha":"oit color alpha",_=this.fboCache.acquire(s.width,s.height,d,D.RGBA16F),l=t===H.ColorEmission;_.acquireColor(Te.COLOR_ATTACHMENT1,D.R16F),a||_.attachDepth(this._framebuffer.depth),this._rctx.bindFramebuffer(_.fbo),this._rctx.clearFramebuffer([0,0,0,1]),n(),_.detachDepth(),h.oitPass=K.FrontFace;const p=this.fboCache.acquire(s.width,s.height,a?"oit hud front":"oit front");return a?p.acquireDepth(C.DEPTH16_BUFFER):p.attachDepth(this._framebuffer.depth),this._rctx.bindFramebuffer(p.fbo),this._rctx.clearFramebuffer(P,!!a),n(),p.detachDepth(),h.oitPass=K.NONE,a?(this._rctx.bindFramebuffer(a.fbo),this._rctx.setClearColor(0,0,0,1e-13),this._rctx.clear(be.COLOR)):this._framebuffer.bind(),this._oitblend??=new V(this._techniques),this._oitblend.blend(this._rctx,_,p,h,l),a?.detachDepth(),p.release(),_.release(),this._renderContext.output=o,a}_renderTransparentEnvironment(){this._shadowAccumulator.render(this._bindParameters),this.performanceInfo.advance(ue.APPLY_ACCUMULATED_SHADOWS),this._framebuffer.bind(),this._plugins.render(this._pluginInput,se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH),this.performanceInfo.advance(ue.TRANSPARENT_MATERIAL_WITHOUT_DEPTH)}_renderPlugins(e,t){this._plugins.produces(this._renderContext.output,e)&&(this._plugins.render(this._pluginInput,e),this.performanceInfo.advance(t))}_renderNodes(e,t,r=!1){if(t.setName(e),this._pluginInput.set(e,t),!this._nodes.produces(e))return r&&this.performanceInfo.advance(e),t;const i=this._nodes.render(t,this._pluginInput,this._releaseNormals);return this.performanceInfo.advance(e),i}_blitFBO(e,t=O,r=!0){return this._blit??=new G(this._techniques),this._blit.blit(this._rctx,e,t,this._bindParameters),this._pluginInput.set(e.name,t),r&&e.release(),t}_ensureBindParametersCamera(e,t){this._bindParameters.camera=e,this._bindParameters.contentCamera=t}_ensureBindParametersSSR(e){if(this._bindParameters.ssr.lastFrameColor){null==this._ssrEnableTime&&(this._ssrEnableTime=e),this._renderContext.lastFrameCamera.equals(this._bindParameters.camera)?this._reprojectionMatrix=b:(g(ye,this._bindParameters.camera.viewMatrix),g(Oe,this._bindParameters.camera.projectionMatrix),f(He,ye,Oe),f(He,this._renderContext.lastFrameCamera.viewMatrix,He),f(He,this._renderContext.lastFrameCamera.projectionMatrix,He),this._reprojectionMatrix=He);const t=this._stage.view.qualitySettings.fadeDuration;this._bindParameters.ssr.fadeFactor=t>0?Math.min(t,e-this._ssrEnableTime)/t:1,this._bindParameters.ssr.fadeFactor<1&&this._requestRender()}else this._reprojectionMatrix=b,this._ssrEnableTime=null}addRenderNode(e){this._nodes.add(e),this._requestRender()}removeRenderNode(e){this._nodes.remove(e),this._requestRender()}updateLighting(e,t,r,i){this._bindParameters.updateLighting(e,t,r,i),this._requestRender(Q.UPDATE)}get usedMemory(){return{fbos:this.fboCache.usedMemory,plugins:this._plugins.usedMemory,edges:this.edgeView?.usedMemory??0}}renderToTargets(e,t,r,i,s=!1,a=!1){t.attachDepth(r),this._rctx.bindFramebuffer(t.fbo),this._rctx.clearFramebuffer(i,s,a),e(),t.detachDepth()}get test(){}}var Ee;e([m({readOnly:!0})],Ae.prototype,"fullResolutionAtmosphere",null),e([m()],Ae.prototype,"_edgeView",void 0),e([m()],Ae.prototype,"updating",null),function(e){e[e.Geometry=0]="Geometry",e[e.HUD=1]="HUD"}(Ee||(Ee={}));const Pe=[se.INTEGRATED_MESH,se.OPAQUE_TERRAIN,se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL],Re=[se.OPAQUE_MATERIAL_WITHOUT_NORMALS,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS],Se=[se.INTEGRATED_MESH,se.OPAQUE_TERRAIN,se.OPAQUE_MATERIAL,se.OPAQUE_MATERIAL_WITHOUT_NORMALS],Ie=[se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS],we=[se.OPAQUE_MATERIAL,se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_DEPTH],Ce=[se.LINE_CALLOUTS_HUD_DEPTH,se.HUD_MATERIAL,se.LABEL_MATERIAL],De=[se.TRANSPARENT_MATERIAL,se.TRANSPARENT_MATERIAL_WITHOUT_NORMALS,se.OPAQUE_MATERIAL,se.OPAQUE_MATERIAL_WITHOUT_NORMALS],Ne=[...De,se.TRANSPARENT_TERRAIN,se.INTEGRATED_MESH,se.OPAQUE_TERRAIN],Oe=T(),ye=T(),He=T();function xe(e){return t=>e.immediate.schedule(t)}export{Ae as Renderer};