@arcgis/core 5.1.0-next.20 → 5.1.0-next.21

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.
Files changed (185) hide show
  1. package/applications/Components/OrientedImageryViewer/galleryUtils.d.ts +45 -15
  2. package/applications/Components/QuantityFormatter.d.ts +11 -11
  3. package/applications/Components/SelectionOperation.d.ts +11 -11
  4. package/applications/Components/SketchTooltipControls.d.ts +9 -9
  5. package/applications/Components/actionUtils.d.ts +2 -1
  6. package/applications/Components/analysisUtils.d.ts +27 -26
  7. package/applications/Components/applySetUtils.d.ts +40 -40
  8. package/applications/Components/arcadeEditorUtils.d.ts +3 -3
  9. package/applications/Components/arcadeFeatureUtils.d.ts +12 -12
  10. package/applications/Components/baUtils.d.ts +8 -8
  11. package/applications/Components/basemapUtils.d.ts +2 -2
  12. package/applications/Components/clipboard.d.ts +14 -14
  13. package/applications/Components/drawUtils.d.ts +3 -3
  14. package/applications/Components/editUtils.d.ts +14 -14
  15. package/applications/Components/featureUtils.d.ts +10 -10
  16. package/applications/Components/fieldFormatUtils.d.ts +2 -2
  17. package/applications/Components/fontUtils.d.ts +2 -2
  18. package/applications/Components/formatUtils.d.ts +2 -2
  19. package/applications/Components/getDefaultUnits.d.ts +2 -2
  20. package/applications/Components/gfxUtils.d.ts +5 -1
  21. package/applications/Components/imageryUtils.d.ts +35 -35
  22. package/applications/Components/layerOriginUtils.d.ts +5 -5
  23. package/applications/Components/layersEffectsJsonUtils.d.ts +2 -2
  24. package/applications/Components/previewSymbol2D.d.ts +2 -2
  25. package/applications/Components/rasterFunctionEditorUtils.d.ts +40 -40
  26. package/applications/Components/reactiveUtils.d.ts +14 -13
  27. package/applications/Components/sanitizerUtils.d.ts +2 -2
  28. package/applications/Components/stringUtils.d.ts +5 -5
  29. package/applications/Components/styleUtils.d.ts +2 -2
  30. package/applications/Components/svgUtils.d.ts +4 -4
  31. package/applications/Components/symbolUtils.d.ts +47 -11
  32. package/applications/Components/templateUtils.d.ts +73 -17
  33. package/applications/Components/templateUtils.js +1 -1
  34. package/applications/Components/testUtils.d.ts +3 -3
  35. package/applications/Components/unitUtils.d.ts +1 -1
  36. package/applications/Components/viewUtils.d.ts +2 -2
  37. package/applications/Components/webStyleSymbolUtils.d.ts +2 -2
  38. package/applications/Excalibur/imageryLayerUtils.d.ts +3 -3
  39. package/applications/Excalibur/videoViewUtils.d.ts +8 -8
  40. package/applications/Excalibur/widgetUtils.d.ts +2 -2
  41. package/applications/ExperienceBuilder/sketchUtils.d.ts +7 -7
  42. package/applications/KnowledgeStudio/dataModelVisualization.d.ts +20 -8
  43. package/applications/KnowledgeStudio/generalSdkInternalAccess.d.ts +21 -21
  44. package/applications/KnowledgeStudio/generalSharedKgUtils.d.ts +35 -35
  45. package/applications/KnowledgeStudio/layerInternalAccessUtils.d.ts +9 -9
  46. package/applications/KnowledgeStudio/reshape.d.ts +40 -40
  47. package/applications/KnowledgeStudio/resourceSerializationUtils.d.ts +11 -11
  48. package/applications/MapViewer/layerUtils.d.ts +2 -2
  49. package/applications/MapViewer/mediaUtils.d.ts +13 -13
  50. package/applications/MapViewer/templateUtils.d.ts +20 -20
  51. package/applications/PortalApp/layerUtils.d.ts +2 -2
  52. package/applications/SceneViewer/colorUtils.d.ts +2 -2
  53. package/applications/SceneViewer/devEnvironmentUtils.d.ts +4 -3
  54. package/applications/SceneViewer/layerUtils.d.ts +3 -3
  55. package/applications/SceneViewer/sceneViewerUtils.d.ts +34 -34
  56. package/applications/SceneViewer/symbolUtils.d.ts +2 -2
  57. package/applications/Urban/LineImagePattern3D.d.ts +3 -2
  58. package/applications/Urban/imagePatternUtils.d.ts +4 -4
  59. package/applications/Urban/meshUtils.d.ts +2 -2
  60. package/applications/WebEditor/sketchUtils.d.ts +8 -8
  61. package/assets/esri/core/workers/RemoteClient.js +1 -1
  62. package/assets/esri/core/workers/chunks/{df321c37b61099f6e4c2.js → 11058e660139c427c3e7.js} +1 -1
  63. package/assets/esri/core/workers/chunks/1dcd057695f8db79eca2.js +1 -0
  64. package/assets/esri/core/workers/chunks/568d32ceee1409809e5a.js +1 -0
  65. package/assets/esri/core/workers/chunks/6b56c8ba978ec6edd6b8.js +1 -0
  66. package/assets/esri/core/workers/chunks/7b59ddad3c73f5f44b4d.js +1 -0
  67. package/assets/esri/core/workers/chunks/a4919dd9963f853a0077.js +1 -0
  68. package/assets/esri/core/workers/chunks/a7dbd38bc216713044fc.js +1 -0
  69. package/assets/esri/core/workers/chunks/{b8b2f160518e3a225d99.js → b364ec104dd59faa41b6.js} +1 -1
  70. package/assets/esri/core/workers/chunks/{0bb3beedae1b73beb1fc.js → b96dce64bdd7487e862a.js} +1 -1
  71. package/assets/esri/core/workers/chunks/{23c856265dd24ce54fdb.js → bfeab15d7ac9a2559fe5.js} +1 -1
  72. package/assets/esri/core/workers/chunks/c3e4f8664988e50bda55.js +1 -0
  73. package/assets/esri/core/workers/chunks/cf100c80b75ba74b479c.js +1 -0
  74. package/chunks/Clouds.glsl.js +1 -1
  75. package/config.js +1 -1
  76. package/geometry/support/curves/curveUtils.js +1 -1
  77. package/geometry/support/curves/densifyCurvedGeometry.js +1 -1
  78. package/graphic/graphicOriginUtils.js +1 -1
  79. package/kernel.js +1 -1
  80. package/layers/WMTSLayer.js +1 -1
  81. package/layers/graphics/editingSupport.js +1 -1
  82. package/layers/support/Sublayer.d.ts +3 -0
  83. package/package.json +1 -1
  84. package/renderers/support/DictionaryControlString.js +1 -1
  85. package/renderers/support/DictionaryLoader.js +1 -1
  86. package/rest/featureService/FeatureService.js +1 -1
  87. package/smartMapping/support/utils.js +1 -1
  88. package/support/revision.js +1 -1
  89. package/symbols/cim/CIMSymbolHelper.js +1 -1
  90. package/symbols/cim/GeometryWalker.js +1 -1
  91. package/symbols/cim/animationUtils.js +1 -1
  92. package/symbols/cim/cimAnalyzer.js +1 -1
  93. package/symbols/cim/effects/EffectDashes.js +1 -1
  94. package/symbols/cim/effects/EffectDonut.js +1 -1
  95. package/symbols/cim/effects/EffectOffset.js +1 -1
  96. package/symbols/cim/effects/EffectWave.js +1 -1
  97. package/symbols/cim/placements/PlacementAlongLineSameSize.js +1 -1
  98. package/symbols/cim/placements/PlacementAtExtremities.js +1 -1
  99. package/symbols/cim/placements/PlacementAtRatioPositions.js +1 -1
  100. package/symbols/cim/placements/PlacementOnLine.js +1 -1
  101. package/symbols/cim/rasterizingUtils.js +1 -1
  102. package/symbols/cim/types.d.ts +220 -117
  103. package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
  104. package/views/2d/layers/features/schema/processor/symbols/utils.js +1 -1
  105. package/views/3d/environment/CloudsRenderer.js +1 -1
  106. package/views/3d/environment/Fog.js +1 -1
  107. package/views/3d/environment/FogTechnique.js +1 -1
  108. package/views/3d/environment/NoiseTextureAtlas.js +1 -1
  109. package/views/3d/environment/NoiseTextureAtlasTechnique.js +1 -1
  110. package/views/3d/layers/graphics/polygonUtils.js +1 -1
  111. package/views/3d/layers/support/patternUtils.js +1 -1
  112. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
  113. package/views/3d/webgl-engine/core/FBOCache.js +1 -1
  114. package/views/3d/webgl-engine/core/FBOCacheFormats.js +1 -1
  115. package/views/3d/webgl-engine/effects/focusArea/FocusAreaMaskNode.js +1 -1
  116. package/views/3d/webgl-engine/effects/geometry/RenderOccludedRenderNode.js +1 -1
  117. package/views/3d/webgl-engine/lib/CutFillDepth.js +1 -1
  118. package/views/3d/webgl-engine/lib/GPUPointOcclusionQuery.js +1 -1
  119. package/views/3d/webgl-engine/lib/Geometry.js +1 -1
  120. package/views/3d/webgl-engine/lib/MainFramebuffer.js +1 -1
  121. package/views/3d/webgl-engine/lib/Material.js +1 -1
  122. package/views/3d/webgl-engine/lib/RayIntersections.js +1 -1
  123. package/views/3d/webgl-engine/lib/RenderGeometry.js +1 -1
  124. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  125. package/views/3d/webgl-engine/lib/RenderingContext.js +1 -1
  126. package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
  127. package/views/3d/webgl-engine/lib/ViewshedShadowMap.js +1 -1
  128. package/views/3d/webgl-engine/lib/geometryDataUtils.js +1 -1
  129. package/views/3d/webgl-engine/materials/ColorMaterial.js +1 -1
  130. package/views/3d/webgl-engine/materials/PatternMaterial.js +1 -1
  131. package/views/3d/webgl-engine/materials/renderers/IndexBufferCache.js +2 -0
  132. package/views/3d/webgl-engine/materials/renderers/IndexLayout.js +2 -0
  133. package/views/3d/webgl-engine/materials/renderers/Instance.js +1 -1
  134. package/views/3d/webgl-engine/materials/renderers/MergedBuffer.js +1 -1
  135. package/views/3d/webgl-engine/materials/renderers/PerBufferData.js +1 -1
  136. package/views/3d/webgl-engine/materials/renderers/VaoRenderer.js +1 -1
  137. package/views/3d/webgl-engine/materials/renderers/VaoWriter.js +1 -1
  138. package/views/View.d.ts +13 -2
  139. package/views/draw/support/Reshape.js +1 -1
  140. package/views/draw/support/reshapeUtils.js +1 -1
  141. package/views/draw/support/types.d.ts +8 -1
  142. package/views/interactive/support/utils.js +1 -1
  143. package/views/webgl/BufferObject.js +1 -1
  144. package/widgets/Attribution/AttributionViewModel.d.ts +3 -1
  145. package/widgets/Attribution/AttributionViewModel.js +1 -1
  146. package/widgets/Attribution.d.ts +1 -1
  147. package/widgets/Attribution.js +1 -1
  148. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  149. package/widgets/Editor/EditorViewModel.d.ts +2 -22
  150. package/widgets/Editor/EditorViewModel.js +1 -1
  151. package/widgets/Editor/SplitFeatureWorkflow.js +1 -1
  152. package/widgets/Editor/UpdateWorkflow.js +1 -1
  153. package/widgets/Editor/Workflow.js +1 -1
  154. package/widgets/Editor/support/SketchController.js +1 -1
  155. package/widgets/Editor/workflowUtils.js +1 -1
  156. package/widgets/Editor.d.ts +10 -15
  157. package/widgets/Editor.js +1 -1
  158. package/widgets/FeatureTable/FeatureTableViewModel.d.ts +0 -15
  159. package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
  160. package/widgets/FeatureTable/support/types.d.ts +0 -1
  161. package/widgets/FeatureTable.d.ts +1 -19
  162. package/widgets/FeatureTable.js +1 -1
  163. package/widgets/HistogramRangeSlider.d.ts +1 -1
  164. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  165. package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
  166. package/widgets/OrientedImageryViewer/adapters/view/MapViewAdapter.js +1 -1
  167. package/widgets/PanoramicVideoViewer.js +1 -1
  168. package/widgets/PanoramicViewer/PanoramicVideoViewerViewModel.js +1 -1
  169. package/widgets/PanoramicViewer/support/PanoramicMedia.js +1 -1
  170. package/widgets/PanoramicViewer/support/PanoramicTileNode.js +1 -1
  171. package/widgets/PanoramicViewer/support/PanoramicTilePyramid.js +1 -1
  172. package/widgets/PanoramicViewer/utils.js +1 -1
  173. package/widgets/Sketch/SketchViewModel.d.ts +4 -22
  174. package/widgets/Sketch/SketchViewModel.js +1 -1
  175. package/widgets/Sketch/support/PluginManager.js +1 -1
  176. package/widgets/Sketch.d.ts +10 -17
  177. package/widgets/Sketch.js +1 -1
  178. package/assets/esri/core/workers/chunks/0d56e3b3265a4470aaa6.js +0 -1
  179. package/assets/esri/core/workers/chunks/5a8b3e5977c233d5c9d0.js +0 -1
  180. package/assets/esri/core/workers/chunks/bbf2afa05314e267893f.js +0 -1
  181. package/assets/esri/core/workers/chunks/bd2f577cae61facdde4a.js +0 -1
  182. package/assets/esri/core/workers/chunks/bf2bfc0d78be8c185d58.js +0 -1
  183. package/assets/esri/core/workers/chunks/c6e0ada6f2ad74fddfec.js +0 -1
  184. package/assets/esri/core/workers/chunks/dcc8363faa22e6211351.js +0 -1
  185. package/assets/esri/core/workers/chunks/e081d6f21a2c01ccaf61.js +0 -1
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import has from"../../../../core/has.js";import{clamp as t,lerp as s,acosClamped as e}from"../../../../core/mathUtils.js";import{releaseMaybe as i}from"../../../../core/maybe.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{translate as r,multiply as h,invert as o,lookAt as n}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as c,create as l}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as d,add as m,scale as u,lerp as _,squaredDistance as f,subtract as g,dot as p,negate as x,normalize as b,copy as w}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as M}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{exactEquals as C,copy as j,negate as y,transformMat4 as v,set as S}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as H}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as D,transformMat4 as F}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as O}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{CascadeCamera as T}from"./CascadeCamera.js";import{applyTextureResizeModulo as Q}from"./textureUtils.js";import{assert as B,logWithBase as L,verify as V,rayRay2D as N}from"./Util.js";import{DepthStencilAttachment as R}from"../../../webgl/enums.js";class W{constructor(){this.camera=new T,this.lightMat=l()}}class q{constructor(){this.maxNumCascadesHighQuality=4,this.maxNumCascadesLowQuality=4,this.textureSizeModHighQuality=1.3,this.textureSizeModLowQuality=.9,this.splitSchemeLambda=0}}class z{constructor(t,s){this._fbos=t,this._viewingMode=s,this._snapshots=new Array,this._textureHeight=0,this._numCascades=1,this.settings=new q,this._projectionView=l(),this._projectionViewInverse=l(),this._modelViewLight=l(),this._cascadeDistances=[0,0,0,0,0],this._usedCascadeDistances=O(),this._cascades=[new W,new W,new W,new W],this._lastOrigin=null,this._enabled=!1,this._maxTextureWidth=Math.min(has("esri-mobile")?4096:16384,t.rctx.parameters.maxTextureSize)}dispose(){this.enabled=!1,this.disposeBuffers()}get depthTexture(){return this._handle?.getTexture(R)}get _textureWidth(){return this._textureHeight*this._numCascades}get numCascades(){return this._numCascades}get cascadeDistances(){return D(this._usedCascadeDistances,this._cascadeDistances[0],this._numCascades>1?this._cascadeDistances[1]:1/0,this._numCascades>2?this._cascadeDistances[2]:1/0,this._numCascades>3?this._cascadeDistances[3]:1/0)}disposeMainBuffer(){this._handle=i(this._handle)}disposeBuffers(){this.disposeMainBuffer(),this._discardSnapshots()}set maxCascades(s){this.settings.maxNumCascadesHighQuality=t(Math.floor(s),1,4)}get maxCascades(){return this.settings.maxNumCascadesHighQuality}set enabled(t){this._enabled=t,t||this.disposeBuffers()}get enabled(){return this._enabled}get ready(){return this._enabled&&null!=this.depthTexture}get cascades(){for(let t=0;t<this._numCascades;++t)X[t]=this._cascades[t];return X.length=this._numCascades,X}start(t,s,e,i,a){B(this.enabled);const{near:r,far:h}=xt(e);this._computeCascadeDistances(r,h,i),this._textureHeight=this._computeTextureHeight(t,a,i),this._setupMatrices(t,s);const{viewMatrix:o,projectionMatrix:n}=t;for(let c=0;c<this._numCascades;++c)this._constructCascade(c,n,o,s);this._lastOrigin=null,this.clear()}finish(){B(this.enabled)}getShadowMapMatrices(t){if(!this._lastOrigin||!C(t,this._lastOrigin)){this._lastOrigin=this._lastOrigin||H(),j(this._lastOrigin,t);for(let s=0;s<this._numCascades;++s){r(Z,this._cascades[s].lightMat,t);for(let t=0;t<16;++t)$[16*s+t]=Z[t]}}return $}moveSnapshot(t){B(this.enabled),this._snapshots[t]?.release(),this._snapshots[t]=this._handle,this._handle?.setName(0===t?"shadow map highlight":"shadow map excluding highlight"),this._handle=null}copySnapshot(t){if(!this.enabled)return;const s=this._handle?.getTexture(R)?.descriptor;if(!s)return;this._snapshots[t]?.release();const e=0===t?"shadow map highlight":"shadow map excluding highlight",i=this._acquireFBO(e);this._snapshots[t]=i;const a=this._handle?.fbo;if(!a||!i?.fbo)return void console.error("No FBO");const{rctx:r}=this._fbos;r.blitFramebuffer(a,i.fbo,256)}getSnapshot(t){return this.enabled?this._snapshots[t]?.getTexture(R):null}clear(){this._ensureFbo(),this.bindFbo(),this._fbos.rctx.clear(256)}_computeTextureHeight({pixelRatio:t,fullWidth:s,fullHeight:e},i,a){const r=Math.min(window.devicePixelRatio,i)/t,h=a?this.settings.textureSizeModHighQuality:this.settings.textureSizeModLowQuality;return Q(Math.max(s,e)*r*h,this._maxTextureWidth/this._numCascades)}_ensureFbo(){this._handle?.fbo?.width===this._textureWidth&&this._handle?.fbo.height===this._textureHeight||(this._handle?.release(),this._handle=this._acquireFBO("shadow map"))}_acquireFBO(t){const s=this._fbos.acquire(this._textureWidth,this._textureHeight,t,13);return s.getTexture(R)?.setShadowFiltering(!0),s}_discardSnapshot(t){this._snapshots[t]=i(this._snapshots[t])}_discardSnapshots(){for(let t=0;t<this._snapshots.length;++t)this._discardSnapshot(t);this._snapshots.length=0}bindFbo(){this._fbos.rctx.bindFramebuffer(this._handle?.fbo)}_constructCascade(t,s,e,i){const a=this._cascades[t],o=-this._cascadeDistances[t],n=-this._cascadeDistances[t+1],c=(s[10]*o+s[14])/Math.abs(s[11]*o+s[15]),l=(s[10]*n+s[14])/Math.abs(s[11]*n+s[15]);B(c<l);for(let r=0;r<8;++r){D(I,r%4==0||r%4==3?-1:1,r%4==0||r%4==1?-1:1,r<4?c:l,1);const t=U[r];F(t,I,this._projectionViewInverse),t[0]/=t[3],t[1]/=t[3],t[2]/=t[3]}y(K,U[0]),a.camera.viewMatrix=r(A,this._modelViewLight,K);for(let r=0;r<8;++r)v(U[r],U[r],a.camera.viewMatrix);let d=U[0][2],m=U[0][2];for(let r=1;r<8;++r)d=Math.min(d,U[r][2]),m=Math.max(m,U[r][2]);d-=200,m+=200,a.camera.near=-m,a.camera.far=-d,pt(e,i,d,m,a.camera),h(a.lightMat,a.camera.projectionMatrix,a.camera.viewMatrix);const u=this._textureHeight;a.camera.viewport=[t*u,0,u,u]}_setupMatrices(t,s){h(this._projectionView,t.projectionMatrix,t.viewMatrix),o(this._projectionViewInverse,this._projectionView);const e=1===this._viewingMode?t.eye:S(K,0,0,1);n(this._modelViewLight,[0,0,0],[-s[0],-s[1],-s[2]],e)}_computeCascadeDistances(t,e,i){const a=i?this.settings.maxNumCascadesHighQuality:this.settings.maxNumCascadesLowQuality;this._numCascades=Math.min(1+Math.floor(L(e/t,4)),a);const r=(e-t)/this._numCascades,h=(e/t)**(1/this._numCascades);let o=t,n=t;for(let c=0;c<this._numCascades+1;++c)this._cascadeDistances[c]=s(o,n,this.settings.splitSchemeLambda),o*=h,n+=r}get test(){}}const A=l(),I=O(),U=[];for(let bt=0;bt<8;++bt)U.push(O());const P=M(),k=M(),E=M(),G=M(),J=M(),K=H(),X=[];function Y(){X.length=0}const Z=l(),$=c.concat(c,c,c),tt=M(),st=M(),et=[M(),M(),M(),M()],it=M(),at=M(),rt=M(),ht=M(),ot=M(),nt=M(),ct=M();function lt(t,s,e,i,a,r,h,o){d(tt,0,0);for(let d=0;d<4;++d)m(tt,tt,t[d]);u(tt,tt,.25),d(st,0,0);for(let d=4;d<8;++d)m(st,st,t[d]);u(st,st,.25),_(et[0],t[4],t[5],.5),_(et[1],t[5],t[6],.5),_(et[2],t[6],t[7],.5),_(et[3],t[7],t[4],.5);let n=0,c=f(et[0],tt);for(let d=1;d<4;++d){const t=f(et[d],tt);t<c&&(c=t,n=d)}g(it,et[n],t[n+4]);const l=it[0];let M,C;it[0]=-it[1],it[1]=l,g(at,st,tt),p(at,it)<0&&x(it,it),_(it,it,at,e),b(it,it),M=C=p(g(rt,t[0],tt),it);for(let d=1;d<8;++d){const s=p(g(rt,t[d],tt),it);s<M?M=s:s>C&&(C=s)}w(i,tt),u(rt,it,M-s),m(i,i,rt);let j=-1,y=1,v=0,S=0;for(let d=0;d<8;++d){g(ht,t[d],i),b(ht,ht);const s=it[0]*ht[1]-it[1]*ht[0];s>0?s>j&&(j=s,v=d):s<y&&(y=s,S=d)}V(j>0,"leftArea"),V(y<0,"rightArea"),u(ot,it,M),m(ot,ot,tt),u(nt,it,C),m(nt,nt,tt),ct[0]=-it[1],ct[1]=it[0];const H=N(i,t[S],nt,m(rt,nt,ct),1,a),D=N(i,t[v],nt,rt,1,r),F=N(i,t[v],ot,m(rt,ot,ct),1,h),O=N(i,t[S],ot,rt,1,o);V(H,"rayRay"),V(D,"rayRay"),V(F,"rayRay"),V(O,"rayRay")}function dt(t,s){return 3*s+t}const mt=M();function ut(t,s){return d(mt,t[s],t[s+3]),mt}const _t=M(),ft=a();function gt(t,s,e,i,a){g(_t,e,i),u(_t,_t,.5),ft[0]=_t[0],ft[1]=_t[1],ft[2]=0,ft[3]=_t[1],ft[4]=-_t[0],ft[5]=0,ft[6]=_t[0]*_t[0]+_t[1]*_t[1],ft[7]=_t[0]*_t[1]-_t[1]*_t[0],ft[8]=1,ft[dt(0,2)]=-p(ut(ft,0),t),ft[dt(1,2)]=-p(ut(ft,1),t);let r=p(ut(ft,0),e)+ft[dt(0,2)],h=p(ut(ft,1),e)+ft[dt(1,2)],o=p(ut(ft,0),i)+ft[dt(0,2)],n=p(ut(ft,1),i)+ft[dt(1,2)];r=-(r+o)/(h+n),ft[dt(0,0)]+=ft[dt(1,0)]*r,ft[dt(0,1)]+=ft[dt(1,1)]*r,ft[dt(0,2)]+=ft[dt(1,2)]*r,r=1/(p(ut(ft,0),e)+ft[dt(0,2)]),h=1/(p(ut(ft,1),e)+ft[dt(1,2)]),ft[dt(0,0)]*=r,ft[dt(0,1)]*=r,ft[dt(0,2)]*=r,ft[dt(1,0)]*=h,ft[dt(1,1)]*=h,ft[dt(1,2)]*=h,ft[dt(2,0)]=ft[dt(1,0)],ft[dt(2,1)]=ft[dt(1,1)],ft[dt(2,2)]=ft[dt(1,2)],ft[dt(1,2)]+=1,r=p(ut(ft,1),s)+ft[dt(1,2)],h=p(ut(ft,2),s)+ft[dt(2,2)],o=p(ut(ft,1),e)+ft[dt(1,2)],n=p(ut(ft,2),e)+ft[dt(2,2)],r=-.5*(r/h+o/n),ft[dt(1,0)]+=ft[dt(2,0)]*r,ft[dt(1,1)]+=ft[dt(2,1)]*r,ft[dt(1,2)]+=ft[dt(2,2)]*r,r=p(ut(ft,1),s)+ft[dt(1,2)],h=p(ut(ft,2),s)+ft[dt(2,2)],o=-h/r,ft[dt(1,0)]*=o,ft[dt(1,1)]*=o,ft[dt(1,2)]*=o,a[0]=ft[0],a[1]=ft[1],a[2]=0,a[3]=ft[2],a[4]=ft[3],a[5]=ft[4],a[6]=0,a[7]=ft[5],a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=ft[6],a[13]=ft[7],a[14]=0,a[15]=ft[8]}function pt(t,s,i,a,r){const h=1/U[0][3],o=1/U[4][3];B(h<o);let n=h+Math.sqrt(h*o);const c=Math.sin(e(t[2]*s[0]+t[6]*s[1]+t[10]*s[2]));n/=c,lt(U,n,c,P,k,E,G,J),gt(P,k,G,J,r.projectionMatrix),r.projectionMatrix[10]=2/(i-a),r.projectionMatrix[14]=-(i+a)/(i-a)}function xt(t){let{near:s,far:e}=t;return s<2&&(s=2),e<2&&(e=2),s>=e&&(s=2,e=4),{near:s,far:e}}export{z as ShadowMap,Y as cleanupShadowmap};
2
+ import has from"../../../../core/has.js";import{clamp as t,lerp as s,acosClamped as e}from"../../../../core/mathUtils.js";import{releaseMaybe as i}from"../../../../core/maybe.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{translate as r,multiply as h,invert as o,lookAt as n}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{IDENTITY as c,create as l}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as d,add as m,scale as u,lerp as _,squaredDistance as f,subtract as g,dot as p,negate as x,normalize as b,copy as w}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as M}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{exactEquals as C,copy as j,negate as y,transformMat4 as v,set as S}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as H}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as D,transformMat4 as F}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{create as O}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{CascadeCamera as T}from"./CascadeCamera.js";import{applyTextureResizeModulo as Q}from"./textureUtils.js";import{assert as B,logWithBase as L,verify as V,rayRay2D as N}from"./Util.js";import{DepthStencilAttachment as R}from"../../../webgl/enums.js";class W{constructor(){this.camera=new T,this.lightMat=l()}}class q{constructor(){this.maxNumCascadesHighQuality=4,this.maxNumCascadesLowQuality=4,this.textureSizeModHighQuality=1.3,this.textureSizeModLowQuality=.9,this.splitSchemeLambda=0}}class z{constructor(t,s){this._fbos=t,this._viewingMode=s,this._snapshots=new Array,this._textureHeight=0,this._numCascades=1,this.settings=new q,this._projectionView=l(),this._projectionViewInverse=l(),this._modelViewLight=l(),this._cascadeDistances=[0,0,0,0,0],this._usedCascadeDistances=O(),this._cascades=[new W,new W,new W,new W],this._lastOrigin=null,this._enabled=!1,this._maxTextureWidth=Math.min(has("esri-mobile")?4096:16384,t.rctx.parameters.maxTextureSize)}dispose(){this.enabled=!1,this.disposeBuffers()}get depthTexture(){return this._handle?.getTexture(R)}get _textureWidth(){return this._textureHeight*this._numCascades}get numCascades(){return this._numCascades}get cascadeDistances(){return D(this._usedCascadeDistances,this._cascadeDistances[0],this._numCascades>1?this._cascadeDistances[1]:1/0,this._numCascades>2?this._cascadeDistances[2]:1/0,this._numCascades>3?this._cascadeDistances[3]:1/0)}disposeMainBuffer(){this._handle=i(this._handle)}disposeBuffers(){this.disposeMainBuffer(),this._discardSnapshots()}set maxCascades(s){this.settings.maxNumCascadesHighQuality=t(Math.floor(s),1,4)}get maxCascades(){return this.settings.maxNumCascadesHighQuality}set enabled(t){this._enabled=t,t||this.disposeBuffers()}get enabled(){return this._enabled}get ready(){return this._enabled&&null!=this.depthTexture}get cascades(){for(let t=0;t<this._numCascades;++t)X[t]=this._cascades[t];return X.length=this._numCascades,X}start(t,s,e,i,a){B(this.enabled);const{near:r,far:h}=xt(e);this._computeCascadeDistances(r,h,i),this._textureHeight=this._computeTextureHeight(t,a,i),this._setupMatrices(t,s);const{viewMatrix:o,projectionMatrix:n}=t;for(let c=0;c<this._numCascades;++c)this._constructCascade(c,n,o,s);this._lastOrigin=null,this.clear()}finish(){B(this.enabled)}getShadowMapMatrices(t){if(!this._lastOrigin||!C(t,this._lastOrigin)){this._lastOrigin=this._lastOrigin||H(),j(this._lastOrigin,t);for(let s=0;s<this._numCascades;++s){r(Z,this._cascades[s].lightMat,t);for(let t=0;t<16;++t)$[16*s+t]=Z[t]}}return $}moveSnapshot(t){B(this.enabled),this._snapshots[t]?.release(),this._snapshots[t]=this._handle,this._handle?.setName(0===t?"shadow map highlight":"shadow map excluding highlight"),this._handle=null}copySnapshot(t){if(!this.enabled)return;const s=this._handle?.getTexture(R)?.descriptor;if(!s)return;this._snapshots[t]?.release();const e=0===t?"shadow map highlight":"shadow map excluding highlight",i=this._acquireFBO(e);this._snapshots[t]=i;const a=this._handle?.fbo;if(!a||!i?.fbo)return void console.error("No FBO");const{rctx:r}=this._fbos;r.blitFramebuffer(a,i.fbo,256)}getSnapshot(t){return this.enabled?this._snapshots[t]?.getTexture(R):null}clear(){this._ensureFbo(),this.bindFbo(),this._fbos.rctx.clear(256)}_computeTextureHeight({pixelRatio:t,fullWidth:s,fullHeight:e},i,a){const r=Math.min(window.devicePixelRatio,i)/t,h=a?this.settings.textureSizeModHighQuality:this.settings.textureSizeModLowQuality;return Q(Math.max(s,e)*r*h,this._maxTextureWidth/this._numCascades)}_ensureFbo(){this._handle?.fbo?.width===this._textureWidth&&this._handle?.fbo.height===this._textureHeight||(this._handle?.release(),this._handle=this._acquireFBO("shadow map"))}_acquireFBO(t){const s=this._fbos.acquire(this._textureWidth,this._textureHeight,t,12);return s.getTexture(R)?.setShadowFiltering(!0),s}_discardSnapshot(t){this._snapshots[t]=i(this._snapshots[t])}_discardSnapshots(){for(let t=0;t<this._snapshots.length;++t)this._discardSnapshot(t);this._snapshots.length=0}bindFbo(){this._fbos.rctx.bindFramebuffer(this._handle?.fbo)}_constructCascade(t,s,e,i){const a=this._cascades[t],o=-this._cascadeDistances[t],n=-this._cascadeDistances[t+1],c=(s[10]*o+s[14])/Math.abs(s[11]*o+s[15]),l=(s[10]*n+s[14])/Math.abs(s[11]*n+s[15]);B(c<l);for(let r=0;r<8;++r){D(I,r%4==0||r%4==3?-1:1,r%4==0||r%4==1?-1:1,r<4?c:l,1);const t=U[r];F(t,I,this._projectionViewInverse),t[0]/=t[3],t[1]/=t[3],t[2]/=t[3]}y(K,U[0]),a.camera.viewMatrix=r(A,this._modelViewLight,K);for(let r=0;r<8;++r)v(U[r],U[r],a.camera.viewMatrix);let d=U[0][2],m=U[0][2];for(let r=1;r<8;++r)d=Math.min(d,U[r][2]),m=Math.max(m,U[r][2]);d-=200,m+=200,a.camera.near=-m,a.camera.far=-d,pt(e,i,d,m,a.camera),h(a.lightMat,a.camera.projectionMatrix,a.camera.viewMatrix);const u=this._textureHeight;a.camera.viewport=[t*u,0,u,u]}_setupMatrices(t,s){h(this._projectionView,t.projectionMatrix,t.viewMatrix),o(this._projectionViewInverse,this._projectionView);const e=1===this._viewingMode?t.eye:S(K,0,0,1);n(this._modelViewLight,[0,0,0],[-s[0],-s[1],-s[2]],e)}_computeCascadeDistances(t,e,i){const a=i?this.settings.maxNumCascadesHighQuality:this.settings.maxNumCascadesLowQuality;this._numCascades=Math.min(1+Math.floor(L(e/t,4)),a);const r=(e-t)/this._numCascades,h=(e/t)**(1/this._numCascades);let o=t,n=t;for(let c=0;c<this._numCascades+1;++c)this._cascadeDistances[c]=s(o,n,this.settings.splitSchemeLambda),o*=h,n+=r}get test(){}}const A=l(),I=O(),U=[];for(let bt=0;bt<8;++bt)U.push(O());const P=M(),k=M(),E=M(),G=M(),J=M(),K=H(),X=[];function Y(){X.length=0}const Z=l(),$=c.concat(c,c,c),tt=M(),st=M(),et=[M(),M(),M(),M()],it=M(),at=M(),rt=M(),ht=M(),ot=M(),nt=M(),ct=M();function lt(t,s,e,i,a,r,h,o){d(tt,0,0);for(let d=0;d<4;++d)m(tt,tt,t[d]);u(tt,tt,.25),d(st,0,0);for(let d=4;d<8;++d)m(st,st,t[d]);u(st,st,.25),_(et[0],t[4],t[5],.5),_(et[1],t[5],t[6],.5),_(et[2],t[6],t[7],.5),_(et[3],t[7],t[4],.5);let n=0,c=f(et[0],tt);for(let d=1;d<4;++d){const t=f(et[d],tt);t<c&&(c=t,n=d)}g(it,et[n],t[n+4]);const l=it[0];let M,C;it[0]=-it[1],it[1]=l,g(at,st,tt),p(at,it)<0&&x(it,it),_(it,it,at,e),b(it,it),M=C=p(g(rt,t[0],tt),it);for(let d=1;d<8;++d){const s=p(g(rt,t[d],tt),it);s<M?M=s:s>C&&(C=s)}w(i,tt),u(rt,it,M-s),m(i,i,rt);let j=-1,y=1,v=0,S=0;for(let d=0;d<8;++d){g(ht,t[d],i),b(ht,ht);const s=it[0]*ht[1]-it[1]*ht[0];s>0?s>j&&(j=s,v=d):s<y&&(y=s,S=d)}V(j>0,"leftArea"),V(y<0,"rightArea"),u(ot,it,M),m(ot,ot,tt),u(nt,it,C),m(nt,nt,tt),ct[0]=-it[1],ct[1]=it[0];const H=N(i,t[S],nt,m(rt,nt,ct),1,a),D=N(i,t[v],nt,rt,1,r),F=N(i,t[v],ot,m(rt,ot,ct),1,h),O=N(i,t[S],ot,rt,1,o);V(H,"rayRay"),V(D,"rayRay"),V(F,"rayRay"),V(O,"rayRay")}function dt(t,s){return 3*s+t}const mt=M();function ut(t,s){return d(mt,t[s],t[s+3]),mt}const _t=M(),ft=a();function gt(t,s,e,i,a){g(_t,e,i),u(_t,_t,.5),ft[0]=_t[0],ft[1]=_t[1],ft[2]=0,ft[3]=_t[1],ft[4]=-_t[0],ft[5]=0,ft[6]=_t[0]*_t[0]+_t[1]*_t[1],ft[7]=_t[0]*_t[1]-_t[1]*_t[0],ft[8]=1,ft[dt(0,2)]=-p(ut(ft,0),t),ft[dt(1,2)]=-p(ut(ft,1),t);let r=p(ut(ft,0),e)+ft[dt(0,2)],h=p(ut(ft,1),e)+ft[dt(1,2)],o=p(ut(ft,0),i)+ft[dt(0,2)],n=p(ut(ft,1),i)+ft[dt(1,2)];r=-(r+o)/(h+n),ft[dt(0,0)]+=ft[dt(1,0)]*r,ft[dt(0,1)]+=ft[dt(1,1)]*r,ft[dt(0,2)]+=ft[dt(1,2)]*r,r=1/(p(ut(ft,0),e)+ft[dt(0,2)]),h=1/(p(ut(ft,1),e)+ft[dt(1,2)]),ft[dt(0,0)]*=r,ft[dt(0,1)]*=r,ft[dt(0,2)]*=r,ft[dt(1,0)]*=h,ft[dt(1,1)]*=h,ft[dt(1,2)]*=h,ft[dt(2,0)]=ft[dt(1,0)],ft[dt(2,1)]=ft[dt(1,1)],ft[dt(2,2)]=ft[dt(1,2)],ft[dt(1,2)]+=1,r=p(ut(ft,1),s)+ft[dt(1,2)],h=p(ut(ft,2),s)+ft[dt(2,2)],o=p(ut(ft,1),e)+ft[dt(1,2)],n=p(ut(ft,2),e)+ft[dt(2,2)],r=-.5*(r/h+o/n),ft[dt(1,0)]+=ft[dt(2,0)]*r,ft[dt(1,1)]+=ft[dt(2,1)]*r,ft[dt(1,2)]+=ft[dt(2,2)]*r,r=p(ut(ft,1),s)+ft[dt(1,2)],h=p(ut(ft,2),s)+ft[dt(2,2)],o=-h/r,ft[dt(1,0)]*=o,ft[dt(1,1)]*=o,ft[dt(1,2)]*=o,a[0]=ft[0],a[1]=ft[1],a[2]=0,a[3]=ft[2],a[4]=ft[3],a[5]=ft[4],a[6]=0,a[7]=ft[5],a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=ft[6],a[13]=ft[7],a[14]=0,a[15]=ft[8]}function pt(t,s,i,a,r){const h=1/U[0][3],o=1/U[4][3];B(h<o);let n=h+Math.sqrt(h*o);const c=Math.sin(e(t[2]*s[0]+t[6]*s[1]+t[10]*s[2]));n/=c,lt(U,n,c,P,k,E,G,J),gt(P,k,G,J,r.projectionMatrix),r.projectionMatrix[10]=2/(i-a),r.projectionMatrix[14]=-(i+a)/(i-a)}function xt(t){let{near:s,far:e}=t;return s<2&&(s=2),e<2&&(e=2),s>=e&&(s=2,e=4),{near:s,far:e}}export{z as ShadowMap,Y as cleanupShadowmap};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import has from"../../../../core/has.js";import{clamp as t}from"../../../../core/mathUtils.js";import{releaseMaybe as e}from"../../../../core/maybe.js";import{fromRotation as i}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{sub as r,add as o,negate as a,transformMat4 as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{applyTextureResizeModulo as n}from"./textureUtils.js";import{ViewshedFaceCamera as l}from"./ViewshedFaceCamera.js";import{DepthStencilAttachment as u,SizedDepthFormat as m}from"../../../webgl/enums.js";import{isSizedDepthStencilFormat as f}from"../../../webgl/textureUtils.js";class d{constructor(){this.textureSizeQuality=1,this.textureSizeModHighQuality=1.3,this.textureSizeModLowQuality=.9,this.textureSizeMultiple=128,this.toleranceSides=5,this.toleranceBottomTop=10}textureSizeModifier(t){const e=t?this.textureSizeModHighQuality:this.textureSizeModLowQuality;return this.textureSizeQuality*e}textureResizeModulo(t){return Math.ceil(t/this.textureSizeMultiple)*this.textureSizeMultiple}}const p=["front","left","right","back","top","bottom"];function g(t){return!["top","bottom"].includes(t)}class x{constructor(t){this._fbos=t,this._faces={},this._width=0,this._height=0,this.settings=new d,this._maxTextureSize=Math.min(has("esri-mobile")?4096:16384,t.rctx.parameters.maxTextureSize)}get depthTexture(){return this._handle?.getTexture(u)}get ready(){return null!=this.depthTexture&&0!==this._width&&0!==this._height}get nearFar(){const t=this.faces;return 0===t.length?null:t[0].nearFar}get numActiveFaces(){const t=this._faces;let e=0;return Object.keys(t).forEach(i=>{t[i]&&(e+=1)}),e}get faces(){const t=this._faces,e=[];for(const i of p){const s=t[i];s&&e.push(s)}return e}get atlasRegions(){return this.faces.map(t=>[t.x/this._width,(t.x+t.width)/this._width,t.y/this._height,(t.y+t.height)/this._height])}get viewshedProjectionMatrices(){return this.faces.map(t=>t.projectionMatrix)}get viewshedViewMatrices(){return this.faces.map(t=>t.viewMatrix)}_setupFaceCamera(e,n,u,m){const{effectiveObserverRenderSpace:f,tiltedUpVector:d,targetRenderSpace:p,farDistanceRenderSpace:x,horizontalFieldOfView:_,verticalFieldOfView:b}=n,w=c();r(w,p,f);const M=c(),S=c(),F=(t,e)=>{const r=c(),a=s();return i(a,t,e),h(r,w,a),o(r,f,r),r};let z,T=d;const v=Math.min(90,_),O=Math.min(90,Math.max(0,(_-90)/2));let j=-45,B=45,y=-45,k=45;if(g(e)){const e=e=>t(e,-45,45);y=e(-b/2)-this.settings.toleranceBottomTop,k=e(+b/2)+this.settings.toleranceBottomTop}switch(e){case"front":z=p,j=-v/2,B=v/2;break;case"left":z=F(Math.PI/2,d),j=45-O;break;case"right":z=F(-Math.PI/2,d),B=-45+O;break;case"top":z=o(M,f,d),T=a(S,w);break;case"bottom":z=r(M,f,d),T=w;break;case"back":z=F(Math.PI,d)}const V=new l({center:z,eye:f,up:T,far:x});V.sectionAnglesDeg=[j-this.settings.toleranceSides,B+this.settings.toleranceSides,y,k],V.fovY=Math.PI/2;const P=V.setViewport(u,m);return this._faces[e]=V,P}isActive(t){return this._computeActiveFaces(t).size>0}_computeActiveFaces(t){const e=new Set,{horizontalFieldOfView:i,verticalFieldOfView:s}=t,r=-s/2,o=s/2;return 0===i||0===s||(r<=45&&o>=-45&&e.add("front"),i>90&&(e.add("left"),e.add("right")),i>270&&e.add("back"),o>45-this.settings.toleranceBottomTop&&e.add("top"),r<-45+this.settings.toleranceBottomTop&&e.add("bottom")),e}_computeBaseTextureSize({pixelRatio:t,fullWidth:e,fullHeight:i},s,r,o){const a=s/t,h=this.settings.textureSizeModifier(r);return n(Math.max(e,i)*a*h,this._maxTextureSize/o)}_ensureFBO(t){const e=this._width,i=this._height,s=this._handle?.fbo;s&&s.width===e&&s.height===i&&t===f(s.depthStencilTexture?.descriptor?.internalFormat??m.DEPTH_COMPONENT16)||(this._handle?.release(),this._handle=this._allocateFBO(t))}_allocateFBO(t){const{_width:e,_height:i}=this,s=t?14:13,r=this._fbos.acquire(e,i,"viewshed shadow map",s);return r.getTexture(u)?.setShadowFiltering(!1),r}clearFBO(t){const e=this._fbos.rctx;this._ensureFBO(t),e.bindFramebuffer(this._handle?.fbo),e.setClearColor(1,1,1,1),e.clear(16640)}dispose(){this._debugFBO||(this._handle=e(this._handle))}start(t,e,i,s,r=!1){this._faces={};const o=this._computeActiveFaces(e),a=o.size;if(0===a)return!1;const h=this._computeBaseTextureSize(t,s,i,a);let c=0,n=0,l=0;return p.filter(t=>o.has(t)).forEach(t=>{const i=_(t,a);i>n&&(l=Math.max(l,c),c=0),n=i;const s=i*h;c+=this._setupFaceCamera(t,e,[c,s],h)}),l=Math.max(l,c),this._width=this.settings.textureResizeModulo(l),this._height=b(a)*h,this.clearFBO(r),!0}finish(){}get test(){}}function _(t,e){if(e<4)return 0;const i="front"===t||"left"===t;return 4===e?i?0:1:i||"right"===t?0:1}function b(t){return t<4?1:2}export{x as ViewshedShadowMap};
2
+ import has from"../../../../core/has.js";import{clamp as t}from"../../../../core/mathUtils.js";import{releaseMaybe as e}from"../../../../core/maybe.js";import{fromRotation as i}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{sub as r,add as o,negate as a,transformMat4 as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{applyTextureResizeModulo as n}from"./textureUtils.js";import{ViewshedFaceCamera as l}from"./ViewshedFaceCamera.js";import{DepthStencilAttachment as u,SizedDepthFormat as m}from"../../../webgl/enums.js";import{isSizedDepthStencilFormat as f}from"../../../webgl/textureUtils.js";class d{constructor(){this.textureSizeQuality=1,this.textureSizeModHighQuality=1.3,this.textureSizeModLowQuality=.9,this.textureSizeMultiple=128,this.toleranceSides=5,this.toleranceBottomTop=10}textureSizeModifier(t){const e=t?this.textureSizeModHighQuality:this.textureSizeModLowQuality;return this.textureSizeQuality*e}textureResizeModulo(t){return Math.ceil(t/this.textureSizeMultiple)*this.textureSizeMultiple}}const p=["front","left","right","back","top","bottom"];function g(t){return!["top","bottom"].includes(t)}class x{constructor(t){this._fbos=t,this._faces={},this._width=0,this._height=0,this.settings=new d,this._maxTextureSize=Math.min(has("esri-mobile")?4096:16384,t.rctx.parameters.maxTextureSize)}get depthTexture(){return this._handle?.getTexture(u)}get ready(){return null!=this.depthTexture&&0!==this._width&&0!==this._height}get nearFar(){const t=this.faces;return 0===t.length?null:t[0].nearFar}get numActiveFaces(){const t=this._faces;let e=0;return Object.keys(t).forEach(i=>{t[i]&&(e+=1)}),e}get faces(){const t=this._faces,e=[];for(const i of p){const s=t[i];s&&e.push(s)}return e}get atlasRegions(){return this.faces.map(t=>[t.x/this._width,(t.x+t.width)/this._width,t.y/this._height,(t.y+t.height)/this._height])}get viewshedProjectionMatrices(){return this.faces.map(t=>t.projectionMatrix)}get viewshedViewMatrices(){return this.faces.map(t=>t.viewMatrix)}_setupFaceCamera(e,n,u,m){const{effectiveObserverRenderSpace:f,tiltedUpVector:d,targetRenderSpace:p,farDistanceRenderSpace:x,horizontalFieldOfView:_,verticalFieldOfView:b}=n,w=c();r(w,p,f);const M=c(),S=c(),F=(t,e)=>{const r=c(),a=s();return i(a,t,e),h(r,w,a),o(r,f,r),r};let z,T=d;const v=Math.min(90,_),O=Math.min(90,Math.max(0,(_-90)/2));let j=-45,B=45,y=-45,k=45;if(g(e)){const e=e=>t(e,-45,45);y=e(-b/2)-this.settings.toleranceBottomTop,k=e(+b/2)+this.settings.toleranceBottomTop}switch(e){case"front":z=p,j=-v/2,B=v/2;break;case"left":z=F(Math.PI/2,d),j=45-O;break;case"right":z=F(-Math.PI/2,d),B=-45+O;break;case"top":z=o(M,f,d),T=a(S,w);break;case"bottom":z=r(M,f,d),T=w;break;case"back":z=F(Math.PI,d)}const V=new l({center:z,eye:f,up:T,far:x});V.sectionAnglesDeg=[j-this.settings.toleranceSides,B+this.settings.toleranceSides,y,k],V.fovY=Math.PI/2;const P=V.setViewport(u,m);return this._faces[e]=V,P}isActive(t){return this._computeActiveFaces(t).size>0}_computeActiveFaces(t){const e=new Set,{horizontalFieldOfView:i,verticalFieldOfView:s}=t,r=-s/2,o=s/2;return 0===i||0===s||(r<=45&&o>=-45&&e.add("front"),i>90&&(e.add("left"),e.add("right")),i>270&&e.add("back"),o>45-this.settings.toleranceBottomTop&&e.add("top"),r<-45+this.settings.toleranceBottomTop&&e.add("bottom")),e}_computeBaseTextureSize({pixelRatio:t,fullWidth:e,fullHeight:i},s,r,o){const a=s/t,h=this.settings.textureSizeModifier(r);return n(Math.max(e,i)*a*h,this._maxTextureSize/o)}_ensureFBO(t){const e=this._width,i=this._height,s=this._handle?.fbo;s&&s.width===e&&s.height===i&&t===f(s.depthStencilTexture?.descriptor?.internalFormat??m.DEPTH_COMPONENT16)||(this._handle?.release(),this._handle=this._allocateFBO(t))}_allocateFBO(t){const{_width:e,_height:i}=this,s=t?13:12,r=this._fbos.acquire(e,i,"viewshed shadow map",s);return r.getTexture(u)?.setShadowFiltering(!1),r}clearFBO(t){const e=this._fbos.rctx;this._ensureFBO(t),e.bindFramebuffer(this._handle?.fbo),e.setClearColor(1,1,1,1),e.clear(16640)}dispose(){this._debugFBO||(this._handle=e(this._handle))}start(t,e,i,s,r=!1){this._faces={};const o=this._computeActiveFaces(e),a=o.size;if(0===a)return!1;const h=this._computeBaseTextureSize(t,s,i,a);let c=0,n=0,l=0;return p.filter(t=>o.has(t)).forEach(t=>{const i=_(t,a);i>n&&(l=Math.max(l,c),c=0),n=i;const s=i*h;c+=this._setupFaceCamera(t,e,[c,s],h)}),l=Math.max(l,c),this._width=this.settings.textureResizeModulo(l),this._height=b(a)*h,this.clearFBO(r),!0}finish(){}get test(){}}function _(t,e){if(e<4)return 0;const i="front"===t||"left"===t;return 4===e?i?0:1:i||"right"===t?0:1}function b(t){return t<4?1:2}export{x as ViewshedShadowMap};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{set as t,add as e,scale as r,dist as n}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{areaPoints3d as i}from"../../../../geometry/support/triangle.js";function s(n,o){if(!n)return!1;const{size:s,data:c,indices:f}=n;t(o,0,0,0),t(u,0,0,0);let g=0,d=0;for(let p=0;p<f.length-2;p+=3){const n=f[p]*s,h=f[p+1]*s,j=f[p+2]*s;t(l,c[n],c[n+1],c[n+2]),t(a,c[h],c[h+1],c[h+2]),t(m,c[j],c[j+1],c[j+2]);const x=i(l,a,m);x?(e(l,l,a),e(l,l,m),r(l,l,1/3*x),e(o,o,l),g+=x):(e(u,u,l),e(u,u,a),e(u,u,m),d+=3)}return(0!==d||0!==g)&&(0!==g?(r(o,o,1/g),!0):0!==d&&(r(o,u,1/d),!0))}function c(e,n){if(!e)return!1;const{size:o,data:i,indices:s}=e;t(n,0,0,0);let c=-1,f=0;for(let t=0;t<s.length;t++){const e=s[t]*o;c!==e&&(n[0]+=i[e],n[1]+=i[e+1],n[2]+=i[e+2],f++),c=e}return f>1&&r(n,n,1/f),f>0}function f(o,i,s){if(!o)return!1;t(s,0,0,0),t(u,0,0,0);let c=0,f=0;const{size:m,data:g,indices:d}=o,p=d.length-1,h=p+(i?2:0);for(let t=0;t<h;t+=2){const o=t<p?t+1:0,i=d[t<p?t:p]*m,h=d[o]*m;l[0]=g[i],l[1]=g[i+1],l[2]=g[i+2],a[0]=g[h],a[1]=g[h+1],a[2]=g[h+2],r(l,e(l,l,a),.5);const j=n(l,a);j>0?(e(s,s,r(l,l,j)),c+=j):0===c&&(e(u,u,l),f++)}return 0!==c?(r(s,s,1/c),!0):0!==f&&(r(s,u,1/f),!0)}const l=o(),a=o(),m=o(),u=o();export{f as computeAttachmentOriginLines,c as computeAttachmentOriginPoints,s as computeAttachmentOriginTriangles};
2
+ import{set as t,add as e,scale as r,dist as n}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as o}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{areaPoints3d as i}from"../../../../geometry/support/triangle.js";function s(n,o,s=o?.indices){if(!o||!s)return!1;const{size:c,data:f}=o;t(n,0,0,0),t(u,0,0,0);let g=0,d=0;for(let p=0;p<s.length-2;p+=3){const o=s[p]*c,h=s[p+1]*c,j=s[p+2]*c;t(l,f[o],f[o+1],f[o+2]),t(a,f[h],f[h+1],f[h+2]),t(m,f[j],f[j+1],f[j+2]);const x=i(l,a,m);x?(e(l,l,a),e(l,l,m),r(l,l,1/3*x),e(n,n,l),g+=x):(e(u,u,l),e(u,u,a),e(u,u,m),d+=3)}return(0!==d||0!==g)&&(0!==g?(r(n,n,1/g),!0):0!==d&&(r(n,u,1/d),!0))}function c(e,n,o=n?.indices){if(!n||!o)return!1;const{size:i,data:s}=n;t(e,0,0,0);let c=-1,f=0;for(let t=0;t<o.length;t++){const r=o[t]*i;c!==r&&(e[0]+=s[r],e[1]+=s[r+1],e[2]+=s[r+2],f++),c=r}return f>1&&r(e,e,1/f),f>0}function f(o,i,s,c=i?.indices){if(!i||!c)return!1;t(o,0,0,0),t(u,0,0,0);let f=0,m=0;const{size:g,data:d}=i,p=c.length-1,h=p+(s?2:0);for(let t=0;t<h;t+=2){const i=t<p?t+1:0,s=c[t<p?t:p]*g,h=c[i]*g;l[0]=d[s],l[1]=d[s+1],l[2]=d[s+2],a[0]=d[h],a[1]=d[h+1],a[2]=d[h+2],r(l,e(l,l,a),.5);const j=n(l,a);j>0?(e(o,o,r(l,l,j)),f+=j):0===f&&(e(u,u,l),m++)}return 0!==f?(r(o,o,1/f),!0):0!==m&&(r(o,u,1/m),!0)}const l=o(),a=o(),m=o(),u=o();export{f as computeAttachmentOriginLines,c as computeAttachmentOriginPoints,s as computeAttachmentOriginTriangles};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{ZEROS as t}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isColorOrOLID as e,isDepth as r,is2DGeometryOutput as s,isColor as i}from"../core/shaderLibrary/ShaderOutput.js";import a from"../lib/GLMaterial.js";import{DefaultBufferWriter as o}from"./DefaultBufferWriter.js";import{TriangleMaterial as n}from"./TriangleMaterial.js";import{VisualVariablePassParameters as h}from"./VisualVariablePassParameters.js";import{getLayout as p,ColorMaterialTechnique as u}from"../shaders/ColorMaterialTechnique.js";import{ColorMaterialTechniqueConfiguration as c}from"../shaders/ColorMaterialTechniqueConfiguration.js";import{alphaCutoff as l}from"../../../../webscene/support/AlphaCutoff.js";class f extends n{constructor(t){super(t,g),this._configuration=new c,this.supportsEdges=!0,this.produces=new Map([[2,t=>this._isOpaqueMaterialPass(t)],[3,t=>this._isOpaqueNoSSAODepthPass(t)],[4,t=>e(t)&&this._transparent&&this.parameters.writeDepth],[5,t=>r(t)&&this._transparent&&this.parameters.writeDepth],[9,t=>e(t)&&this._transparent&&!this.parameters.writeDepth],[20,t=>s(t)]])}getConfiguration(t,e){return super.getConfiguration(t,e,this._configuration),this._configuration.cullFace=this.parameters.cullFace,this._configuration.hasVertexColors=this.parameters.hasVertexColors&&!this.parameters.vvColor,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.transparent=this._transparent,this._configuration.discardInvisibleFragments=this._transparent&&!this._isOpaquePass(t)&&this.parameters.discardInvisibleFragments,this._configuration.polygonOffset=this.parameters.polygonOffset,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.hasOccludees=e.hasOccludees,this._configuration.enableOffset=e.enableOffset,this._configuration.terrainDepthTest=e.terrainDepthTest&&i(t),this._configuration.cullAboveTerrain=e.cullAboveTerrain,this._configuration.hasVVColor=!!this.parameters.vvColor,this._configuration.draped=this.parameters.draped,this._configuration.emissionSource=this.hasEmissions?1:0,this._configuration}get visible(){return this.parameters.color[3]>=l}get _transparent(){return this.parameters.color[3]<1||this.parameters.forceTransparentMode}get hasEmissions(){return this.parameters.emissiveStrength>0}_isOpaquePass(t){return i(t)||this._isOpaqueMaterialPass(t)||this._isOpaqueNoSSAODepthPass(t)}_isOpaqueMaterialPass(t){return 8===t||e(t)&&!this._transparent}_isOpaqueNoSSAODepthPass(t){return r(t)&&this.parameters.writeDepth&&!this._transparent}createGLMaterial(t){return new m(t)}createBufferWriter(){return new o(p(this.parameters))}}class m extends a{beginSlot(t){return this.getTechnique(u,t)}}class g extends h{constructor(){super(...arguments),this.color=t,this.forceTransparentMode=!1,this.writeDepth=!0,this.hasVertexColors=!1,this.polygonOffset=!1,this.hasSlicePlane=!1,this.cullFace=0,this.draped=!1,this.discardInvisibleFragments=!1,this.emissiveStrength=0}}export{f as ColorMaterial,g as Parameters};
2
+ import{ZEROS as t}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isColorOrOLID as e,isDepth as s,is2DGeometryOutput as r,isColor as i}from"../core/shaderLibrary/ShaderOutput.js";import a from"../lib/GLMaterial.js";import{DefaultBufferWriter as n}from"./DefaultBufferWriter.js";import{TriangleMaterial as o}from"./TriangleMaterial.js";import{VisualVariablePassParameters as h}from"./VisualVariablePassParameters.js";import{getLayout as p,ColorMaterialTechnique as u}from"../shaders/ColorMaterialTechnique.js";import{ColorMaterialTechniqueConfiguration as c}from"../shaders/ColorMaterialTechniqueConfiguration.js";import{alphaCutoff as l}from"../../../../webscene/support/AlphaCutoff.js";class f extends o{constructor(t){super(t,g),this._configuration=new c,this.supportsEdges=!0,this.produces=new Map([[2,t=>this._isOpaqueMaterialPass(t)],[3,t=>this._isOpaqueNoSSAODepthPass(t)],[4,t=>e(t)&&this._transparent&&this.parameters.writeDepth],[5,t=>s(t)&&this._transparent&&this.parameters.writeDepth],[9,t=>e(t)&&this._transparent&&!this.parameters.writeDepth],[20,t=>r(t)]])}getConfiguration(t,e){return super.getConfiguration(t,e,this._configuration),this._configuration.cullFace=this.parameters.cullFace,this._configuration.hasVertexColors=this.parameters.hasVertexColors&&!this.parameters.vvColor,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.transparent=this._transparent,this._configuration.discardInvisibleFragments=this._transparent&&!this._isOpaquePass(t)&&this.parameters.discardInvisibleFragments,this._configuration.polygonOffset=this.parameters.polygonOffset,this._configuration.writeDepth=this.parameters.writeDepth,this._configuration.hasOccludees=e.hasOccludees,this._configuration.enableOffset=e.enableOffset,this._configuration.terrainDepthTest=e.terrainDepthTest&&i(t),this._configuration.cullAboveTerrain=e.cullAboveTerrain,this._configuration.hasVVColor=!!this.parameters.vvColor,this._configuration.draped=this.parameters.draped,this._configuration.emissionSource=this.hasEmissions?1:0,this._configuration}get visible(){return this.parameters.color[3]>=l}get _transparent(){return this.parameters.color[3]<1||this.parameters.forceTransparentMode}get hasEmissions(){return this.parameters.emissiveStrength>0}_isOpaquePass(t){return i(t)||this._isOpaqueMaterialPass(t)||this._isOpaqueNoSSAODepthPass(t)}_isOpaqueMaterialPass(t){return 8===t||e(t)&&!this._transparent}_isOpaqueNoSSAODepthPass(t){return s(t)&&this.parameters.writeDepth&&!this._transparent}createGLMaterial(t){return new m(t)}createBufferWriter(){return new n(p(this.parameters))}}class m extends a{beginSlot(t){return this.getTechnique(u,t)}}class g extends h{constructor(){super(...arguments),this.color=t,this.forceTransparentMode=!1,this.writeDepth=!0,this.hasVertexColors=!1,this.polygonOffset=!1,this.hasSlicePlane=!1,this.cullFace=0,this.draped=!1,this.discardInvisibleFragments=!1,this.emissiveStrength=0,this.useIndexing=!1}}export{f as ColorMaterial,g as Parameters};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{IDENTITY as e}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as t}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{BufferViewVec4f as r,BufferViewUint32 as s,BufferViewMat3f as i,BufferViewVec4u8 as o,BufferViewFloat as n}from"../../../../geometry/support/buffer/BufferView.js";import{isHighlightOrOLID as a,isColor as u,isDepth as l,isColorHighlightOrOLID as f}from"../core/shaderLibrary/ShaderOutput.js";import c from"../lib/GLMaterial.js";import{assert as h}from"../lib/Util.js";import{DefaultBufferWriter as p}from"./DefaultBufferWriter.js";import{TriangleMaterial as m}from"./TriangleMaterial.js";import{VisualVariablePassParameters as g}from"./VisualVariablePassParameters.js";import{writeAttributes as d,writeBufferVec4 as b,writeColor as x,writeVVFeatureAttribute as y}from"./internal/bufferWriterUtils.js";import{getLayout as j,getTextureLayout as _}from"../shaders/PatternLayouts.js";import{PatternTechnique as v}from"../shaders/PatternTechnique.js";import{PatternTechniqueConfiguration as C}from"../shaders/PatternTechniqueConfiguration.js";import{alphaCutoff as w}from"../../../../webscene/support/AlphaCutoff.js";class B extends m{constructor(e){super(e,P),this._configuration=new C,this.supportsEdges=!0,this.produces=new Map([[2,e=>a(e)],[4,e=>u(e)],[5,e=>l(e)],[20,e=>this.parameters.draped&&f(e)]])}getConfiguration(e,t){return super.getConfiguration(e,t,this._configuration),this._configuration.cullFace=this.parameters.cullFace,this._configuration.hasVertexColors=this.parameters.hasVertexColors&&!this.parameters.vvColor,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.polygonOffset=this.parameters.polygonOffset,this._configuration.style=this.parameters.style,this._configuration.draped=this.parameters.draped,this._configuration.enableOffset=t.enableOffset,this._configuration.terrainDepthTest=t.terrainDepthTest&&u(e),this._configuration.cullAboveTerrain=t.cullAboveTerrain,this._configuration.hasVVColor=!!this.parameters.vvColor,this._configuration.emissionSource=this.hasEmissions?1:0,this._configuration}get visible(){return this.parameters.color[3]>=w}get hasEmissions(){return this.parameters.emissiveStrength>0}createGLMaterial(e){return new F(e)}createBufferWriter(){return new S(j(this.parameters),_(this.parameters))}}class F extends c{beginSlot(e){return this.getTechnique(v,e)}}class S extends p{constructor(e,t){super(e),this.textureBufferLayout=t}elementCountTextureBuffer(e){return e.get("boundingRect")?.indices.length??0}write(e,t,i,o,n,a,u){const l=d(i,o,this.layout,e,t,n,a);for(const s of this.layout.fields.keys()){const e=i.get(s),t=e?.indices;if(e&&t)switch(s){case"uvMapSpace":{h(4===e.size);const t=n.getField(s,r);t&&b(e,t,a);break}}}const{textureBufferLayout:f}=this;if(null==f)return l;h(null!=u,"Using a texture layout, but the texture range for this instance was not provided");const c=u.from;h(1===u.numElements,"Provided more than one texture buffer element per polygon");const p=n.getField("textureElementIndex",s);h(null!=p,"Missing component index field");const m=i.get("position")?.indices.length??0;for(let r=0;r<m;++r)p.set(a+r,c);return l}writeTextureBuffer(t,r,s,a,u){const{textureBufferLayout:l}=this;if(null==l)return;const f=a.getField("boundingRect",i),c=s.get("boundingRect");f&&c&&(h(9===c.size),T(c,t??e,f,u));const p=a.getField("color",o),m=s.get("color");p&&m&&(h(3===m.size||4===m.size),x(m,m.size,p,u));const g=a.getField("colorFeatureAttribute",n),d=s.get("colorFeatureAttribute");g&&d&&(h(1===d.size),y(d,g,u))}}function T(e,t,r,s){const{data:i,indices:o}=e,n=t,a=r.typedBuffer,u=r.typedBufferStride,l=o.length;s*=u;for(let f=0;f<l;++f){const e=9*o[f],t=i[e],r=i[e+1],l=i[e+2];a[s]=n[0]*t+n[4]*r+n[8]*l+n[12],a[s+1]=n[1]*t+n[5]*r+n[9]*l+n[13],a[s+2]=n[2]*t+n[6]*r+n[10]*l+n[14];for(let o=3;o<9;++o)a[s+o]=i[e+o];s+=u}}class P extends g{constructor(){super(...arguments),this.color=t(1,1,1,1),this.emissiveStrength=0,this.hasVertexColors=!1,this.polygonOffset=!1,this.hasSlicePlane=!1,this.cullFace=0,this.hasOccludees=!1,this.style=2,this.draped=!0}}export{P as Parameters,B as PatternMaterial};
2
+ import{IDENTITY as e}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as t}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{BufferViewVec4f as r,BufferViewUint32 as s,BufferViewMat3f as i,BufferViewVec4u8 as o,BufferViewFloat as n}from"../../../../geometry/support/buffer/BufferView.js";import{isHighlightOrOLID as a,isColor as u,isDepth as l,isColorHighlightOrOLID as f}from"../core/shaderLibrary/ShaderOutput.js";import c from"../lib/GLMaterial.js";import{assert as h}from"../lib/Util.js";import{DefaultBufferWriter as p}from"./DefaultBufferWriter.js";import{TriangleMaterial as m}from"./TriangleMaterial.js";import{VisualVariablePassParameters as g}from"./VisualVariablePassParameters.js";import{writeAttributes as d,writeBufferVec4 as b,writeColor as x,writeVVFeatureAttribute as y}from"./internal/bufferWriterUtils.js";import{getLayout as j,getTextureLayout as _}from"../shaders/PatternLayouts.js";import{PatternTechnique as v}from"../shaders/PatternTechnique.js";import{PatternTechniqueConfiguration as C}from"../shaders/PatternTechniqueConfiguration.js";import{alphaCutoff as w}from"../../../../webscene/support/AlphaCutoff.js";class B extends m{constructor(e){super(e,P),this._configuration=new C,this.supportsEdges=!0,this.produces=new Map([[2,e=>a(e)],[4,e=>u(e)],[5,e=>l(e)],[20,e=>this.parameters.draped&&f(e)]])}getConfiguration(e,t){return super.getConfiguration(e,t,this._configuration),this._configuration.cullFace=this.parameters.cullFace,this._configuration.hasVertexColors=this.parameters.hasVertexColors&&!this.parameters.vvColor,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.polygonOffset=this.parameters.polygonOffset,this._configuration.style=this.parameters.style,this._configuration.draped=this.parameters.draped,this._configuration.enableOffset=t.enableOffset,this._configuration.terrainDepthTest=t.terrainDepthTest&&u(e),this._configuration.cullAboveTerrain=t.cullAboveTerrain,this._configuration.hasVVColor=!!this.parameters.vvColor,this._configuration.emissionSource=this.hasEmissions?1:0,this._configuration}get visible(){return this.parameters.color[3]>=w}get hasEmissions(){return this.parameters.emissiveStrength>0}createGLMaterial(e){return new F(e)}createBufferWriter(){return new S(j(this.parameters),_(this.parameters))}}class F extends c{beginSlot(e){return this.getTechnique(v,e)}}class S extends p{constructor(e,t){super(e),this.textureBufferLayout=t}elementCountTextureBuffer(e){return e.get("boundingRect")?.indices.length??0}write(e,t,i,o,n,a,u){const l=d(i,o,this.layout,e,t,n,a);for(const s of this.layout.fields.keys()){const e=i.get(s),t=e?.indices;if(e&&t)switch(s){case"uvMapSpace":{h(4===e.size);const t=n.getField(s,r);t&&b(e,t,a);break}}}const{textureBufferLayout:f}=this;if(null==f)return l;h(null!=u,"Using a texture layout, but the texture range for this instance was not provided");const c=u.from;h(1===u.numElements,"Provided more than one texture buffer element per polygon");const p=n.getField("textureElementIndex",s);h(null!=p,"Missing component index field");const m=i.get("position")?.indices.length??0;for(let r=0;r<m;++r)p.set(a+r,c);return l}writeTextureBuffer(t,r,s,a,u){const{textureBufferLayout:l}=this;if(null==l)return;const f=a.getField("boundingRect",i),c=s.get("boundingRect");f&&c&&(h(9===c.size),T(c,t??e,f,u));const p=a.getField("color",o),m=s.get("color");p&&m&&(h(3===m.size||4===m.size),x(m,m.size,p,u));const g=a.getField("colorFeatureAttribute",n),d=s.get("colorFeatureAttribute");g&&d&&(h(1===d.size),y(d,g,u))}}function T(e,t,r,s){const{data:i,indices:o}=e,n=t,a=r.typedBuffer,u=r.typedBufferStride,l=o.length;s*=u;for(let f=0;f<l;++f){const e=9*o[f],t=i[e],r=i[e+1],l=i[e+2];a[s]=n[0]*t+n[4]*r+n[8]*l+n[12],a[s+1]=n[1]*t+n[5]*r+n[9]*l+n[13],a[s+2]=n[2]*t+n[6]*r+n[10]*l+n[14];for(let o=3;o<9;++o)a[s+o]=i[e+o];s+=u}}class P extends g{constructor(){super(...arguments),this.color=t(1,1,1,1),this.emissiveStrength=0,this.hasVertexColors=!1,this.polygonOffset=!1,this.hasSlicePlane=!1,this.cullFace=0,this.hasOccludees=!1,this.style=2,this.draped=!0,this.useIndexing=!0}}export{P as Parameters,B as PatternMaterial};
@@ -0,0 +1,2 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ import{BufferCache as e}from"./BufferCache.js";import{getStrideForDataType as r}from"./IndexLayout.js";import{BufferObject as t}from"../../../../webgl/BufferObject.js";import{DataType as s}from"../../../../webgl/enums.js";class c{constructor(r){this._cache=new e(r.newCache,e=>{const c=t.createIndex(r,35044);return c.setSize(e,s.UNSIGNED_BYTE),c},"IndexBufferCache")}dispose(){this._cache.dispose()}newIndexBuffer(e,t){const s=r(t)*e,c=this._cache.newBuffer(s);return c.setIndexType(t),c}deleteIndexBuffer(e){this._cache.deleteBuffer(e)}}export{c as IndexBufferCache};
@@ -0,0 +1,2 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ import{assert as r}from"../../lib/Util.js";import{DataType as t}from"../../../../webgl/enums.js";class e{constructor(r){this.bufferConstructor=r,this.dataType=r===Uint8Array?t.UNSIGNED_BYTE:r===Uint16Array?t.UNSIGNED_SHORT:t.UNSIGNED_INT}get stride(){return this.bufferConstructor.BYTES_PER_ELEMENT}createView(r,t){return new this.bufferConstructor(r,t)}}const n=new e(Uint8Array),i=new e(Uint16Array),s=new e(Uint32Array);function u(e){switch(e){case t.UNSIGNED_BYTE:return n;case t.UNSIGNED_SHORT:return i;case t.UNSIGNED_INT:case void 0:case null:return s;default:r(!1,`Invalid dataType ${e}`)}}function a(r){return u(r).stride}function o(r){return null==r?s:r<255?n:r<65535?i:s}export{e as IndexLayout,u as getIndexLayoutForDataType,o as getIndexLayoutForMaxIndex,a as getStrideForDataType};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- class t{constructor(t,i,h){this.geometry=t,this.targetRanges=i,this._highlightName=null,this.updateHighlightOptions(h)}updateHighlightOptions(t){const{geometry:i}=this;if(!i.hasHighlights)return void(this._highlightName=null);let h=-1,e=null;i.foreachHighlightOptions(i=>{const s=t.get(i)??-1;s>h&&(h=s,e=i)}),this._highlightName=e}get highlightName(){return this._highlightName}get isVisible(){return this.geometry.visible}get hasHighlights(){return this.isVisible&&this.geometry.hasHighlights}get hasOccludees(){return null!=this.geometry.occludees}}export{t as Instance};
2
+ class t{constructor(t,i,e,h){this.geometry=t,this.targetRanges=i,this.drawRangeTarget=h,this._highlightName=null,this.updateHighlightOptions(e)}updateHighlightOptions(t){const{geometry:i}=this;if(!i.hasHighlights)return void(this._highlightName=null);let e=-1,h=null;i.foreachHighlightOptions(i=>{const g=t.get(i)??-1;g>e&&(e=g,h=i)}),this._highlightName=h}get highlightName(){return this._highlightName}get isVisible(){return this.geometry.visible}get hasHighlights(){return this.isVisible&&this.geometry.hasHighlights}get hasOccludees(){return null!=this.geometry.occludees}get drawRange(){return this.targetRanges[this.drawRangeTarget]}}export{t as Instance};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import{removeUnordered as s,filterInPlace as o}from"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import{getOrCreateMapValue as n}from"../../../../../core/MapUtils.js";import{NestedMap as r}from"../../../../../core/NestedMap.js";import{nullUid as a}from"../../../../../core/uid.js";import{property as i,subclass as c}from"../../../../../core/accessorSupport/decorators.js";import{assert as l}from"../../lib/Util.js";import{bufferRangePool as f,mergeAdjacentRanges as u}from"./BufferRange.js";import{Instance as d}from"./Instance.js";import{PerBaseInstanceData as h}from"./PerBaseInstanceData.js";import{PerBufferData as m,hasVao as p}from"./PerBufferData.js";import{PerOriginData as g}from"./PerOriginData.js";import{VaoWriter as y}from"./VaoWriter.js";let v=class extends t{constructor(e){super(e),this._vaoWriter=null,this._useMetalWorkaround=!1,this._hasOccludees=!1}destroy(){for(const e of this.dataByBaseInstance.values()){for(const t of e.dataByOrigin.values())for(const e of t.buffers)this._vaoWriter?.deleteBuffer(e);e.dispose()}this.dataByBaseInstance.clear(),this.uninitializeRenderContext()}initializeRenderContext(e){this._useMetalWorkaround=e.renderContext.rctx.isAssumedMetalDriver,this._vaoWriter=new y(this.material,e.renderContext.rctx)}uninitializeRenderContext(){this._useMetalWorkaround=!1,this._vaoWriter=null}get hasOccludees(){return this._hasOccludees}modify(e,t){this._applyUpdates(e,t),this._applyAddsAndRemoves(e),this._updateDrawCommands()}get canCompact(){for(const e of this.dataByBaseInstance.values())for(const t of e.dataByOrigin.values())if(t.buffers.some(e=>e.holes.geometry.length>1))return!0;return!1}compact(e){if(!this.canCompact)return!1;let t=!1;for(const o of this.dataByBaseInstance.values())for(const n of o.dataByOrigin.values()){const r=new Array;for(let t=0;t<n.buffers.length&&!e.done;){const o=n.buffers[t];o.holes.geometry.length<=1?++t:(o.instances.forEach(({geometry:e})=>r.push(e)),this._vaoWriter?.deleteBuffer(o),s(n.buffers,o,void 0,{last:t}),e.madeProgress())}if(r.length>0){const{baseInstanceData:e}=o;n.buffers.forEach(t=>this._applyAdds(e,t,r));const s=null!=e;for(;r.length>0;)n.buffers.push(this._applyAndRebuild(e,new m(s,this._vaoWriter.targetBuffers),r,null));t=!0}}return t}updateHighlights(e){this.highlightOrderMap=e;for(const t of this.dataByBaseInstance.values())for(const s of t.dataByOrigin.values())for(const t of s.buffers)t.updateHighlights(e)}_applyUpdates(e,t){const o=this._vaoWriter;if(null==o)return void e.clearUpdates();let n;const r=this._useMetalWorkaround?(e,t)=>{n??=new Map;let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}:(e,t)=>o.updateInstance(e,t);for(const i of e.updates){if(t.done)return;const{renderGeometry:o,updateType:n}=i;s(e.pending.updates,i),t.madeProgress();const c=this.dataByBaseInstance.get(o.geometry.baseGeometry?.id??a),l=c?.dataByOrigin.get(o.localOrigin.id)?.findBuffer(o.id);if(null==l)return;const f=l.instances.get(o.id);6&n&&r(f,l),25&n&&(l.drawCommandsDirty=!0)}n&&o.updateInstancesMetal(n)}_computeDeltas(e,t){const s=new Map;for(const o of e){const e=o.localOrigin;if(null==e)continue;const t=o.geometry.baseGeometry,r=n(s,t??null,b);let a=r.get(e,null);null==a&&(a=new B(e.vec3,t),r.set(e,null,a)),a.changes.push(o)}for(const o of t){const e=o.localOrigin;if(null==e)continue;const t=o.geometry.baseGeometry,r=this.dataByBaseInstance.get(t?.id??a),i=r?.dataByOrigin.get(e.id)?.findBuffer(o.id);if(null==i)continue;const c=n(s,t??null,b);let l=c.get(e,i);null==l&&(l=new B(e.vec3,t),c.set(e,i,l)),l.changes.push(o)}return s}_applyAddsAndRemoves(e){const{_vaoWriter:t,dataByBaseInstance:o}=this;if(null==t)return void e.clearAddsAndRemoves();const r=this._computeDeltas(e.adds,e.removes);for(const[i,c]of r){const e=n(o,i?.id??a,()=>new h(t.createBaseInstanceData(i)));for(const[o,r]of c.outerMap()){const a=r.get(null),i=a?.changes??[];c.delete(o,null);const f=n(e.dataByOrigin,o.id,()=>new g(o.vec3));for(const[n,u]of r){if(c.delete(o,n),null==n&&l(!1,"No VAO for removed geometries"),n.instances.size===u.changes.length){t.deleteBuffer(n),s(f.buffers,n),0===f.buffers.length&&0===i.length&&e.dataByOrigin.delete(o.id);continue}switch(t.evaluateBufferAllocation(n.numElements.geometry,i,u.changes,n)){case 0:u.changes.forEach(({id:e})=>n.deleteInstance(e)),n.instances.forEach(({geometry:e})=>i.push(e)),t.deleteBuffer(n),s(f.buffers,n);break;case 1:this._applyAndRebuild(e.baseInstanceData,n,i,u);break;case 2:this._applyRemoves(n,u)}}if(i.length>0){const{baseInstanceData:s}=e,o=null!=s;for(const e of f.buffers)this._applyAdds(s,e,i);const{targetBuffers:n}=t;for(;i.length>0;)f.buffers.push(this._applyAndRebuild(s,new m(o,n),i,null))}}0===e.dataByOrigin.size&&(e.dispose(),o.delete(e.id))}e.clearAddsAndRemoves()}_updateDrawCommands(){this._hasOccludees=!1;for(const e of this.dataByBaseInstance.values())for(const t of e.dataByOrigin.values())for(const e of t.buffers)e.updateDirtyDrawCommands(this.highlightOrderMap),this._hasOccludees||=e.hasOccludees}_applyAndRebuild(e,t,s,o){if(o)for(const l of o.changes)t.deleteInstance(l.id);const n=this._vaoWriter,{targetBuffers:r}=n,a={},i={};for(const l of r)a[l]=n.maxElements(l),i[l]=t.numElements[l];for(;s.length>0;){const e=s.pop(),o={};for(const t of r)o[t]=n.elementCount(e.geometry,t);if(r.some(e=>i[e]+o[e]>a[e]&&i[e]>0)){s.push(e);break}for(const t of r)i[t]+=o[t];const c=new d(e,{geometry:f.acquire(0,0),texture:f.acquire(0,0)},this.highlightOrderMap);t.addInstance(e.id,c)}t.resetInstanceSummary(),n.reallocateBuffer(e,t,i);const c=n.rebuildInstances(i,t.writeableInstances.values(),t);t.updateInstances(),t.clearHoles();for(const l of r)t.holes[l].push(f.acquire(c[l],t.getEndElement(l)));return t.updateDrawCommands(this.highlightOrderMap),t}_applyRemoves(e,t){const{_vaoWriter:s}=this;if(0===t.changes.length||null==s)return;const{targetBuffers:o}=s,n={},r={};for(const a of o)n[a]=[],r[a]=f.acquire(1/0,-1/0);for(const a of t.changes){const t=a.id,s=e.instances.get(t);if(s){if(this._useMetalWorkaround)for(const e of o){const t=s.targetRanges[e],o=r[e];o.from=Math.min(o.from,t.from),o.to=Math.max(o.to,t.to)}for(const e of o){const t=s.targetRanges[e],o=n[e],r=o.at(-1);r?.to===t.from?r.to=t.to:r?.from===t.to?r.from=t.from:o.push(f.acquire(t.from,t.to))}e.deleteInstance(t)}}for(const a of o)u(n[a]);this._useMetalWorkaround?s.clearHolesMetal(e.instances.values(),r,e):s.clearHoles(n,e);for(const a of o)f.release(r[a]);for(const a of o){const t=e.holes[a];for(const e of n[a])t.push(e)}e.drawCommandsDirty=!0}_applyAdds(e,t,s){if(0===s.length||null==this._vaoWriter)return;if(!p(t))return void this._applyAndRebuild(e,t,s,null);const n=this._vaoWriter,{targetBuffers:r}=n,a={};for(const o of r){const e=t.numElements[o],r=s.reduce((e,{geometry:t})=>e+n.elementCount(t,o),0);a[o]=Math.min(e+r,n.maxElements(o))}if(n.canGrow(t,a))return void this._applyAndRebuild(e,t,s,null);t.mergeHoles();const i={},c={};for(const o of r)i[o]=[],c[o]=f.acquire(1/0,-1/0);for(const{geometry:o}of s){const e={},s={};for(const a of r)e[a]=n.elementCount(o,a),s[a]=_(t.holes[a],e[a]);if(r.every(e=>null!=s[e]))for(const t of r){const o=s[t];if(i[t].push(o),this._useMetalWorkaround){const s=c[t];s.from=Math.min(s.from,o),s.to=Math.max(s.to,o+e[t])}}else for(const t of r)i[t].push(null)}const l=this._addInstances(s,t,i);if(this._useMetalWorkaround){if(r.some(e=>!Number.isFinite(c[e].from)||!Number.isFinite(c[e].to)))return;for(const e of l);n.writeInstanceRangeMetal(c,t.instances.values(),t)}else n.writeRandomInstances(a,l,t);o(s,(e,t)=>r.some(e=>null==i[e][t]))}*_addInstances(e,t,s){const o=e.length,n=this._vaoWriter,{targetBuffers:r}=n;for(let a=0;a<o;++a){const o=e[a];if(r.some(e=>null==s[e][a]))continue;const i={};for(const e of r){const t=s[e][a];i[e]=f.acquire(t,t+n.elementCount(o.geometry,e))}const c=new d(o,i,this.highlightOrderMap);t.addInstance(o.id,c),t.drawCommandsDirty=!0,yield c}}static prune(){y.prune()}get test(){}};e([i({constructOnly:!0})],v.prototype,"dataByBaseInstance",void 0),e([i({constructOnly:!0})],v.prototype,"material",void 0),e([i()],v.prototype,"highlightOrderMap",void 0),v=e([c("esri.views.3d.webgl-engine.materials.renderers.MergedBuffer")],v);class B{constructor(e,t){this.origin=e,this.baseInstance=t,this.changes=new Array}}function _(e,t){if(0===t)return 0;const o=e.find(e=>e.numElements>=t);if(null==o)return null;const n=o.from;return o.from+=t,o.numElements<=0&&(s(e,o),f.release(o)),n}function b(){return new r}export{v as MergedBuffer};
2
+ import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import{removeUnordered as s,filterInPlace as o}from"../../../../../core/arrayUtils.js";import"../../../../../core/has.js";import{getOrCreateMapValue as n}from"../../../../../core/MapUtils.js";import{NestedMap as r}from"../../../../../core/NestedMap.js";import{nullUid as a}from"../../../../../core/uid.js";import{property as i,subclass as l}from"../../../../../core/accessorSupport/decorators.js";import{assert as c}from"../../lib/Util.js";import{bufferRangePool as f,mergeAdjacentRanges as u}from"./BufferRange.js";import{PerBaseInstanceData as d}from"./PerBaseInstanceData.js";import{PerBufferData as h,hasVao as m}from"./PerBufferData.js";import{PerOriginData as p}from"./PerOriginData.js";import{VaoWriter as g}from"./VaoWriter.js";let y=class extends t{constructor(e){super(e),this._vaoWriter=null,this._useMetalWorkaround=!1,this._hasOccludees=!1}destroy(){for(const e of this.dataByBaseInstance.values()){for(const t of e.dataByOrigin.values())for(const e of t.buffers)this._vaoWriter?.deleteBuffer(e);e.dispose()}this.dataByBaseInstance.clear(),this.uninitializeRenderContext()}initializeRenderContext(e){this._useMetalWorkaround=e.renderContext.rctx.isAssumedMetalDriver,this._vaoWriter=new g(this.material,e.renderContext.rctx)}uninitializeRenderContext(){this._useMetalWorkaround=!1,this._vaoWriter=null}get hasOccludees(){return this._hasOccludees}modify(e,t){this._applyUpdates(e,t),this._applyAddsAndRemoves(e),this._updateDrawCommands()}get canCompact(){for(const e of this.dataByBaseInstance.values())for(const t of e.dataByOrigin.values())if(t.buffers.some(e=>e.holes.geometry.length>1))return!0;return!1}compact(e){if(!this.canCompact)return!1;let t=!1;for(const o of this.dataByBaseInstance.values())for(const n of o.dataByOrigin.values()){const r=new Array;for(let t=0;t<n.buffers.length&&!e.done;){const o=n.buffers[t];o.holes.geometry.length<=1?++t:(o.instances.forEach(({geometry:e})=>r.push(e)),this._vaoWriter?.deleteBuffer(o),s(n.buffers,o,void 0,{last:t}),e.madeProgress())}if(r.length>0){const{baseInstanceData:e}=o;n.buffers.forEach(t=>this._applyAdds(e,t,r));const s=null!=e;for(;r.length>0;)n.buffers.push(this._applyAndRebuild(e,new h(s,this._vaoWriter.targetBuffers),r,null));t=!0}}return t}updateHighlights(e){this.highlightOrderMap=e;for(const t of this.dataByBaseInstance.values())for(const s of t.dataByOrigin.values())for(const t of s.buffers)t.updateHighlights(e)}_applyUpdates(e,t){const o=this._vaoWriter;if(null==o)return void e.clearUpdates();let n;const r=this._useMetalWorkaround?(e,t)=>{n??=new Map;let s=n.get(t);s||(s=[],n.set(t,s)),s.push(e)}:(e,t)=>o.updateInstance(e,t);for(const i of e.updates){if(t.done)return;const{renderGeometry:o,updateType:n}=i;s(e.pending.updates,i),t.madeProgress();const l=this.dataByBaseInstance.get(o.geometry.baseGeometry?.id??a),c=l?.dataByOrigin.get(o.localOrigin.id)?.findBuffer(o.id);if(null==c)return;const f=c.instances.get(o.id);6&n&&r(f,c),25&n&&(c.drawCommandsDirty=!0)}n&&o.updateInstancesMetal(n)}_computeDeltas(e,t){const s=new Map;for(const o of e){const e=o.localOrigin;if(null==e)continue;const t=o.geometry.baseGeometry,r=n(s,t??null,_);let a=r.get(e,null);null==a&&(a=new v(e.vec3,t),r.set(e,null,a)),a.changes.push(o)}for(const o of t){const e=o.localOrigin;if(null==e)continue;const t=o.geometry.baseGeometry,r=this.dataByBaseInstance.get(t?.id??a),i=r?.dataByOrigin.get(e.id)?.findBuffer(o.id);if(null==i)continue;const l=n(s,t??null,_);let c=l.get(e,i);null==c&&(c=new v(e.vec3,t),l.set(e,i,c)),c.changes.push(o)}return s}_applyAddsAndRemoves(e){const{_vaoWriter:t,dataByBaseInstance:o}=this;if(null==t)return void e.clearAddsAndRemoves();const r=this._computeDeltas(e.adds,e.removes);for(const[i,l]of r){const e=n(o,i?.id??a,()=>new d(t.createBaseInstanceData(i)));for(const[o,r]of l.outerMap()){const a=r.get(null),i=a?.changes??[];l.delete(o,null);const f=n(e.dataByOrigin,o.id,()=>new p(o.vec3));for(const[n,u]of r){if(l.delete(o,n),null==n&&c(!1,"No VAO for removed geometries"),n.instances.size===u.changes.length){t.deleteBuffer(n),s(f.buffers,n),0===f.buffers.length&&0===i.length&&e.dataByOrigin.delete(o.id);continue}switch(t.evaluateBufferAllocation(n.numElements.geometry,i,u.changes,n)){case 0:u.changes.forEach(({id:e})=>n.deleteInstance(e)),n.instances.forEach(({geometry:e})=>i.push(e)),t.deleteBuffer(n),s(f.buffers,n);break;case 1:this._applyAndRebuild(e.baseInstanceData,n,i,u);break;case 2:this._applyRemoves(n,u)}}if(i.length>0){const{baseInstanceData:s}=e,o=null!=s;for(const e of f.buffers)this._applyAdds(s,e,i);const{targetBuffers:n}=t;for(;i.length>0;)f.buffers.push(this._applyAndRebuild(s,new h(o,n),i,null))}}0===e.dataByOrigin.size&&(e.dispose(),o.delete(e.id))}e.clearAddsAndRemoves()}_updateDrawCommands(){this._hasOccludees=!1;for(const e of this.dataByBaseInstance.values())for(const t of e.dataByOrigin.values())for(const e of t.buffers)e.updateDirtyDrawCommands(this.highlightOrderMap),this._hasOccludees||=e.hasOccludees}_applyAndRebuild(e,t,s,o){if(o)for(const c of o.changes)t.deleteInstance(c.id);const n=this._vaoWriter,{targetBuffers:r}=n,a={},i={};for(const c of r)a[c]=n.maxElements(c),i[c]=t.numElements[c];for(;s.length>0;){const e=s.pop(),o={};for(const t of r)o[t]=n.elementCount(e.geometry,t);if(r.some(e=>i[e]+o[e]>a[e]&&i[e]>0)){s.push(e);break}for(const t of r)i[t]+=o[t];t.createInstance(e,this.highlightOrderMap)}t.resetInstanceSummary(),n.reallocateBuffer(e,t,i);const l=n.rebuildInstances(i,t.writeableInstances.values(),t);t.updateInstances(),t.clearHoles();for(const c of r)t.holes[c].push(f.acquire(l[c],t.endElements[c]));return t.updateDrawCommands(this.highlightOrderMap),t}_applyRemoves(e,t){const{_vaoWriter:s}=this;if(0===t.changes.length||null==s)return;const{targetBuffers:o}=s,n={},r={};for(const a of o)n[a]=[],r[a]=f.acquire(1/0,-1/0);for(const a of t.changes){const t=a.id,s=e.instances.get(t);if(s){if(this._useMetalWorkaround)for(const e of o){const t=s.targetRanges[e],o=r[e];o.from=Math.min(o.from,t.from),o.to=Math.max(o.to,t.to)}for(const e of o){const t=s.targetRanges[e],o=n[e],r=o.at(-1);r?.to===t.from?r.to=t.to:r?.from===t.to?r.from=t.from:o.push(f.acquire(t.from,t.to))}e.deleteInstance(t)}}for(const a of o)u(n[a]);this._useMetalWorkaround?s.clearHolesMetal(e.instances.values(),r,e):s.clearHoles(n,e);for(const a of o)f.release(r[a]);for(const a of o){const t=e.holes[a];for(const e of n[a])t.push(e)}e.drawCommandsDirty=!0}_applyAdds(e,t,s){if(0===s.length||null==this._vaoWriter)return;if(!m(t))return void this._applyAndRebuild(e,t,s,null);const n=this._vaoWriter,{targetBuffers:r}=n,a={};for(const o of r){const e=t.numElements[o],r=s.reduce((e,{geometry:t})=>e+n.elementCount(t,o),0);a[o]=Math.min(e+r,n.maxElements(o))}if(n.canGrow(t,a))return void this._applyAndRebuild(e,t,s,null);t.mergeHoles();const i={},l={};for(const o of r)i[o]=[],l[o]=f.acquire(1/0,-1/0);for(const{geometry:o}of s){const e={},s={};for(const a of r)e[a]=n.elementCount(o,a),s[a]=B(t.holes[a],e[a]);if(r.every(e=>null!=s[e]))for(const t of r){const o=s[t];if(i[t].push(o),this._useMetalWorkaround){const s=l[t];s.from=Math.min(s.from,o),s.to=Math.max(s.to,o+e[t])}}else for(const t of r)i[t].push(null)}const c=this._addInstances(s,t,i);if(this._useMetalWorkaround){if(r.some(e=>!Number.isFinite(l[e].from)||!Number.isFinite(l[e].to)))return;for(const e of c);n.writeInstanceRangeMetal(l,t.instances.values(),t)}else n.writeRandomInstances(a,c,t);o(s,(e,t)=>r.some(e=>null==i[e][t]))}*_addInstances(e,t,s){const o=e.length,n=this._vaoWriter,{targetBuffers:r}=n;for(let a=0;a<o;++a){const o=e[a];if(r.some(e=>null==s[e][a]))continue;const i={};for(const e of r){const t=s[e][a];i[e]=f.acquire(t,t+n.elementCount(o.geometry,e))}const l=t.createInstance(o,this.highlightOrderMap,i);t.drawCommandsDirty=!0,yield l}}static prune(){g.prune()}get test(){}};e([i({constructOnly:!0})],y.prototype,"dataByBaseInstance",void 0),e([i({constructOnly:!0})],y.prototype,"material",void 0),e([i()],y.prototype,"highlightOrderMap",void 0),y=e([l("esri.views.3d.webgl-engine.materials.renderers.MergedBuffer")],y);class v{constructor(e,t){this.origin=e,this.baseInstance=t,this.changes=new Array}}function B(e,t){if(0===t)return 0;const o=e.find(e=>e.numElements>=t);if(null==o)return null;const n=o.from;return o.from+=t,o.numElements<=0&&(s(e,o),f.release(o)),n}function _(){return new r}export{y as MergedBuffer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import s from"../../../../../core/PooledArray.js";import{assert as e}from"../../lib/Util.js";import{bufferRangePool as n,mergeAdjacentRanges as a}from"./BufferRange.js";import{DrawCommand as i}from"./DrawCommand.js";import{InstancedCommandVAO as o}from"./InstancedCommandVAO.js";import{InstancedCommandVAOs as r}from"./InstancedCommandVAOs.js";import{defaultHighlightName as h}from"../../../../support/HighlightDefaults.js";class m{constructor(t,s){this.isInstanced=t,this.targetBuffers=s,this.vao=null,this.textureBuffer=null,this.vaoEndElement=0,this.textureEndElement=0,this._instances=new Map,this.hasHiddenInstances=!1,this.hasOccludees=!1,this.drawCommandsDirty=!0,this.highlightNames=new Set,this.drawCommandsDefault=c(),this.drawCommandsHighlights=new Map,this.drawCommandsOccludees=c(),this.drawCommandsShadowHighlightRest=c(),this._instancedCommandVAOs=null;const e={},n={};for(const a of s)e[a]=0,n[a]=[];this._numElements=e,this._holes=n}getTargetBuffer(t){return"geometry"===t?this.vao?.buffer("geometry"):this.textureBuffer}get numElements(){return this._numElements}get instances(){return this._instances}get writeableInstances(){return this._instances}clearHoles(){for(const t of this.targetBuffers){const s=this._holes[t];for(const t of s)n.release(t);s.length=0}}getEndElement(t){return"geometry"===t?this.vaoEndElement:this.textureEndElement}get holes(){return this._holes}get hasHighlights(){return this.highlightNames.size>0}get instancedCommandVAOs(){return this._instancedCommandVAOs}resetInstanceSummary(){this.hasHiddenInstances=!1,this.hasOccludees=!1,this.highlightNames.clear()}updateDirtyDrawCommands(t){if(this.drawCommandsDirty){this.resetInstanceSummary();for(const t of this.instances.values())this.updateDrawState(t);this.updateDrawCommands(t)}}addInstance(t,s){e(!this._instances.has(t)),this._instances.set(t,s);for(const e of this.targetBuffers)this._numElements[e]+=s.targetRanges[e].numElements}deleteInstance(t){const s=this._instances.get(t);if(s){for(const t of this.targetBuffers){const e=s.targetRanges[t];this._numElements[t]-=e.numElements,n.release(e)}this._instances.delete(t)}}updateInstances(){const{targetBuffers:t}=this,s={};for(const e of t)s[e]=0;for(const e of this._instances.values()){for(const n of t)s[n]+=e.targetRanges[n].numElements;this.updateDrawState(e)}this._numElements=s}updateDrawState(t){if(t.isVisible){const{highlightName:s}=t;s&&this.highlightNames.add(s),t.hasOccludees&&(this.hasOccludees=!0)}else this.hasHiddenInstances=!0}updateDrawCommands(t){this._updateDrawCommands(t),this._updateInstancedCommandVAOs()}_updateDrawCommands(t){if(this.drawCommandsDefault.clear(),this.drawCommandsOccludees.clear(),this.drawCommandsDirty=!1,0===this._instances.size)return;const{sortedInstances:s}=this;if(this._updateHighlightDrawCommands(t,s),!this.needsMultipleCommands){const t=this.drawCommandsDefault.pushNew(),s=this.holes.geometry.at(0);return this.vao&&1===this.holes.geometry.length&&s.to===this.vaoEndElement?(t.first=0,void(t.count=s.from)):(t.first=1/0,t.count=0,this._instances.forEach(s=>{t.first=Math.min(t.first,s.targetRanges.geometry.from),t.count=Math.max(t.count,s.targetRanges.geometry.to)}),void(t.count-=t.first))}for(const e of s)e.isVisible&&l(e.hasOccludees?this.drawCommandsOccludees:this.drawCommandsDefault,e)}get sortedInstances(){return Array.from(this._instances.values()).sort(({targetRanges:{geometry:t}},{targetRanges:{geometry:s}})=>t.from===s.from?t.to-s.to:t.from-s.from)}updateHighlights(t){this.highlightNames.clear();const s=this.sortedInstances;for(const e of s)e.updateHighlightOptions(t),e.isVisible&&e.highlightName&&this.highlightNames.add(e.highlightName);this._updateHighlightDrawCommands(t,s),this._updateInstancedCommandVAOs()}mergeHoles(){const t=this._holes;for(const s of this.targetBuffers)a(t[s])}_updateHighlightDrawCommands(s,e){const{drawCommandsHighlights:n,drawCommandsShadowHighlightRest:a}=this;n.clear(),a.clear();for(const i of e){if(i.updateHighlightOptions(s),!i.isVisible)continue;const{highlightName:e}=i;if(e){this.highlightNames.add(e);l(t(n,e,c),i)}e&&e===h||l(a,i)}}_updateInstancedCommandVAOs(){const t=this.vao;if(!this.isInstanced||null==t)return;this._instancedCommandVAOs??=new r;const s=this._instancedCommandVAOs,e=s.commandVAOs.copy();s.clear();const n=s.commandVAOs,a=(s,a)=>{for(const i of s){const{first:s,count:r}=i,h=n.get(s,r)??e.pop(s,r)??new o(t.shallowCloneWithBaseInstances(new Map([["geometry",i.first]])),i.count);n.set(s,r,h),a.push(h)}};a(this.drawCommandsDefault,s.drawCommandsDefault);for(const[i,o]of this.drawCommandsHighlights){const t=new Array;a(o,t),s.drawCommandsHighlights.set(i,t)}a(this.drawCommandsOccludees,s.drawCommandsOccludees),a(this.drawCommandsShadowHighlightRest,s.drawCommandsShadowHighlightRest);for(const i of e.values())i.dispose();e.clear()}get needsMultipleCommands(){return this.hasOccludees||this.hasHighlights||this.hasHiddenInstances}}function d(t){return null!=t.vao}function c(){return new s({allocator:t=>t||new i,deallocator:t=>t})}function l(t,{targetRanges:{geometry:s}}){const e=t.back();if(null==e){const e=t.pushNew();return e.first=s.from,void(e.count=s.numElements)}if(u(e,s)){const t=s.from-e.first+s.numElements;e.count=t}else{const e=t.pushNew();e.first=s.from,e.count=s.numElements}}function u(t,s){return t.first+t.count>=s.from}export{m as PerBufferData,d as hasVao};
2
+ import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import s from"../../../../../core/PooledArray.js";import{assert as e}from"../../lib/Util.js";import{bufferRangePool as n,mergeAdjacentRanges as a}from"./BufferRange.js";import{DrawCommand as i}from"./DrawCommand.js";import{Instance as r}from"./Instance.js";import{InstancedCommandVAO as o}from"./InstancedCommandVAO.js";import{InstancedCommandVAOs as h}from"./InstancedCommandVAOs.js";import{defaultHighlightName as d}from"../../../../support/HighlightDefaults.js";class m{constructor(t,s){this.isInstanced=t,this.targetBuffers=s,this.vao=null,this.textureBuffer=null,this.endElements={geometry:0,texture:0,index:0},this._instances=new Map,this.hasHiddenInstances=!1,this.hasOccludees=!1,this.drawCommandsDirty=!0,this.highlightNames=new Set,this.drawCommandsDefault=l(),this.drawCommandsHighlights=new Map,this.drawCommandsOccludees=l(),this.drawCommandsShadowHighlightRest=l(),this._instancedCommandVAOs=null;const e={},n={};for(const a of s)e[a]=0,n[a]=[];this._numElements=e,this._holes=n,this.useIndexing=s.includes("index"),this._drawRangesTarget=this.useIndexing?"index":"geometry"}getTargetBuffer(t){return"geometry"===t?this.vao?.buffer("geometry"):"texture"===t?this.textureBuffer:this.vao?.indexBuffer}get numElements(){return this._numElements}get instances(){return this._instances}get writeableInstances(){return this._instances}get indexType(){return this.vao?.indexBuffer?.indexType}clearHoles(){for(const t of this.targetBuffers){const s=this._holes[t];for(const t of s)n.release(t);s.length=0}}get holes(){return this._holes}get hasHighlights(){return this.highlightNames.size>0}get instancedCommandVAOs(){return this._instancedCommandVAOs}get _drawTargetHoles(){return this._holes[this._drawRangesTarget]}get _drawTargetEndElement(){return this.endElements[this._drawRangesTarget]}resetInstanceSummary(){this.hasHiddenInstances=!1,this.hasOccludees=!1,this.highlightNames.clear()}updateDirtyDrawCommands(t){if(this.drawCommandsDirty){this.resetInstanceSummary();for(const t of this.instances.values())this.updateDrawState(t);this.updateDrawCommands(t)}}createInstance(t,s,e=this._makeEmptyRanges()){const n=new r(t,e,s,this._drawRangesTarget);return this.addInstance(t.id,n),n}addInstance(t,s){e(!this._instances.has(t)),this._instances.set(t,s);for(const e of this.targetBuffers)this._numElements[e]+=s.targetRanges[e].numElements}deleteInstance(t){const s=this._instances.get(t);if(s){for(const t of this.targetBuffers){const e=s.targetRanges[t];this._numElements[t]-=e.numElements,n.release(e)}this._instances.delete(t)}}updateInstances(){const{targetBuffers:t}=this,s={};for(const e of t)s[e]=0;for(const e of this._instances.values()){for(const n of t)s[n]+=e.targetRanges[n].numElements;this.updateDrawState(e)}this._numElements=s}updateDrawState(t){if(t.isVisible){const{highlightName:s}=t;s&&this.highlightNames.add(s),t.hasOccludees&&(this.hasOccludees=!0)}else this.hasHiddenInstances=!0}updateDrawCommands(t){this._updateDrawCommands(t),this._updateInstancedCommandVAOs()}_updateDrawCommands(t){if(this.drawCommandsDefault.clear(),this.drawCommandsOccludees.clear(),this.drawCommandsDirty=!1,0===this._instances.size)return;const{sortedInstances:s}=this;if(this._updateHighlightDrawCommands(t,s),!this.needsMultipleCommands){const t=this.drawCommandsDefault.pushNew(),s=this._drawTargetHoles,e=s.at(0);return this.vao&&1===s.length&&e.to===this._drawTargetEndElement?(t.first=0,void(t.count=e.from)):(t.first=1/0,t.count=0,this._instances.forEach(s=>{t.first=Math.min(t.first,s.drawRange.from),t.count=Math.max(t.count,s.drawRange.to)}),void(t.count-=t.first))}for(const e of s)e.isVisible&&this.addOrMerge(e.hasOccludees?this.drawCommandsOccludees:this.drawCommandsDefault,e)}get sortedInstances(){return Array.from(this._instances.values()).sort(({drawRange:t},{drawRange:s})=>t.from===s.from?t.to-s.to:t.from-s.from)}updateHighlights(t){this.highlightNames.clear();const s=this.sortedInstances;for(const e of s)e.updateHighlightOptions(t),e.isVisible&&e.highlightName&&this.highlightNames.add(e.highlightName);this._updateHighlightDrawCommands(t,s),this._updateInstancedCommandVAOs()}mergeHoles(){const t=this._holes;for(const s of this.targetBuffers)a(t[s])}_updateHighlightDrawCommands(s,e){const{drawCommandsHighlights:n,drawCommandsShadowHighlightRest:a}=this;n.clear(),a.clear();for(const i of e){if(i.updateHighlightOptions(s),!i.isVisible)continue;const{highlightName:e}=i;if(e){this.highlightNames.add(e);const s=t(n,e,l);this.addOrMerge(s,i)}e&&e===d||this.addOrMerge(a,i)}}_updateInstancedCommandVAOs(){const t=this.vao;if(!this.isInstanced||null==t)return;this._instancedCommandVAOs??=new h;const s=this._instancedCommandVAOs,e=s.commandVAOs.copy();s.clear();const n=s.commandVAOs,a=(s,a)=>{for(const i of s){const{first:s,count:r}=i,h=n.get(s,r)??e.pop(s,r)??new o(t.shallowCloneWithBaseInstances(new Map([["geometry",i.first]])),i.count);n.set(s,r,h),a.push(h)}};a(this.drawCommandsDefault,s.drawCommandsDefault);for(const[i,r]of this.drawCommandsHighlights){const t=new Array;a(r,t),s.drawCommandsHighlights.set(i,t)}a(this.drawCommandsOccludees,s.drawCommandsOccludees),a(this.drawCommandsShadowHighlightRest,s.drawCommandsShadowHighlightRest);for(const i of e.values())i.dispose();e.clear()}get needsMultipleCommands(){return this.hasOccludees||this.hasHighlights||this.hasHiddenInstances}addOrMerge(t,{drawRange:s}){const e=t.back();if(null==e){const e=t.pushNew();return e.first=s.from,void(e.count=s.numElements)}if(u(e,s)){const t=s.from-e.first+s.numElements;e.count=t}else{const e=t.pushNew();e.first=s.from,e.count=s.numElements}}_makeEmptyRanges(){const t={};for(const s of this.targetBuffers)t[s]=n.acquire(0,0);return t}}function c(t){return null!=t.vao}function l(){return new s({allocator:t=>t||new i,deallocator:t=>t})}function u(t,s){return t.first+t.count>=s.from}export{m as PerBufferData,c as hasVao};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as t}from"tslib";import e from"../../../../../core/Accessor.js";import"../../../../../core/has.js";import{disposeMaybe as s}from"../../../../../core/maybe.js";import{property as i,subclass as a}from"../../../../../core/accessorSupport/decorators.js";import{GLMaterials as r}from"../../lib/GLMaterials.js";import{DrawParameters as n}from"../DrawParameters.js";import{defaultHighlightName as o}from"../../../../support/HighlightDefaults.js";let h=class extends e{constructor(t){super(t),this._glMaterials=null,this._drawParameters=new n,this._highlightNames=new Set,this._produces=new Map}initialize(){this._updateProduces()}destroy(){this.uninitializeRenderContext()}get _hasHighlights(){return this._highlightNames.size>0}hasHighlight(t){return this._highlightNames.has(t)}get produces(){return this._produces}_updateProduces(){this.material.produces.forEach((t,e)=>{this._produces.set(e,e=>!(0===this.dataByBaseInstance.size||!(8!==e&&4!==e||this._hasHighlights))&&t(e))})}initializeRenderContext(t){this._glMaterials=new r(this.material,t.materials)}uninitializeRenderContext(){this._glMaterials=s(this._glMaterials)}acquireTechniques(t){if(!this.material.shouldRender(t))return null;const{output:e,bind:s}=t,i=this.material.produces.get(s.slot);if(!i?.(e))return null;const{highlight:a,slot:r}=s,n=4===e,h=8===e,l=h||n,d=a?.name;if(l&&(0===this._highlightNames.size||h&&d&&!this._highlightNames.has(d)))return null;const u=t=>h&&!!d&&!t.has(d),c=5===e,g=!(l||c);for(const m of this.dataByBaseInstance.values())for(const i of m.dataByOrigin.values())for(const a of i.buffers){if(u(a.highlightNames))continue;const i=n?a.drawCommandsHighlights.get(o):l?d?a.drawCommandsHighlights.get(d):a.drawCommandsHighlights.size>0:((c&&a.needsMultipleCommands?a.drawCommandsShadowHighlightRest:a.drawCommandsDefault)||null)?.length??!1,h=g&&a.drawCommandsOccludees||null;if(i||h?.length){const i=this._glMaterials.load(t.rctx,r,e),a=i?.beginSlot(s);if(a)return a}}return null}render(t,e){const{output:s,bind:i}=t,{highlight:a}=i,r=8===s,n=a?.name??"";if(r&&!a)return;const h=4===s,g=r||h,m=5===s,w=!(g||m),{rctx:_}=t;_.runAppleAmdDriverHelper();const C=_.bindTechnique(e,i,this.material.parameters);for(const b of this.dataByBaseInstance.values()){const{baseInstanceData:t}=b,s=null!=t,a=s?c:u,y=s?d:l;for(const l of b.dataByOrigin.values()){this._drawParameters.origin=l.origin;for(const s of l.buffers){if(r&&(!s.hasHighlights||!s.drawCommandsHighlights.has(n)))continue;if(h&&(!s.hasHighlights||!s.drawCommandsHighlights.has(o)))continue;this._drawParameters.textureBuffer=s.textureBuffer?.texture;const l=y(s),d=f(l,s.needsMultipleCommands,n,h,g,m),u=p(l,w);(d?.length||u?.length)&&(C.bindDraw(i,this.material.parameters,this._drawParameters),a(_,s,t,e,d,u,i)),this._drawParameters.textureBuffer=null}}}}updateHighlights(){const{_highlightNames:t}=this;t.clear();for(const e of this.dataByBaseInstance.values())for(const s of e.dataByOrigin.values())for(const e of s.buffers)for(const s of e.highlightNames)t.add(s);this._updateProduces()}get test(){}};t([i({constructOnly:!0})],h.prototype,"material",void 0),t([i({constructOnly:!0})],h.prototype,"dataByBaseInstance",void 0),h=t([a("esri.views.3d.webgl-engine.materials.renderers.VaoRenderer")],h);const l=t=>t,d=t=>t.instancedCommandVAOs,u=(t,{vao:e},s,i,a,r,n)=>{i.ensureAttributeLocations(e),t.bindVAO(e),g(t,i,a,n,!1),g(t,i,r,n,!0)},c=(t,e,{baseCommand:s},i,a,r,n)=>{m(t,i,s,a,n,!1),m(t,i,s,r,n,!0)};function g(t,e,s,i,a){if(s?.length){t.setPipelineState(e.getPipeline(i,a));for(const i of s)t.drawArrays(e.primitiveType,i.first,i.count)}}function m(t,e,{first:s,count:i},a,r,n){if(a?.length){t.setPipelineState(e.getPipeline(r,n));for(const{vao:r,instanceCount:n}of a)e.ensureAttributeLocations(r),t.bindVAO(r),t.drawArraysInstanced(e.primitiveType,s,i,n)}}function f(t,e,s,i,a,r){const n=a&&!i?t.drawCommandsHighlights.get(s)??null:null;return i?t.drawCommandsHighlights.get(o):a?n:r&&e?t.drawCommandsShadowHighlightRest:t.drawCommandsDefault}function p(t,e){return e&&t.drawCommandsOccludees||null}export{h as VaoRenderer};
2
+ import{__decorate as t}from"tslib";import e from"../../../../../core/Accessor.js";import"../../../../../core/has.js";import{disposeMaybe as i}from"../../../../../core/maybe.js";import{property as s,subclass as r}from"../../../../../core/accessorSupport/decorators.js";import{GLMaterials as n}from"../../lib/GLMaterials.js";import{assert as a}from"../../lib/Util.js";import{DrawParameters as o}from"../DrawParameters.js";import{getStrideForDataType as l}from"./IndexLayout.js";import{defaultHighlightName as h}from"../../../../support/HighlightDefaults.js";let d=class extends e{constructor(t){super(t),this._glMaterials=null,this._drawParameters=new o,this._highlightNames=new Set,this._produces=new Map}initialize(){this._updateProduces()}destroy(){this.uninitializeRenderContext()}get _hasHighlights(){return this._highlightNames.size>0}hasHighlight(t){return this._highlightNames.has(t)}get produces(){return this._produces}_updateProduces(){this.material.produces.forEach((t,e)=>{this._produces.set(e,e=>!(0===this.dataByBaseInstance.size||!(8!==e&&4!==e||this._hasHighlights))&&t(e))})}initializeRenderContext(t){this._glMaterials=new n(this.material,t.materials)}uninitializeRenderContext(){this._glMaterials=i(this._glMaterials)}acquireTechniques(t){if(!this.material.shouldRender(t))return null;const{output:e,bind:i}=t,s=this.material.produces.get(i.slot);if(!s?.(e))return null;const{highlight:r,slot:n}=i,a=4===e,o=8===e,l=o||a,d=r?.name;if(l&&(0===this._highlightNames.size||o&&d&&!this._highlightNames.has(d)))return null;const u=t=>o&&!!d&&!t.has(d),c=5===e,m=!(l||c);for(const g of this.dataByBaseInstance.values())for(const s of g.dataByOrigin.values())for(const r of s.buffers){if(u(r.highlightNames))continue;const s=a?r.drawCommandsHighlights.get(h):l?d?r.drawCommandsHighlights.get(d):r.drawCommandsHighlights.size>0:((c&&r.needsMultipleCommands?r.drawCommandsShadowHighlightRest:r.drawCommandsDefault)||null)?.length??!1,o=m&&r.drawCommandsOccludees||null;if(s||o?.length){const s=this._glMaterials.load(t.rctx,n,e),r=s?.beginSlot(i);if(r)return r}}return null}render(t,e){const{output:i,bind:s}=t,{highlight:r}=s,n=8===i,o=r?.name??"";if(n&&!r)return;const l=4===i,d=n||l,p=5===i,w=!(d||p),{rctx:_}=t;_.runAppleAmdDriverHelper();const C=_.bindTechnique(e,s,this.material.parameters),x=this.material.useIndexing;for(const B of this.dataByBaseInstance.values()){const{baseInstanceData:t}=B,i=null!=t;a(!(i&&x),"Instanced indexed rendering is not supported");const r=i?f:x?g:m,H=i?c:u;for(const a of B.dataByOrigin.values()){this._drawParameters.origin=a.origin;for(const i of a.buffers){if(n&&(!i.hasHighlights||!i.drawCommandsHighlights.has(o)))continue;if(l&&(!i.hasHighlights||!i.drawCommandsHighlights.has(h)))continue;this._drawParameters.textureBuffer=i.textureBuffer?.texture;const a=H(i),u=y(a,i.needsMultipleCommands,o,l,d,p),c=b(a,w);(u?.length||c?.length)&&(C.bindDraw(s,this.material.parameters,this._drawParameters),r(_,i,t,e,u,c,s)),this._drawParameters.textureBuffer=null}}}}updateHighlights(){const{_highlightNames:t}=this;t.clear();for(const e of this.dataByBaseInstance.values())for(const i of e.dataByOrigin.values())for(const e of i.buffers)for(const i of e.highlightNames)t.add(i);this._updateProduces()}get test(){}};t([s({constructOnly:!0})],d.prototype,"material",void 0),t([s({constructOnly:!0})],d.prototype,"dataByBaseInstance",void 0),d=t([r("esri.views.3d.webgl-engine.materials.renderers.VaoRenderer")],d);const u=t=>t,c=t=>t.instancedCommandVAOs,m=(t,{vao:e},i,s,r,n,a)=>{s.ensureAttributeLocations(e),t.bindVAO(e),p(t,s,r,a,!1),p(t,s,n,a,!0)},g=(t,{vao:e},i,s,r,n,o)=>{s.ensureAttributeLocations(e),t.bindVAO(e);const l=e.indexBuffer?.indexType;a(null!=l,"Missing index array"),w(t,s,r,o,!1,l),w(t,s,n,o,!0,l)},f=(t,e,{baseCommand:i},s,r,n,a)=>{_(t,s,i,r,a,!1),_(t,s,i,n,a,!0)};function p(t,e,i,s,r){if(i?.length){t.setPipelineState(e.getPipeline(s,r));for(const s of i)t.drawArrays(e.primitiveType,s.first,s.count)}}function w(t,e,i,s,r,n){if(!i?.length)return;const a=l(n);t.setPipelineState(e.getPipeline(s,r));for(const o of i)t.drawElements(e.primitiveType,o.count,n,o.first*a)}function _(t,e,{first:i,count:s},r,n,a){if(r?.length){t.setPipelineState(e.getPipeline(n,a));for(const{vao:n,instanceCount:a}of r)e.ensureAttributeLocations(n),t.bindVAO(n),t.drawArraysInstanced(e.primitiveType,i,s,a)}}function y(t,e,i,s,r,n){const a=r&&!s?t.drawCommandsHighlights.get(i)??null:null;return s?t.drawCommandsHighlights.get(h):r?a:n&&e?t.drawCommandsShadowHighlightRest:t.drawCommandsDefault}function b(t,e){return e&&t.drawCommandsOccludees||null}export{d as VaoRenderer};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{nextHighestPowerOfTwo as t}from"../../../../../core/mathUtils.js";import{copy as e,invert as r,transpose as o}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as s}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{glLayout as a}from"../../../support/buffer/glUtil.js";import{VertexArrayObject as n}from"../../lib/VertexArrayObject.js";import{getMaxItemCount as f,getMaxByteSize as u}from"../../lib/TextureBackedBuffer/TextureBackedBufferUtils.js";import{bufferRangePool as i}from"./BufferRange.js";import{DrawCommand as c}from"./DrawCommand.js";import{BaseInstanceData as l}from"./PerBaseInstanceData.js";import{VertexBuffer as m}from"../../../../webgl/VertexBuffer.js";class g{constructor(t,e){this._rctx=e,this._vaoCacheValue=null,this._instanceVboCacheValue=null,this._textureBufferCacheValue=null;const r=t.createBufferWriter();this._bufferWriter=r;const o=["geometry"],s="textureBufferLayout"in r&&null!=r.textureBufferLayout;this.useTextureBuffer=s,s&&o.push("texture"),this.targetBuffers=o}get _vaoCache(){return this._vaoCacheValue??=this._rctx.getVaoCache(a(this._bufferWriter.layout)),this._vaoCacheValue}get _instanceVboCache(){return this._instanceVboCacheValue??=this._rctx.getVboCache(a(this._bufferWriter.layout,1)),this._instanceVboCacheValue}get _textureBufferCache(){return this.useTextureBuffer?(this._textureBufferCacheValue??=this._rctx.getTextureBufferCache(this._bufferWriter.textureBufferLayout),this._textureBufferCacheValue):null}maxElements(t){if("texture"===t){const t=this._targetLayout("texture");return null==t?0:f(this._rctx,t)}return Math.floor(b/this._targetStrideBytes(t))}_targetStrideBytes(t){return this._targetLayout(t)?.stride??0}_targetLayout(t){return"geometry"===t?this._bufferWriter.layout:"baseInstance"===t?this._bufferWriter.baseInstanceLayout:this._bufferWriter.textureBufferLayout}evaluateBufferAllocation(t,e,r,o){const s=this._targetStrideBytes("geometry"),a=e.reduce((t,{geometry:e})=>t+this.vertexElementCount(e),0),n=r.reduce((t,{geometry:e})=>t+this.vertexElementCount(e),0),f=Math.min((t+a-n)*s,b),u=o.vao?.buffer("geometry"),i=u?.sizeBytes??0;return f>_&&f<i/2?0:f>i?1:2}deleteBuffer(t){t.isInstanced?(t.instancedCommandVAOs?.dispose(),this._instanceVboCache.deleteVbo(t.vao?.mutableBuffer("geometry")),t.vao?.disposeVAOOnly()):this._vaoCache.deleteVao(t.vao),this._textureBufferCache?.deleteTextureBuffer(t.textureBuffer),t.vao=null,t.textureBuffer=null,t.vaoEndElement=0,t.textureEndElement=0}createBaseInstanceData(t){const{_bufferWriter:e}=this;if(null==t||null==e.baseInstanceLayout||null==e.writeBaseInstance||null==e.elementCountBaseInstance)return null;const r=this._targetLayout("baseInstance"),o=e.elementCountBaseInstance(t.attributes),s=o*r.stride,n=new m(this._rctx,a(r));n.setSize(Math.ceil(s));const f=d(s),u=r.createView(f.buffer);e.writeBaseInstance(t.attributes,u),n.setSubData(f,0,0,s);const i=new c;return i.first=0,i.count=o,new l(t,n,i)}reallocateBuffer(t,e,r){if(this.deleteBuffer(e),null!=t){const o=t.baseInstanceBuffer,s=r.geometry*this._targetStrideBytes("geometry"),a=this._instanceVboCache.newVbo(C(s));e.vao=new n(this._rctx,new Map([["baseInstance",o],["geometry",a]]))}else{const t=r.geometry*this._targetStrideBytes("geometry");e.vao=this._vaoCache.newVao(C(t))}const o=this._targetLayout("texture"),s=this._textureBufferCache;if(null!=o&&null!=s){const t=C(r.texture*o.stride),a=Math.ceil(t/o.stride);e.textureBuffer=s.newTextureBuffer(a)}e.vaoEndElement=Math.floor((e.vao?.getByteLength("geometry")??0)/this._targetStrideBytes("geometry")),e.textureEndElement=e.textureBuffer?.itemCount??0}elementCount(t,e){const{attributes:r}=t;return"geometry"===e?this._bufferWriter.elementCount(r):"baseInstance"===e?this._bufferWriter.elementCountBaseInstance?.(r)??0:this._bufferWriter.elementCountTextureBuffer?.(r)??0}vertexElementCount(t){return this._bufferWriter.elementCount(t.attributes)}textureElementCount(t){return this._bufferWriter.elementCountTextureBuffer?.(t.attributes)??0}canGrow(t,e){const r=this.targetBuffers.map(r=>this._evaluateTargetBufferGrowth(r,t,e));return r.every(({canGrow:t})=>t)&&r.some(({needsToGrow:t})=>t)}_evaluateTargetBufferGrowth(t,e,r){const o=this._targetLayout(t),s=e.getTargetBuffer(t);if(null==o||null==s)return{needsToGrow:null!=o,canGrow:!0};return{needsToGrow:r[t]*o.stride>s.sizeBytes,canGrow:"geometry"===t?s.sizeBytes<C(b-_):s.sizeBytes<u(this._rctx,o)}}clearHoles(t,e){for(const r of this.targetBuffers){const o=this._targetStrideBytes(r),s=t[r],a=s.reduce((t,e)=>Math.max(t,e.numElements),0)*o,n=d(a);n.fill(0,0,a);for(const t of s)this._setTargetSubData(r,e,o,t,n)}}clearHolesMetal(t,e,r){const{targetBuffers:o}=this,s={};let a=0;for(const u of o){const t=e[u].numElements*this._targetStrideBytes(u);s[u]=a,a+=w(t)}const n=d(a);n.fill(0,0,a);const f={};for(const u of o)f[u]=this._targetLayout(u)?.createView(n.buffer,s[u]);for(const u of t){const t=u.targetRanges.geometry;if(!(t.from>=e.geometry.from&&t.to<=e.geometry.to))continue;const r={};for(const s of o)r[s]=u.targetRanges[s].from-e[s].from;this._writeGeometry(u.geometry,f,r,u.targetRanges)}for(const u of o)this._setTargetSubData(u,r,this._targetStrideBytes(u),e[u],n,s[u])}writeRandomInstances(t,e,r){const{targetBuffers:o}=this,s={},a={},n={},f={};let u=0;for(const m of o)s[m]=t[m]*this._targetStrideBytes(m),a[m]=u,n[m]=0,f[m]=i.acquire(0,0),u+=w(s[m]);const c=d(u),l={};for(const i of o)l[i]=this._targetLayout(i)?.createView(c.buffer,a[i]);for(const i of e){for(const t of o){const e=i.targetRanges[t],o=f[t];o.to===e.from||(o.numElements>0&&this._setTargetSubData(t,r,this._targetStrideBytes(t),f[t],c,a[t]),o.from=e.from,n[t]=0)}this._writeGeometry(i.geometry,l,n,i.targetRanges);for(const t of o){const e=i.targetRanges[t];n[t]+=e.numElements,f[t].to=e.to}}for(const m of o){const t=f[m];t.numElements>0&&this._setTargetSubData(m,r,this._targetStrideBytes(m),t,c,a[m]),i.release(f[m])}}writeInstanceRangeMetal(t,e,r){const{targetBuffers:o}=this,s={},a={};let n=0;for(const i of o)s[i]=t[i].numElements*this._targetStrideBytes(i),a[i]=n,n+=w(s[i]);const f=d(n),u={};for(const i of o)u[i]=this._targetLayout(i)?.createView(f.buffer,a[i]);f.fill(0,0,n);for(const i of e){const e=i.targetRanges.geometry;if(!(e.from>=t.geometry.from&&e.to<=t.geometry.to))continue;const r={},s={};for(const a of o){const e=i.targetRanges[a];r[a]=e.from-t[a].from,s[a]=e}this._writeGeometry(i.geometry,u,r,s)}for(const i of o)t[i].numElements>0&&this._setTargetSubData(i,r,this._targetStrideBytes(i),t[i],f,a[i])}rebuildInstances(t,e,r){const{targetBuffers:o}=this,s={},a={},n={};let f=0;for(const i of o)s[i]=t[i]*this._targetStrideBytes(i),a[i]=f,f+=w(s[i]),n[i]=0;const u=d(f),c={};for(const i of o)c[i]=this._targetLayout(i)?.createView(u.buffer,a[i]);for(const i of e){const t={},e={};for(const r of o){t[r]=n[r],n[r]+=this.elementCount(i.geometry.geometry,r);const o=i.targetRanges[r];o.from=t[r],o.to=n[r],e[r]=o}this._writeGeometry(i.geometry,c,t,e)}for(const l of o){const t=i.acquire(0,n[l]);this._setTargetSubData(l,r,this._targetStrideBytes(l),t,u,a[l]),i.release(t)}return n}updateInstance(t,e){const{targetBuffers:r}=this,o={},s={};let a=0;for(const i of r){const e=this._targetStrideBytes(i);o[i]=this.elementCount(t.geometry.geometry,i)*e,s[i]=a,a+=w(o[i])}const n=d(a),f={},u={};for(const i of r)u[i]=0,f[i]=this._targetLayout(i)?.createView(n.buffer,s[i]);this._writeGeometry(t.geometry,f,u,t.targetRanges);for(const i of r)this._setTargetSubData(i,e,this._targetStrideBytes(i),t.targetRanges[i],n,s[i])}updateInstancesMetal(t){const{targetBuffers:e}=this;for(const[r,o]of t){const t={};for(const r of e)t[r]=i.acquire(1/0,-1/0);for(const r of o)for(const o of e){const e=t[o],s=r.targetRanges[o];e.from=Math.min(e.from,s.from),e.to=Math.max(e.to,s.to)}this.writeInstanceRangeMetal(t,r.instances.values(),r);for(const r of e)i.release(t[r])}}_writeGeometry(t,s,a,n){const{_bufferWriter:f}=this;null!=f&&(e(h,t.transformation),h[12]-=t.localOrigin.vec3[0],h[13]-=t.localOrigin.vec3[1],h[14]-=t.localOrigin.vec3[2],r(y,h),o(y,y),f.write(h,y,t.geometry.attributes,t.geometry.olidColor,s.geometry,a.geometry,n.texture),null!=s.texture&&f.writeTextureBuffer&&f.writeTextureBuffer(h,y,t.geometry.attributes,s.texture,a.texture))}_setTargetSubData(t,e,r,o,s,a=0){if("geometry"===t){const n=e.getTargetBuffer(t);n?.setSubData(s,o.from*r,a,o.numElements*r)}else if("texture"===t){const r=e.getTargetBuffer(t);r?.setSubData(s.buffer,o.from,a,o.numElements)}}static prune(){x=new Uint8Array(_)}}const h=s(),y=s(),_=262144,B=1024,b=16777216;let x=new Uint8Array(_);function d(t){return x.byteLength<t&&(x=new Uint8Array(t)),x}function w(t){return 4*Math.ceil(t/4)}function C(e){return e<=B?B:e<_?t(e):Math.max(Math.min(Math.ceil(1.5*e/_)*_,b),e)}export{g as VaoWriter};
2
+ import{nextHighestPowerOfTwo as e}from"../../../../../core/mathUtils.js";import{copy as t,invert as r,transpose as s}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as o}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{glLayout as n}from"../../../support/buffer/glUtil.js";import{assert as a}from"../../lib/Util.js";import{VertexArrayObject as i}from"../../lib/VertexArrayObject.js";import{getMaxItemCount as f,getMaxByteSize as u}from"../../lib/TextureBackedBuffer/TextureBackedBufferUtils.js";import{bufferRangePool as c}from"./BufferRange.js";import{DrawCommand as l}from"./DrawCommand.js";import{getIndexLayoutForMaxIndex as h,getIndexLayoutForDataType as g}from"./IndexLayout.js";import{BaseInstanceData as m}from"./PerBaseInstanceData.js";import{VertexBuffer as y}from"../../../../webgl/VertexBuffer.js";class d{constructor(e,t){this._rctx=t,this._vaoCacheValue=null,this._instanceVboCacheValue=null,this._textureBufferCacheValue=null,this._vboCacheValue=null;const r=e.createBufferWriter();this._bufferWriter=r;const s=["geometry"],o="textureBufferLayout"in r&&null!=r.textureBufferLayout;this.useTextureBuffer=o,o&&s.push("texture"),this.useIndexing=e.useIndexing,this.useIndexing&&s.push("index"),this.targetBuffers=s}get _vaoCache(){return this._vaoCacheValue??=this._rctx.getVaoCache(n(this._bufferWriter.layout)),this._vaoCacheValue}get _instanceVboCache(){return this._instanceVboCacheValue??=this._rctx.getVboCache(n(this._bufferWriter.layout,1)),this._instanceVboCacheValue}get _textureBufferCache(){return this.useTextureBuffer?(this._textureBufferCacheValue??=this._rctx.getTextureBufferCache(this._bufferWriter.textureBufferLayout),this._textureBufferCacheValue):null}get _vboCache(){return this._vboCacheValue??=this._rctx.getVboCache(n(this._bufferWriter.layout)),this._vboCacheValue}maxElements(e){if("texture"===e){const e=this._targetLayout("texture");return null==e?0:f(this._rctx,e)}const t=Math.floor(w/this._targetStrideBytes("geometry"));if("index"===e){const e=h(t-1).dataType;return Math.floor(w/this._targetStrideBytes("index",e))}return t}_targetStrideBytes(e,t){return this._targetLayout(e,t)?.stride??0}_targetLayout(e,t){return"geometry"===e?this._bufferWriter.layout:"baseInstance"===e?this._bufferWriter.baseInstanceLayout:"index"===e?g(t):this._bufferWriter.textureBufferLayout}evaluateBufferAllocation(e,t,r,s){const o=this._targetStrideBytes("geometry"),n=t.reduce((e,{geometry:t})=>e+this.vertexElementCount(t),0),a=r.reduce((e,{geometry:t})=>e+this.vertexElementCount(t),0),i=Math.min((e+n-a)*o,w),f=s.vao?.buffer("geometry"),u=f?.sizeBytes??0;return i>B&&i<u/2?0:i>u?1:2}deleteBuffer(e){e.isInstanced?(e.instancedCommandVAOs?.dispose(),this._instanceVboCache.deleteVbo(e.vao?.mutableBuffer("geometry")),e.vao?.disposeVAOOnly()):this.useIndexing?(this._vboCache.deleteVbo(e.vao?.mutableBuffer("geometry")),this._rctx.indexBufferCache.deleteIndexBuffer(e.vao?.indexBuffer),e.vao?.disposeVAOOnly()):this._vaoCache.deleteVao(e.vao),this._textureBufferCache?.deleteTextureBuffer(e.textureBuffer),e.vao=null,e.textureBuffer=null,e.endElements.geometry=0,e.endElements.texture=0,e.endElements.index=0}createBaseInstanceData(e){const{_bufferWriter:t}=this;if(null==e||null==t.baseInstanceLayout||null==t.writeBaseInstance||null==t.elementCountBaseInstance)return null;const r=this._targetLayout("baseInstance"),s=t.elementCountBaseInstance(e.attributes),o=s*r.stride,a=new y(this._rctx,n(r));a.setSize(Math.ceil(o));const i=v(o),f=r.createView(i.buffer);t.writeBaseInstance(e.attributes,f),a.setSubData(i,0,0,o);const u=new l;return u.first=0,u.count=s,new m(e,a,u)}reallocateBuffer(e,t,r){if(this.deleteBuffer(t),null!=e){a(!this.useIndexing,"Instanced indexed rendering is not supported");const s=e.baseInstanceBuffer,o=r.geometry*this._targetStrideBytes("geometry"),n=this._instanceVboCache.newVbo(p(o));t.vao=new i(this._rctx,new Map([["baseInstance",s],["geometry",n]]))}else if(this.useIndexing){const e=r.geometry*this._targetStrideBytes("geometry"),s=this._vboCache.newVbo(p(e)),o=Math.floor(s.sizeBytes/this._bufferWriter.layout.stride)-1,n=h(o),a=r.index*n.stride,f=Math.ceil(p(a)/n.stride),u=this._rctx.indexBufferCache.newIndexBuffer(f,n.dataType);t.vao=new i(this._rctx,s,u)}else{const e=r.geometry*this._targetStrideBytes("geometry");t.vao=this._vaoCache.newVao(p(e))}const s=this._targetLayout("texture"),o=this._textureBufferCache;if(null!=s&&null!=o){const e=p(r.texture*s.stride),n=Math.ceil(e/s.stride);t.textureBuffer=o.newTextureBuffer(n)}t.endElements.geometry=Math.floor((t.vao?.getByteLength("geometry")??0)/this._targetStrideBytes("geometry")),t.endElements.texture=t.textureBuffer?.itemCount??0,t.endElements.index=t.vao?.indexBuffer?.size??0}elementCount(e,t){const{attributes:r}=e;return"geometry"===t?this._bufferWriter.elementCount(r):"baseInstance"===t?this._bufferWriter.elementCountBaseInstance?.(r)??0:"index"===t?e.drawIndices?.length??0:this._bufferWriter.elementCountTextureBuffer?.(r)??0}vertexElementCount(e){return this._bufferWriter.elementCount(e.attributes)}canGrow(e,t){const r=this.targetBuffers.map(r=>this._evaluateTargetBufferGrowth(r,e,t));return r.every(({canGrow:e})=>e)&&r.some(({needsToGrow:e})=>e)}_evaluateTargetBufferGrowth(e,t,r){const s=this._targetLayout(e,t.indexType),o=t.getTargetBuffer(e);if(null==s||null==o)return{needsToGrow:null!=s,canGrow:!0};return{needsToGrow:r[e]*s.stride>o.sizeBytes,canGrow:"geometry"===e||"index"===e?o.sizeBytes<p(w-B):o.sizeBytes<u(this._rctx,s)}}clearHoles(e,t){const{indexType:r}=t;for(const s of this.targetBuffers){const o=this._targetStrideBytes(s,r),n=e[s],a=n.reduce((e,t)=>Math.max(e,t.numElements),0)*o,i=v(a);i.fill(0,0,a);for(const e of n)this._setTargetSubData(s,t,o,e,i)}}clearHolesMetal(e,t,r){const{indexType:s}=r,{targetBuffers:o}=this,n={};let a=0;for(const u of o){const e=t[u].numElements*this._targetStrideBytes(u,s);n[u]=a,a+=V(e)}const i=v(a);i.fill(0,0,a);const f={};for(const u of o)f[u]=this._targetLayout(u,s)?.createView(i.buffer,n[u]);for(const u of e){const e=u.targetRanges.geometry;if(!(e.from>=t.geometry.from&&e.to<=t.geometry.to))continue;const r={};for(const s of o)r[s]=u.targetRanges[s].from-t[s].from;this._writeGeometry(u.geometry,f,r,u.targetRanges)}for(const u of o)this._setTargetSubData(u,r,this._targetStrideBytes(u,s),t[u],i,n[u])}writeRandomInstances(e,t,r){const{indexType:s}=r,{targetBuffers:o}=this,n={},a={},i={},f={};let u=0;for(const g of o)n[g]=e[g]*this._targetStrideBytes(g,s),a[g]=u,i[g]=0,f[g]=c.acquire(0,0),u+=V(n[g]);const l=v(u),h={};for(const c of o)h[c]=this._targetLayout(c,s)?.createView(l.buffer,a[c]);for(const c of t){for(const e of o){const t=c.targetRanges[e],o=f[e];o.to===t.from||(o.numElements>0&&this._setTargetSubData(e,r,this._targetStrideBytes(e,s),f[e],l,a[e]),o.from=t.from,i[e]=0)}this._writeGeometry(c.geometry,h,i,c.targetRanges);for(const e of o){const t=c.targetRanges[e];i[e]+=t.numElements,f[e].to=t.to}}for(const g of o){const e=f[g];e.numElements>0&&this._setTargetSubData(g,r,this._targetStrideBytes(g,s),e,l,a[g]),c.release(f[g])}}writeInstanceRangeMetal(e,t,r){const{indexType:s}=r,{targetBuffers:o}=this,n={},a={};let i=0;for(const c of o)n[c]=e[c].numElements*this._targetStrideBytes(c,s),a[c]=i,i+=V(n[c]);const f=v(i),u={};for(const c of o)u[c]=this._targetLayout(c,s)?.createView(f.buffer,a[c]);f.fill(0,0,i);for(const c of t){const t=c.targetRanges.geometry;if(!(t.from>=e.geometry.from&&t.to<=e.geometry.to))continue;const r={},s={};for(const n of o){const t=c.targetRanges[n];r[n]=t.from-e[n].from,s[n]=t}this._writeGeometry(c.geometry,u,r,s)}for(const c of o)e[c].numElements>0&&this._setTargetSubData(c,r,this._targetStrideBytes(c,s),e[c],f,a[c])}rebuildInstances(e,t,r){const{indexType:s}=r,{targetBuffers:o}=this,n={},a={},i={};let f=0;for(const c of o)n[c]=e[c]*this._targetStrideBytes(c,s),a[c]=f,f+=V(n[c]),i[c]=0;const u=v(f),l={};for(const c of o)l[c]=this._targetLayout(c,s)?.createView(u.buffer,a[c]);for(const c of t){const e={},t={};for(const r of o){e[r]=i[r],i[r]+=this.elementCount(c.geometry.geometry,r);const s=c.targetRanges[r];s.from=e[r],s.to=i[r],t[r]=s}this._writeGeometry(c.geometry,l,e,t)}for(const h of o){const e=c.acquire(0,i[h]);this._setTargetSubData(h,r,this._targetStrideBytes(h,s),e,u,a[h]),c.release(e)}return i}updateInstance(e,t){const{indexType:r}=t,{targetBuffers:s}=this,o={},n={};let a=0;for(const c of s){const t=this._targetStrideBytes(c,r);o[c]=this.elementCount(e.geometry.geometry,c)*t,n[c]=a,a+=V(o[c])}const i=v(a),f={},u={};for(const c of s)u[c]=0,f[c]=this._targetLayout(c,r)?.createView(i.buffer,n[c]);this._writeGeometry(e.geometry,f,u,e.targetRanges);for(const c of s)this._setTargetSubData(c,t,this._targetStrideBytes(c,r),e.targetRanges[c],i,n[c])}updateInstancesMetal(e){const{targetBuffers:t}=this;for(const[r,s]of e){const e={};for(const r of t)e[r]=c.acquire(1/0,-1/0);for(const r of s)for(const s of t){const t=e[s],o=r.targetRanges[s];t.from=Math.min(t.from,o.from),t.to=Math.max(t.to,o.to)}this.writeInstanceRangeMetal(e,r.instances.values(),r);for(const r of t)c.release(e[r])}}_writeGeometry(e,o,n,i){const{_bufferWriter:f}=this;if(null!=f&&(t(x,e.transformation),x[12]-=e.localOrigin.vec3[0],x[13]-=e.localOrigin.vec3[1],x[14]-=e.localOrigin.vec3[2],r(_,x),s(_,_),f.write(x,_,e.geometry.attributes,e.geometry.olidColor,o.geometry,n.geometry,i.texture),null!=o.texture&&f.writeTextureBuffer&&f.writeTextureBuffer(x,_,e.geometry.attributes,o.texture,n.texture),this.useIndexing)){const t=e.geometry.drawIndices;a(null!=o.index,"Should have an indexed view when using indexing"),a(null!=t,"Material requires vertex indices"),this._writeIndexBuffer(i.geometry,o.index,n,t)}}_writeIndexBuffer(e,t,r,s){const o=e.from,n=t,a=r.index;for(let i=0;i<s.length;++i)n[a+i]=s[i]+o}_setTargetSubData(e,t,r,s,o,n=0){if("geometry"===e){const a=t.getTargetBuffer(e);a?.setSubData(o,s.from*r,n,n+s.numElements*r)}else if("texture"===e){const r=t.getTargetBuffer(e);r?.setSubData(o.buffer,s.from,n,s.numElements)}else if("index"===e){const a=t.getTargetBuffer(e);a?.setSubData(o,s.from*r,n,n+s.numElements*r)}}static prune(){C=new Uint8Array(B)}}const x=o(),_=o(),B=262144,b=1024,w=16777216;let C=new Uint8Array(B);function v(e){return C.byteLength<e&&(C=new Uint8Array(e)),C}function V(e){return 4*Math.ceil(e/4)}function p(t){return t<=b?b:t<B?e(t):Math.max(Math.min(Math.ceil(1.5*t/B)*B,w),t)}export{d as VaoWriter};
package/views/View.d.ts CHANGED
@@ -318,11 +318,22 @@ export default abstract class View<TLayerView extends LayerView = LayerView> ext
318
318
  */
319
319
  accessor animationsEnabled: boolean;
320
320
  /**
321
- * The array of attribution items to be displayed in the view's attribution.
321
+ * The array of attribution items to be displayed in the view's attribution. This property is populated once the view has finished updating. Items are ordered based on descending [score](https://developers.arcgis.com/javascript/latest/references/core/views/support/AttributionItem/#score) with higher scored items appearing first in the attribution.
322
322
  *
323
323
  * ![attribution](https://developers.arcgis.com/javascript/latest/assets/references/core/widgets/attribution.png)
324
324
  *
325
325
  * @since 5.0
326
+ * @example
327
+ * // Access the attributionItems property after the view is finished updating to get the array of attribution items to be displayed in the view's attribution
328
+ * reactiveUtils.when(
329
+ * () => !view.updating,
330
+ * () => {
331
+ * const attributionText = view.attributionItems
332
+ * .map((item) => item.text)
333
+ * .join(" | ");
334
+ * console.log(attributionText);
335
+ * }
336
+ * );
326
337
  */
327
338
  get attributionItems(): ReadonlyArray<AttributionItem>;
328
339
  /**
@@ -646,7 +657,7 @@ export default abstract class View<TLayerView extends LayerView = LayerView> ext
646
657
  */
647
658
  get resolution(): number;
648
659
  /**
649
- * A custom selection manager that overrides the default selection manager. This property is ignored if either [Editor.syncViewSelection](https://developers.arcgis.com/javascript/latest/references/core/widgets/Editor/#syncViewSelection) or [FeatureTable.syncWithViewSelectionManager](https://developers.arcgis.com/javascript/latest/references/core/widgets/FeatureTable/#syncWithViewSelectionManager) is `true`.
660
+ * The default [SelectionManager](https://developers.arcgis.com/javascript/latest/references/core/views/SelectionManager/) for this view. Used to manage selections of features across layers.
650
661
  *
651
662
  * @since 5.0
652
663
  * @beta
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import{__decorate as t}from"tslib";import e from"../../../Graphic.js";import{createTask as i}from"../../../core/asyncUtils.js";import s from"../../../core/Collection.js";import o from"../../../core/Error.js";import{EventedAccessor as r}from"../../../core/Evented.js";import n from"../../../core/Logger.js";import{getOrCreateMapValue as a}from"../../../core/MapUtils.js";import{destroyMaybe as h,abortMaybe as p,assertIsSome as l}from"../../../core/maybe.js";import{pausable as c,when as d,watch as m,initial as u,sync as v}from"../../../core/reactiveUtils.js";import{property as y,subclass as _}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as g}from"../../../core/support/UpdatingHandles.js";import f from"../../../geometry/Point.js";import b from"../../../geometry/Polyline.js";import{fromPolylineUsingImportOperator as G,toGeometry as x}from"../../../geometry/operators/support/apiConverter.js";import{closeRingsAndFixWinding as M,geometryToCoordinates as C}from"../../../geometry/support/coordsUtils.js";import{isPoint as S}from"../../../geometry/support/typeUtils.js";import{interpolateCircle as E}from"../../../geometry/support/curves/circleUtils.js";import{deriveCircleFromCircularArc as w,toEllipticArc7 as O}from"../../../geometry/support/curves/circularArcUtils.js";import{getEndpoint as k,isCircularArc as H,isEllipticArc4 as I,isBezierCurve as L,isCoordinate as V,isEllipticArc7 as P}from"../../../geometry/support/curves/curveUtils.js";import{deriveCircleFromEllipticArc4 as R}from"../../../geometry/support/curves/ellipticArc4Utils.js";import{wrapAtan2 as T}from"../../../geometry/support/curves/mathUtils.js";import A from"../../../layers/GraphicsLayer.js";import{SnappingVisualizer2D as j}from"../../2d/interactive/SnappingVisualizer2D.js";import{ConnectedReshapeManager as U}from"./ConnectedReshapeManager.js";import{screenDeltaToMapDelta as F,cloneMove as D}from"./drawUtils.js";import z from"./GraphicMover.js";import K from"./HighlightHelper.js";import{addUniqueLayer as N,isConnectedReshapeSupportedLayer as W}from"./layerUtils.js";import{createTooltipInfos as q,connectTooltip as Z,updateTranslateTooltipInfo as $,updateTranslateVertexTooltipInfo as B}from"./reshapeTooltipUtils.js";import{defaultSymbols as J,createMidpointGraphics as Q,createVertexGraphics as X,createCurveControlPointGraphics as Y,createCurveConstructionLineGraphics as tt,attributeKeys as et,getMidpoint as it,controlPointKinds as st,saveUpdatedCurveOrCoordinate as ot,toolIdAttribute as rt,splitCurve as nt,isSingleSegmentCircle as at,isSingleSegmentEllipse as ht}from"./reshapeUtils.js";import{ViewEventPriorities as pt}from"../../input/InputManager.js";import{createCoordinateHelper as lt}from"../../interactive/coordinateHelper.js";import{sketchKeys as ct}from"../../interactive/keybindings.js";import{EditGeometryOperations as dt}from"../../interactive/editGeometry/EditGeometryOperations.js";import mt from"../../interactive/sketch/SketchOptions.js";import{SnappingContext as ut}from"../../interactive/snapping/SnappingContext.js";import{makeTooltip as vt,enterInputModeIfAvailable as yt}from"../../interactive/tooltip/tooltipCommonUtils.js";import{MeasurementWorkerHandle as _t}from"../../support/MeasurementWorkerHandle.js";const gt=Symbol(),ft={mode:"on-the-ground",offset:0};let bt=class extends r{constructor(t){super(t),this._updateHandlesOnExternalGeometryChange=null,this._activeOperationInfo=null,this._connectedReshapeManager=null,this._editGeometryOperations=null,this._segmentLabels=null,this._segmentLabelsImportTask=null,this._mover=null,this._snappingContext=null,this._snappingGraphicsLayer=null,this._hoverGraphic=null,this._snappingTask=null,this._stagedVertex=null,this._updatingHandles=new g,this._measurementWorker=new _t({preloadGeodetic:!0}),this.callbacks={onReshapeStart(){},onReshape(){},onReshapeStop(){},onMoveStart(){},onMove(){},onMoveStop(){},onGraphicClick(){}},this.connectedReshapeProviders=null,this.enableMidpoints=!0,this.enableCurveOnMidpoint=!1,this.enableMovement=!0,this.enableVertices=!0,this.graphic=null,this.highlightName=null,this.highlightsEnabled=!0,this.layer=null,this.snappingManager=null,this.symbols=J,this.tooltip=null,this.activeTooltipInfo=null,this.sketchOptions=new mt,this.type="reshape",this.vertexGraphics=new s,this.curveControlPointGraphics=new s,this.constructionLineGraphics=new s,this.midpointGraphics=new s,this.selectedManipulators=new s,this.view=null}initialize(){const t=this.view;this._highlightHelper=new K({view:t}),this._setup(),this._updateHandlesOnExternalGeometryChange=c(()=>this.graphic?.geometry,t=>{if(!t)return;const e=new Set(this.selectedManipulators.map(Ht));this._highlightHelper.removeAll(),this._setUpHighlights(),this._setupGraphics(),this._clearSelection(),this.vertexGraphics.filter(t=>e.has(Ht(t))).forEach(t=>this._addToSelection(t));const{enableMovement:i,_mover:s,graphic:o,midpointGraphics:r,vertexGraphics:n,curveControlPointGraphics:a}=this,h=n.concat(r,a).toArray();i&&h.push(o),s?.set("graphics",h)},v),this.tooltip=vt(()=>({view:t,options:this.sketchOptions.tooltips})),this.tooltipInfos=q(this.sketchOptions),this.addHandles([d(()=>t?.ready,()=>{const{layer:t,view:e}=this;N(e,t),this.addHandles(e.on("key-down",t=>this._keyDownHandler(t),pt.TOOL))},{once:!0,initial:!0}),m(()=>this.graphic,()=>this.refresh()),m(()=>this.layer,(t,e)=>{e&&(this._clearSelection(),this._resetGraphics(e)),this.refresh()}),m(()=>[this.highlightsEnabled,this.highlightName],()=>{this._highlightHelper?.removeAll(),this._setUpHighlights()}),m(()=>this.enableMidpoints,()=>this.refresh()),Z(this.tooltip,()=>this._tooltipsContext,this._updatingHandles),m(()=>this.sketchOptions.labels.enabled,t=>{this._segmentLabels?this._segmentLabels.visible=t:this._setUpGeometryHelper()}),m(()=>this.view.effectiveTheme.accentColor,()=>this._updateSymbolsForTheme(),u),this._updateHandlesOnExternalGeometryChange]),this._updateTooltip()}destroy(){this._reset(),this._mover=h(this._mover),this._connectedReshapeManager=h(this._connectedReshapeManager),this.tooltip=h(this.tooltip),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._updatingHandles=h(this._updatingHandles),this._measurementWorker.destroy()}get _coordinateHelper(){return this._editGeometryOperations?.data.coordinateHelper??lt(!!this.graphic.geometry?.hasZ,!!this.graphic.geometry?.hasM,this.view.spatialReference)}get test(){return{segmentLabels:this._segmentLabels}}get _selectedManipulator(){return 1===this.selectedManipulators.length?this.selectedManipulators.at(0):void 0}get _tooltipsContext(){const{sketchOptions:t,activeTooltipInfo:e,graphic:i}=this;return{sketchOptions:t,activeTooltipInfo:e,graphic:i,selectedVertex:this._selectedManipulator,measurementWorker:this._measurementWorker,updateGeometry:(t,e,i,s,o)=>{this._setUpGeometryHelper();const r=t===this.graphic;r?this._emitMoveStartEvent(0,0):this._emitReshapeStartEvent(t);const n=!0;if(this._syncGeometryAfterVertexMove(t,e,s,o,n),r){const{view:t}=this,s=t.toScreen(i),o=t.toScreen(e),r=(o?.x??0)-(s?.x??0),n=(o?.y??0)-(s?.y??0);this._emitMoveEvent(r,n),this._emitMoveStopEvent(r,n)}else this._emitReshapeEvent(t),this._emitReshapeStopEvent(t)}}}get state(){const t=this.view.ready,e=!(!this.graphic||!this.layer);return t&&e?"active":t?"ready":"disabled"}get updating(){return this._updatingHandles.updating||!!this._segmentLabels?.updating}isUIGraphic(t){return t===this.graphic||this._isMidpoint(t)||this._isCurveControlPoint(t)||this._isVertex(t)||this._isConstructionLine(t)}refresh(){this._reset(),this._setup()}reset(){this.graphic=null}clearSelection(){this._clearSelection()}removeSelectedVertices(){const{selectedManipulators:t}=this;t.length&&this._removeVertices(t)}_setup(){const{graphic:t,layer:e}=this;if(!e||null==t?.geometry)return;const i=t.geometry;"mesh"!==i.type&&"extent"!==i.type?("polygon"===i.type&&M(i),this._setUpHighlights(),this._setupGraphics(),this._setupMover(),this._setupConnectedReshapeManager(),this._setUpGeometryHelper()):this._logGeometryTypeError()}_setUpHighlights(){this.highlightsEnabled&&this.graphic&&this._highlightHelper?.add(this.graphic,this.highlightName)}_setUpGeometryHelper(){const t=this.graphic.geometry;if(null==t||"mesh"===t.type||"extent"===t.type)return this._segmentLabels=h(this._segmentLabels),void this._logGeometryTypeError();this._editGeometryOperations?this._syncEditGeometryOperations(t):this._editGeometryOperations=dt.fromGeometry(t,2,{allowCurves:!0}),this._updatingHandles.consumePromise(this._setupSegmentLabels())}_saveSnappingContextForHandle(t,e){this._snappingGraphicsLayer=new A({listMode:"hide",internal:!0,title:"Reshape snapping layer"}),this.view.map.layers.add(this._snappingGraphicsLayer);const i=this._editGeometryOperations;l(i),this._snappingContext=new ut({editGeometryOperations:i,elevationInfo:ft,pointer:e.viewEvent?.pointerType||"mouse",excludeFeature:this.graphic,feature:this.graphic,visualizer:new j(this._snappingGraphicsLayer),vertexHandle:this._getVertexFromEditGeometry(t)})}_reset(){this._clearSelection(),this._highlightHelper?.removeAll(),this._updateTooltip(),this._resetGraphics(),this._resetSnappingStateVars(),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._activeOperationInfo=null,this._mover=h(this._mover),this.removeHandles(gt)}_resetSnappingStateVars(){null!=this.snappingManager&&this.snappingManager.doneSnapping(),null!=this._snappingGraphicsLayer&&(this.view?.map&&this.view.map.layers.remove(this._snappingGraphicsLayer),this._snappingGraphicsLayer.destroy()),this._snappingTask=p(this._snappingTask),this._snappingTask=null,this._snappingContext=null,this._stagedVertex=null}_resetGraphics(t){this._removeMidpointGraphics(t),this._removeVertexGraphics(t),this._removeCurveGraphics(t),this._updateTooltip()}_removeMidpointGraphics(t=this.layer){const{midpointGraphics:e}=this;t?.removeMany(e.items),e.drain(h)}_removeVertexGraphics(t=this.layer){const{vertexGraphics:e}=this;t?.removeMany(e.items),e.drain(h)}_removeCurveGraphics(t=this.layer){const{curveControlPointGraphics:e,constructionLineGraphics:i}=this;t?.removeMany(e.items),t?.removeMany(i.items),e.drain(h),i.drain(h)}_setupGraphics(){const t=this.graphic.geometry;if(null!=t&&("polyline"===t.type||"polygon"===t.type||"multipoint"===t.type)){const e=Gt(t);this.enableMidpoints&&"multipoint"!==t.type&&this._setUpMidpointGraphics(e),this.enableVertices&&(this._setUpVertexGraphics(e),this._setupCurveGraphics(e))}}_setUpMidpointGraphics(t){this._removeMidpointGraphics();const e=Q(t,this.symbols,this._coordinateHelper,"polygon"===this.graphic.geometry?.type);this.midpointGraphics.addMany(e),this.layer.addMany(e)}_setUpVertexGraphics(t){this._removeVertexGraphics();const e=X(t,this.symbols,this._coordinateHelper);this.vertexGraphics.addMany(e),this._storeRelatedVertexIndices(),this.layer.addMany(e)}_setupCurveGraphics(t){this._removeCurveGraphics();const e=Y(t,this.symbols,this._coordinateHelper),i=tt(t,this.symbols,this._coordinateHelper);this.curveControlPointGraphics.addMany(e),this.constructionLineGraphics.addMany(i),this.layer.addMany(i),this.layer.addMany(e)}async _setupSegmentLabels(){const t=this._editGeometryOperations,e=this.sketchOptions.labels.enabled;if(t&&this._segmentLabels?.context?.editGeometryOperations===t&&e||(this._segmentLabels=h(this._segmentLabels)),!this._segmentLabels&&t&&e){const e=this._segmentLabelsImportTask??=i(async t=>{const e=import("../../2d/interactive/SegmentLabels2D.js"),{SegmentLabels2D:i}=await this._updatingHandles.addPromise(e);return t.aborted?null:i}),s=await e.promise;if(!s)return;this._segmentLabels=h(this._segmentLabels),this._segmentLabels=new s({context:{view:this.view,editGeometryOperations:t,elevationInfo:ft,labelOptions:this.sketchOptions.labels},visible:!0})}}_updateSymbolsForTheme(){const t=this.view.effectiveTheme.accentColor;this.symbols={vertices:{...this.symbols.vertices,default:this.symbols.vertices.default.clone().set("color",t),hover:this.symbols.vertices.hover?.clone().set("color",t)},controlPoints:{...this.symbols.controlPoints,default:this.symbols.controlPoints.default.clone().set("color",t),hover:this.symbols.controlPoints.hover?.clone().set("color",t)},midpoints:{...this.symbols.midpoints},constructionLines:this.symbols.constructionLines.clone().set("color",t)};for(const e of this.vertexGraphics)this._isSelected(e)?e.symbol=this.symbols.vertices.selected:this._hoverGraphic===e?e.symbol=this.symbols.vertices.hover:e.symbol=this.symbols.vertices.default;for(const e of this.curveControlPointGraphics)this._isSelected(e)?e.symbol=this.symbols.controlPoints.selected:this._hoverGraphic===e?e.symbol=this.symbols.controlPoints.hover:e.symbol=this.symbols.controlPoints.default;for(const e of this.constructionLineGraphics)e.symbol=this.symbols.constructionLines}_storeRelatedVertexIndices(){const t=this.vertexGraphics.items;if(!t)return;const e=t.map(({geometry:t})=>({x:t.x,y:t.y}));for(let i=0;i<e.length;i++){const s=[];for(let t=0;t<e.length;t++){if(i===t)continue;const o=e[i],r=e[t];o.x===r.x&&o.y===r.y&&s.push(t)}t[i].attributes[et.relatedGraphicIndices]=s}}_setupMover(){const{enableMovement:t,graphic:e,midpointGraphics:i,vertexGraphics:s,view:o}=this,r=s.concat(i,this.curveControlPointGraphics).toArray();t&&"multipoint"!==e.geometry?.type&&r.push(e),this._mover=new z({enableMoveAllGraphics:!1,highlightsEnabled:!1,indicatorsEnabled:!1,graphics:r,view:o,callbacks:{onGraphicClick:t=>this._onGraphicClickCallback(t),onGraphicMoveStart:t=>this._onGraphicMoveStartCallback(t),onGraphicMove:t=>this._onGraphicMoveCallback(t),onGraphicMoveStop:t=>this._onGraphicMoveStopCallback(t),onGraphicPointerOver:t=>this._onGraphicPointerOverCallback(t),onGraphicPointerOut:t=>this._onGraphicPointerOutCallback(t)}})}_setupConnectedReshapeManager(){const{connectedReshapeProviders:t}=this;null!=t&&0!==t.length&&(this._connectedReshapeManager=new U({providerFactories:t,view:this.view}))}_onGraphicClickCallback(t){t.viewEvent.stopPropagation();const e=t.graphic,i=this._isCurveControlPoint(e);if(e===this.graphic)this.clearSelection(),this.emit("graphic-click",t),this.callbacks.onGraphicClick?.(t);else if(this._isMidpoint(e)){if(2===t.viewEvent.button)return;const i=this.graphic.clone(),s=this._handleMidpointClickOrStartMove(t);this.refresh(),s.length&&this._emitVertexAddEvent([e],i,s)}else if(this._isVertex(e)||i){if(t.viewEvent.stopPropagation(),2===t.viewEvent.button)return void(i||this._removeVertices(e));t.viewEvent.native.shiftKey||this._clearSelection(),this.selectedManipulators.includes(e)?this._removeFromSelection(e,!0):this._addToSelection(e)}}_setUpOperation(t){const{graphic:e,dx:i,dy:s}=t,o=e===this.graphic;this._resetSnappingStateVars(),this._setUpGeometryHelper(),this._saveSnappingContextForHandle(e,t),this._activeOperationInfo={target:this.graphic,mover:e,operationType:o?"move":"reshape",totalDx:i,totalDy:s}}_onGraphicMoveStartCallback(t){const{dx:e,dy:i,graphic:s}=t,o=this._connectedReshapeManager,r=o?Lt(this.graphic):null;if(s===this.graphic){const{geometry:n}=s;return this._setUpOperation(t),this._emitMoveStartEvent(e,i),r&&o?.startFeatureMove([r]),void(null!=n&&"point"===n.type&&this._onHandleMove(s,e,i,t,()=>{this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(e,i)}))}const{selectedManipulators:n}=this;if(!n.includes(s)){if(this._clearSelection(),this._isMidpoint(s)){const e=this.graphic.clone(),i=this._handleMidpointClickOrStartMove(t);i.length&&(this._emitVertexAddEvent([s],e,i),this._refreshGraphicIndicesAttributes(i[0]))}this._addToSelection(s)}if(this._setUpOperation(t),r){const t=n.filter(t=>this._isVertex(t));o?.startVertexMove(r,Vt(t))}this._emitReshapeStartEvent(s),this._onHandleMove(s,e,i,t,()=>{this._updateTooltip(s,t.viewEvent),this._emitReshapeEvent(s)})}_onGraphicMoveCallback(t){const e=this._activeOperationInfo;if(!e)return;const{dx:i,dy:s,graphic:o}=t;e.totalDx+=i,e.totalDy+=s;const{operationType:r}=e,{geometry:n}=o;if(null!=n)if("move"!==r)this._onHandleMove(o,i,s,t,()=>{this._updateTooltip(o,t.viewEvent),this._emitReshapeEvent(o)});else{if("point"===n.type)this._onHandleMove(o,i,s,t,()=>{this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(i,s)});else if("polyline"===n.type||"polygon"===n.type){const e=Gt(n);this._updateVertexGraphicLocations(e);const{dxMap:o,dyMap:r}=F(i,s,this.view);this._connectedReshapeManager?.translate(o,r,0),this._updateTooltip(this.graphic,t.viewEvent),this._emitMoveEvent(i,s)}this._syncEditGeometryOperations(n)}}_onGraphicMoveStopCallback(t){const e=this._activeOperationInfo;if(!e)return;const{dx:i,dy:s,graphic:o}=t,{operationType:r}=e;e.totalDx+=i,e.totalDy+=s,this._onHandleMove(o,i,s,t,()=>"move"===r?this._emitMoveStopEvent():this._emitReshapeStopEvent(o)),this._isMidpoint(o)||o.getAttribute(et.curveFromStraightEdgeFlag)?this.refresh():(this._updateTooltip(this._isVertex(o)?o:null),this._resetSnappingStateVars(),this._connectedReshapeManager?.finish(),this._activeOperationInfo=null)}_updateVertexGraphicLocations(t){const{_coordinateHelper:e}=this;for(const i of this.vertexGraphics){const{pathIndex:s,pointIndex:o}=i.attributes;i.geometry=e.arrayToPoint(k(t[s][o]))}this._updateMidpointGraphicLocations(t),this._updateCurveGraphicLocations(t)}_updateMidpointGraphicLocations(t){const{_coordinateHelper:e}=this;for(const i of this.midpointGraphics){const{pathIndex:s,pointIndexStart:o,pointIndexEnd:r}=i.attributes,n=t[s];i.geometry=it(n[o],n[r],e)}}_updateCurveGraphicLocations(t){const{spatialReference:e}=this._coordinateHelper,i=new Map;for(const s of this.selectedManipulators){const[t,e]=kt(s);null!=t&&null!=e&&s.getAttribute(et.controlPointKind)&&a(i,t,()=>new Set)?.add(e)}for(const s of this.curveControlPointGraphics){const[e,o]=kt(s);if(i.get(e)?.has(o))continue;const r=t[e][o];if(H(r)||I(r)){const i=k(t[e][o-1]),n=H(r)?w(i,r):R(i,r),[a,h]=E(n,.25);s.geometry=new f({x:a,y:h,spatialReference:this._coordinateHelper.spatialReference})}else if(L(r)){const t=s.getAttribute(et.controlPointKind),[e,i]=t===st.bezier.cp1?r.b[1]:r.b[2];s.geometry=new f({x:e,y:i,spatialReference:this._coordinateHelper.spatialReference})}}for(const s of this.constructionLineGraphics){const i=s.getAttribute(et.controlPointKind),[o,r]=kt(s),n=t[o],a=k(n[r-1]),h=k(n[r]),p=t[o][r];i===st.bezier.line1?s.geometry=new b({paths:[[[a[0],a[1]],[...p.b[1]]]],spatialReference:e}):s.geometry=new b({paths:[[[h[0],h[1]],[...p.b[2]]]],spatialReference:e})}}_refreshGraphicIndicesAttributes(t){const{componentIndex:e,vertexIndex:i}=t,s=t=>{const[s,o]=kt(t);s===e&&o>=i&&t.setAttribute(et.pointIndex,o+1)};this.vertexGraphics.forEach(s),this.curveControlPointGraphics.forEach(s),this.constructionLineGraphics.forEach(s);for(const o of this.midpointGraphics){if(o.getAttribute(et.pathIndex)!==e)continue;const t=o.getAttribute(et.pointIndexStart);t>=i&&(o.setAttribute(et.pointIndexStart,t+1),o.setAttribute(et.pointIndexEnd,o.getAttribute(et.pointIndexEnd)+1))}}_getVertexFromEditGeometry(t){const[e,i]=kt(t);return l(this._editGeometryOperations),this._editGeometryOperations.data.parts[e].vertices[i]}_onHandleMove(t,e,s,o,r){p(this._snappingTask);const n=this._snappingContext;if(!n)return;const a=t.geometry,h="graphic-move-stop"===o.type;if(a&&S(a))if(null!=this.snappingManager&&this.selectedManipulators.length<2&&!h){const o=this.snappingManager;this._stagedVertex=o.update({point:a,context:n}),this._syncGeometryAfterVertexMove(t,new f(this._stagedVertex),e,s,h),r(),this._snappingTask=i(async i=>{const p=await o.snap({point:a,context:n,signal:i});p.valid&&(this._stagedVertex=p.apply(),this._syncGeometryAfterVertexMove(t,new f(this._stagedVertex),e,s,h),r())})}else{const i=null!=this._stagedVertex?new f(this._stagedVertex):a;this._syncGeometryAfterVertexMove(t,i,e,s,h),r()}else r()}_syncGeometryAfterVertexMove(t,e,i,s,o=!1){const r=this._editGeometryOperations?.data.geometry.clone();if(!r)return;const{_coordinateHelper:n}=this,a=n.pointToVector(e),h=this._getVertexFromEditGeometry(t);if(h){const t=n.getZ(a),e=a[0]-h.pos[0],i=a[1]-h.pos[1],s=null!=t?t-h.pos[2]:0;"point"!==r.type&&"mesh"!==r.type||this._editGeometryOperations?.moveVertices([h],e,i,s),this._connectedReshapeManager?.translate(e,i,s)}if("point"===r.type)t.geometry=e;else if("mesh"===r.type)t.geometry=r.centerAt(e);else{if(t!==this.graphic){const o=n.spatialReference,[a,h]=kt(t);let p=xt(r);const l=n.pointToArray(e);this._updateGeometryFromGraphic(t,p,a,h,l,o,"polygon"===r.type),this._isVertex(t)||this._isCurveControlPoint(t)?(p=this._moveRelatedCoordinates(p,t,l),p=this._moveSelectedHandleCoordinates(p,t,i,s,"polygon"===r.type),this._updateMidpointGraphicLocations(p),this._updateCurveGraphicLocations(p)):this._isMidpoint(t)&&this._updateCurveGraphicLocations(p),ot(r,p)}this._updateGraphicGeometry(r),this._syncEditGeometryOperations(r),o&&(this._mover?this._mover.updateGeometry(this._mover.graphics.indexOf(t),e):t.geometry=e)}}_syncEditGeometryOperations(t){const e=this._editGeometryOperations?.trySetGeometry(t);e||(this._editGeometryOperations=null,this._setUpGeometryHelper())}_moveRelatedCoordinates(t,e,i){const{relatedGraphicIndices:s}=e.attributes,o=this._coordinateHelper.spatialReference;if(!s?.length)return t;for(const r of s){const s=this.vertexGraphics.at(r),[n,a]=kt(s);Ot(t,n,a,i,o),s.geometry=e.geometry}return t}_moveSelectedHandleCoordinates(t,e,i,s,o){const r=this._coordinateHelper.spatialReference;for(const n of this.selectedManipulators)if(n!==e){const[e,a]=kt(n),h=n.getAttribute(et.relatedGraphicIndices),p=D(n.geometry,i,s,this.view),l=C(p);if(n.geometry=p,this._updateGeometryFromGraphic(n,t,e,a,l,r,o),h?.length)for(const i of h){const e=this.vertexGraphics.at(i),[s,o]=kt(e);Ot(t,s,o,l,r),e.geometry=p}}return t}_updateGeometryFromGraphic(t,e,i,s,o,r,n){const a=e[i].length-1;this._isCurveControlPoint(t)?Ct(e,i,s,[o[0],o[1]],t.getAttribute(et.controlPointKind)):(Ot(e,i,s,o,r),n&&(0===s?Ot(e,i,a,o,r):s===a&&(e[i][0]=o)))}_onGraphicPointerOverCallback(t){const e=t.graphic;this._hoverGraphic=e;const i=this._isVertex(e);i&&!this._isSelected(e)?e.symbol=this.symbols.vertices.hover:this._isCurveControlPoint(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.controlPoints.hover),this._updateTooltip(i?e:null),this._updateHoverCursor(e)}_onGraphicPointerOutCallback(t){const e=t.graphic;this._hoverGraphic=null,this._isVertex(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.vertices.default),this._isCurveControlPoint(e)&&!this._isSelected(e)&&(e.symbol=this.symbols.controlPoints.default),this.removeHandles(gt),this._updateTooltip()}_handleMidpointClickOrStartMove(t){const{graphic:e}=t,i=this.graphic.geometry;if(null==i||"polygon"!==i.type&&"polyline"!==i.type)return[];const s=i.clone(),o=[],{[et.pathIndex]:r,[et.pointIndexStart]:n,[et.pointIndexEnd]:a}=e.attributes,h=C(e.geometry),p=0===a?n+1:a;e.attributes={[et.tool]:rt,[et.pathIndex]:r,[et.pointIndex]:p,[et.relatedGraphicIndices]:[]};const l=xt(s),c=l[r][a];if(V(c)){if(this.enableCurveOnMidpoint&&t.viewEvent.native.shiftKey){const t=k(l[r][p]);l[r].splice(p,1,{c:[t,[h[0],h[1]]]}),e.setAttribute(et.controlPointKind,st.circle.interior),e.setAttribute(et.curveFromStraightEdgeFlag,!0),this.midpointGraphics.remove(e),this.curveControlPointGraphics.push(e),ot(s,l)}else l[r].splice(p,0,h),o.push({coordinates:l[r][p],componentIndex:r,vertexIndex:p})}else{const t=k(l[r][n]),e=nt(t,c,.5,this._coordinateHelper);l[r].splice(a,1,...e),o.push({coordinates:k(l[r][p]),componentIndex:r,vertexIndex:p})}return this._updateGraphicGeometry(s),this._syncEditGeometryOperations(s),o}_addToSelection(t){const e=It(t);for(const i of e)this._isCurveControlPoint(i)?i.symbol=this.symbols.controlPoints.selected:i.symbol=this.symbols.vertices.selected,this.selectedManipulators.add(i),this._updateTooltip(i);this._emitSelectEvent(e)}_removeFromSelection(t,e){if(this._isVertex(t)){const{vertices:i}=this.symbols;t.symbol=e?i.hover:i.default}else if(this._isCurveControlPoint(t)){const{controlPoints:i}=this.symbols;t.symbol=e?i.hover:i.default}this.selectedManipulators.remove(t),this._emitDeselectEvent([t]),this._updateTooltip()}_clearSelection(){const t=this.selectedManipulators.toArray(),{controlPoints:e,vertices:i}=this.symbols;if(t.length>0){for(const s of t)this._isVertex(s)?s.symbol=i.default:this._isCurveControlPoint(s)&&(s.symbol=e.default);this.selectedManipulators.removeAll(),this._emitDeselectEvent(t),this._updateTooltip()}}_keyDownHandler(t){null==this._activeOperationInfo&&yt(t,this.tooltip)||ct.delete.includes(t.key)&&!t.repeat&&this.selectedManipulators.length&&(this._removeVertices(this.selectedManipulators),t.stopPropagation())}_removeVertices(t){const e=this.graphic.geometry,i=this.vertexGraphics.length;if(null==e||"polygon"!==e.type&&"polyline"!==e.type&&"multipoint"!==e.type)return;if("polygon"===e.type&&i<4||"multipoint"===e.type&&i<2||"polyline"===e.type&&i<3)return;const s=this.graphic.clone(),o=e.clone();let r=xt(o);const n=[],a=It(t);for(const h of a){if(this._isCurveControlPoint(h))continue;const{x:t,y:e}=h.geometry;for(let i=0;i<r.length;i++){const s=r[i];for(let o=0;o<s.length;o++){const[a,h]=k(s[o]);if(t===a&&e===h){n.push({coordinates:k(r[i][o]),componentIndex:i,vertexIndex:o}),r[i].splice(Number(o),1);const t=r[i][o];t&&!V(t)&&(r[i][o]=k(t))}}}}if("polygon"===o.type)r=r.filter(t=>{if(t.length<2)return!1;const[e,i]=k(t[0]),[s,o]=k(t[t.length-1]);return(2!==t.length||e!==s||i!==o)&&(e===s&&i===o||t.push(t[0]),!0)});else if("polyline"===o.type)for(const h of r)1===h.length&&r.splice(r.indexOf(h),1);ot(o,r),this._updateGraphicGeometry(o),this.refresh(),this._emitVertexRemoveEvent(a,s,n)}_isVertex(t){return this.vertexGraphics.includes(t)}_isCurveControlPoint(t){return this.curveControlPointGraphics.includes(t)}_isConstructionLine(t){return this.constructionLineGraphics.includes(t)}_isSelected(t){return(this._isVertex(t)||this.curveControlPointGraphics.includes(t))&&this.selectedManipulators.includes(t)}_isMidpoint(t){return this.midpointGraphics.includes(t)}_updateHoverCursor(t){const e=this._isMidpoint(t)?"copy":"move";this.addHandles(this.view.acquireCursor(e,"high"),gt)}_updateTooltip(t,e){let i=null;const{graphic:s,view:o,tooltipInfos:r}=this,n=s?.geometry;"point"===n?.type?i=r.movePoint:this._selectedManipulator?i=r.selectedVertex:t===this.graphic?(i=r.translateGraphic,$(i,o,this._tooltipsContext,this._updatingHandles,e)):t&&this.selectedManipulators.length>1&&(i=r.translateVertices,B(i,o,n,this._tooltipsContext,this._updatingHandles,e)),this.activeTooltipInfo=i}_updateGraphicGeometry(t){this._updateHandlesOnExternalGeometryChange?.pause(),this.graphic.geometry=t,this._updateHandlesOnExternalGeometryChange?.resume()}_emitMoveStartEvent(t,e){const i={type:"move-start",mover:this.graphic,dx:t,dy:e};this.emit("move-start",i),this.callbacks.onMoveStart?.(i)}_emitMoveEvent(t,e){const i={type:"move",mover:this.graphic,dx:t,dy:e};this.emit("move",i),this.callbacks.onMove?.(i)}_emitMoveStopEvent(t,e){if(null==t||null==e){const i=this._activeOperationInfo;if(!i)return;t=i.totalDx,e=i.totalDy}const i={type:"move-stop",mover:this.graphic,dx:t,dy:e};this.emit("move-stop",i),this.callbacks.onMoveStop?.(i)}_emitReshapeStartEvent(t){const e={type:"reshape-start",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape-start",e),this.callbacks.onReshapeStart?.(e)}_emitReshapeEvent(t){const e={type:"reshape",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape",e),this.callbacks.onReshape?.(e)}_emitReshapeStopEvent(t){const e={type:"reshape-stop",graphic:this.graphic,mover:t,selected:this.selectedManipulators.toArray()};this.emit("reshape-stop",e),this.callbacks.onReshapeStop?.(e)}_emitSelectEvent(t){const e={type:"vertex-select",added:t};this.emit("select",e),this.callbacks.onVertexSelect?.(e)}_emitDeselectEvent(t){const e={type:"vertex-deselect",removed:t};this.emit("deselect",e),this.callbacks.onVertexDeselect?.(e)}_emitVertexAddEvent(t,e,i){const s={type:"vertex-add",added:t,graphic:this.graphic,oldGraphic:e,vertices:i};this.emit("vertex-add",s),this.callbacks.onVertexAdd?.(s)}_emitVertexRemoveEvent(t,e,i){const s={type:"vertex-remove",removed:t,graphic:this.graphic,oldGraphic:e,vertices:i};this.emit("vertex-remove",s),this.callbacks.onVertexRemove?.(s)}_logGeometryTypeError(){n.getLogger(this).error(new o("reshape:invalid-geometry","Reshape operation not supported for the provided graphic. The geometry type is not supported."))}};function Gt(t){const e=xt(t.clone());if("polygon"===t.type)for(const i of e){const t=i[i.length-1];if(!V(t))continue;const e=i[0];e[0]===t[0]&&e[1]===t[1]&&i.length>2&&i.pop()}return e}function xt(t){return"polygon"===t.type?t.curveRings?.slice()??t.rings.slice():"polyline"===t.type?t.curvePaths?.slice()??t.paths.slice():t.points.map(t=>[t])}function Mt(t,e,i,s){const o=t[e][i];if(H(o))o.c[1]=s;else if(I(o)){const o=k(t[e][i]);t[e][i]={c:[o,s]}}}function Ct(t,e,i,s,o){switch(o){case st.circle.interior:Mt(t,e,i,s);break;case st.bezier.cp1:t[e][i].b[1]=s;break;case st.bezier.cp2:t[e][i].b[2]=s}}function St(t,e){return t<1e-8*e}function Et(t,{cx:e,cy:i,isInvalid:s,thetaStart:o,thetaEnd:r},n,a){const[h,p]=t,[l,c]=n,d=l-h,m=c-p;e-=h,i-=p;const u=a?o>r:o<r,[v,y]=s?[e,i]:u?[-i,e]:[i,-e],[_,g]=[d,m],[f,b]=[v,y],G=_*b-g*f,x=(d**2+m**2)/2;if(St(Math.abs(G),x))return[(h+l)/2,(p+c)/2];const[M,C]=[b/G*x,-f/G*x],S=M**2+C**2,[E,w]=[d/2-M,m/2-C];if(St(E**2+w**2,S)){const[t,e]=u?[-C,M]:[C,-M];return[t+M+h,e+C+p]}const O=Math.sqrt((M**2+C**2)/(E**2+w**2))*Math.sign(d*v+m*y);return[E*O+M+h,w*O+C+p]}function wt(t,e,i){const s=G(new b({curvePaths:[[t,e]],spatialReference:i})),{curvePaths:o}=x(s,i),r=o[0][1];return P(r)?r:O(t,r)}function Ot(t,e,i,s,o){const r=t[e][i],n=t[e].at(i+1);if(at(t,e)){const i=t[e][1];return t[e][0]=[...s],void(t[e][1]={a:[[...s],[...i.a[1]],0,0]})}if(ht(t,e)){const i=t[e][1],[o,r]=i.a[1],[n,a]=s,h=Math.hypot(n-o,a-r),[p,l]=[n-o,a-r],c=T(l,p);return t[e][0]=[...s],void(t[e][1]={a:[[...s],[...i.a[1]],0,0,c,h,i.a[6]]})}const a=k(r);if(V(r))r.splice(0,r.length,...s);else if(L(r))r.b[0].splice(0,r.b[0].length,...s);else if(H(r)||I(r)){const o=k(t[e][i-1]),n=H(r)?w(o,r):R(o,r);t[e].splice(i,1,{c:[[...s],Et(o,n,s,!0)]})}else if(P(r)){r.a[0].splice(0,r.a[0].length,...s);const n=k(t[e][i-1]);r.a=wt(n,r,o).a}if(n&&!V(n)&&!L(r))if(H(n)||I(n)){const o=k(n),r=H(n)?w(a,n):R(a,n);t[e].splice(i+1,1,{c:[o,Et(o,r,s,!1)]})}else if(P(n)){const t=k(r);n.a=wt(t,n,o).a}}function kt({attributes:t}){return[t?.[et.pathIndex]||0,t?.[et.pointIndex]||0]}function Ht({attributes:t}){return`${t?.[et.pathIndex]}-${t?.[et.pointIndex]}`}function It(t){return t instanceof e?[t]:[...t]}function Lt(t){const e=t.sourceLayer??t.layer;return W(e)?{graphic:t,layer:e}:null}function Vt(t){return t.toArray().map(({attributes:t})=>({pathIndex:t[et.pathIndex],vertexIndex:t[et.pointIndex]}))}t([y()],bt.prototype,"_activeOperationInfo",void 0),t([y()],bt.prototype,"_connectedReshapeManager",void 0),t([y()],bt.prototype,"_coordinateHelper",null),t([y()],bt.prototype,"_editGeometryOperations",void 0),t([y()],bt.prototype,"_segmentLabels",void 0),t([y()],bt.prototype,"test",null),t([y()],bt.prototype,"_segmentLabelsImportTask",void 0),t([y()],bt.prototype,"_updatingHandles",void 0),t([y()],bt.prototype,"_selectedManipulator",null),t([y()],bt.prototype,"_tooltipsContext",null),t([y()],bt.prototype,"callbacks",void 0),t([y()],bt.prototype,"connectedReshapeProviders",void 0),t([y()],bt.prototype,"enableMidpoints",void 0),t([y()],bt.prototype,"enableCurveOnMidpoint",void 0),t([y()],bt.prototype,"enableMovement",void 0),t([y()],bt.prototype,"enableVertices",void 0),t([y()],bt.prototype,"graphic",void 0),t([y()],bt.prototype,"highlightName",void 0),t([y()],bt.prototype,"highlightsEnabled",void 0),t([y()],bt.prototype,"layer",void 0),t([y()],bt.prototype,"snappingManager",void 0),t([y({readOnly:!0})],bt.prototype,"state",null),t([y()],bt.prototype,"symbols",void 0),t([y()],bt.prototype,"tooltip",void 0),t([y()],bt.prototype,"tooltipInfos",void 0),t([y()],bt.prototype,"activeTooltipInfo",void 0),t([y()],bt.prototype,"updating",null),t([y({type:mt})],bt.prototype,"sketchOptions",void 0),t([y({readOnly:!0})],bt.prototype,"type",void 0),t([y({readOnly:!0})],bt.prototype,"vertexGraphics",void 0),t([y({readOnly:!0})],bt.prototype,"curveControlPointGraphics",void 0),t([y({readOnly:!0})],bt.prototype,"constructionLineGraphics",void 0),t([y({readOnly:!0})],bt.prototype,"midpointGraphics",void 0),t([y({readOnly:!0})],bt.prototype,"selectedManipulators",void 0),t([y()],bt.prototype,"view",void 0),bt=t([_("esri.views.draw.support.Reshape")],bt);const Pt=bt;export{Pt as default};
2
+ import{__decorate as e}from"tslib";import t from"../../../Graphic.js";import{createTask as i}from"../../../core/asyncUtils.js";import s from"../../../core/Collection.js";import o from"../../../core/Error.js";import{EventedAccessor as r}from"../../../core/Evented.js";import n from"../../../core/Logger.js";import{getOrCreateMapValue as a}from"../../../core/MapUtils.js";import{destroyMaybe as h,abortMaybe as p,assertIsSome as l}from"../../../core/maybe.js";import{pausable as c,when as d,watch as m,initial as v,sync as u}from"../../../core/reactiveUtils.js";import{property as y,subclass as _}from"../../../core/accessorSupport/decorators.js";import{UpdatingHandles as g}from"../../../core/support/UpdatingHandles.js";import f from"../../../geometry/Point.js";import G from"../../../geometry/Polyline.js";import{fromPolylineUsingImportOperator as b,toGeometry as x}from"../../../geometry/operators/support/apiConverter.js";import{closeRingsAndFixWinding as M,geometryToCoordinates as C}from"../../../geometry/support/coordsUtils.js";import{isPoint as S}from"../../../geometry/support/typeUtils.js";import{interpolateCircle as E}from"../../../geometry/support/curves/circleUtils.js";import{deriveCircleFromCircularArc as w,toEllipticArc7 as I}from"../../../geometry/support/curves/circularArcUtils.js";import{getPaths as V,getEndpoint as H,isCircularArc as O,isEllipticArc4 as k,isBezierCurve as L,isCoordinate as P,cloneCurve as T,isEllipticArc7 as R}from"../../../geometry/support/curves/curveUtils.js";import{deriveCircleFromEllipticArc4 as A}from"../../../geometry/support/curves/ellipticArc4Utils.js";import{wrapAtan2 as j}from"../../../geometry/support/curves/mathUtils.js";import U from"../../../layers/GraphicsLayer.js";import{SnappingVisualizer2D as F}from"../../2d/interactive/SnappingVisualizer2D.js";import{ConnectedReshapeManager as D}from"./ConnectedReshapeManager.js";import{screenDeltaToMapDelta as K,cloneMove as z}from"./drawUtils.js";import N from"./GraphicMover.js";import W from"./HighlightHelper.js";import{addUniqueLayer as $,isConnectedReshapeSupportedLayer as q}from"./layerUtils.js";import{createTooltipInfos as X,connectTooltip as Y,updateTranslateTooltipInfo as Z,updateTranslateVertexTooltipInfo as B}from"./reshapeTooltipUtils.js";import{defaultSymbols as J,createMidpointGraphics as Q,createVertexGraphics as ee,createCurveControlPointGraphics as te,createCurveConstructionLineGraphics as ie,attributeKeys as se,getMidpoint as oe,controlPointKinds as re,fastCloneGeometry as ne,saveUpdatedCurveOrCoordinate as ae,toolIdAttribute as he,splitCurve as pe,isSingleSegmentCircle as le,isSingleSegmentEllipse as ce}from"./reshapeUtils.js";import{ViewEventPriorities as de}from"../../input/InputManager.js";import{createCoordinateHelper as me}from"../../interactive/coordinateHelper.js";import{sketchKeys as ve}from"../../interactive/keybindings.js";import{EditGeometryOperations as ue}from"../../interactive/editGeometry/EditGeometryOperations.js";import ye from"../../interactive/sketch/SketchOptions.js";import{SnappingContext as _e}from"../../interactive/snapping/SnappingContext.js";import{makeTooltip as ge,enterInputModeIfAvailable as fe}from"../../interactive/tooltip/tooltipCommonUtils.js";import{MeasurementWorkerHandle as Ge}from"../../support/MeasurementWorkerHandle.js";const be=Symbol(),xe={mode:"on-the-ground",offset:0};let Me=class extends r{constructor(e){super(e),this._updateHandlesOnExternalGeometryChange=null,this._activeOperationInfo=null,this._connectedReshapeManager=null,this._editGeometryOperations=null,this._primaryGraphicMoving=!1,this._segmentLabels=null,this._segmentLabelsImportTask=null,this._mover=null,this._snappingContext=null,this._snappingGraphicsLayer=null,this._hoverGraphic=null,this._snappingTask=null,this._stagedVertex=null,this._relatedGraphicIndex=null,this._updatingHandles=new g,this._measurementWorker=new Ge({preloadGeodetic:!0}),this.callbacks={onReshapeStart(){},onReshape(){},onReshapeStop(){},onMoveStart(){},onMove(){},onMoveStop(){},onGraphicClick(){}},this.connectedReshapeProviders=null,this.enableMidpoints=!0,this.enableCurveOnMidpoint=!1,this.enableMovement=!0,this.enableVertices=!0,this.filterVerticesEnabled=!0,this.graphic=null,this.highlightName=null,this.highlightsEnabled=!0,this.layer=null,this.snappingManager=null,this.symbols=J,this.tooltip=null,this.activeTooltipInfo=null,this.sketchOptions=new ye,this.type="reshape",this.vertexGraphics=new s,this.curveControlPointGraphics=new s,this.constructionLineGraphics=new s,this.midpointGraphics=new s,this.selectedManipulators=new s,this.view=null}initialize(){const e=this.view;this._highlightHelper=new W({view:e}),this._setup(),this._updateHandlesOnExternalGeometryChange=c(()=>this.graphic?.geometry,e=>{if(!e||!0===this._primaryGraphicMoving)return;const t=new Set(this.selectedManipulators.map(Le));this._highlightHelper.removeAll(),this._setUpHighlights(),this._setupGraphics(),this._clearSelection(),this.vertexGraphics.filter(e=>t.has(Le(e))).forEach(e=>this._addToSelection(e)),this.curveControlPointGraphics.filter(e=>t.has(Le(e))).forEach(e=>this._addToSelection(e));const{enableMovement:i,_mover:s,graphic:o,midpointGraphics:r,vertexGraphics:n,curveControlPointGraphics:a}=this,h=n.concat(r,a).toArray();i&&h.push(o),s?.set("graphics",h)},u),this.tooltip=ge(()=>({view:e,options:this.sketchOptions.tooltips})),this.tooltipInfos=X(this.sketchOptions),this.addHandles([d(()=>e?.ready,()=>{const{layer:e,view:t}=this;$(t,e),this.addHandles(t.on("key-down",e=>this._keyDownHandler(e),de.TOOL))},{once:!0,initial:!0}),m(()=>this.graphic,()=>this.refresh()),...this._effectiveFilterVerticesEnabled?[m(()=>[this.view.viewpoint,this.view.stationary],()=>{this.view.stationary&&this.refresh()})]:[],m(()=>this.layer,(e,t)=>{t&&(this._clearSelection(),this._resetGraphics(t)),this.refresh()}),m(()=>[this.highlightsEnabled,this.highlightName],()=>{this._highlightHelper?.removeAll(),this._setUpHighlights()}),m(()=>this.enableMidpoints,()=>this.refresh()),Y(this.tooltip,()=>this._tooltipsContext,this._updatingHandles),m(()=>this.sketchOptions.labels.enabled,e=>{this._segmentLabels?this._segmentLabels.visible=e:this._setUpGeometryHelper()}),m(()=>this.view.effectiveTheme.accentColor,()=>this._updateSymbolsForTheme(),v),this._updateHandlesOnExternalGeometryChange]),this._updateTooltip()}destroy(){this._reset(),this._mover=h(this._mover),this._connectedReshapeManager=h(this._connectedReshapeManager),this.tooltip=h(this.tooltip),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._updatingHandles=h(this._updatingHandles),this._measurementWorker.destroy()}get _coordinateHelper(){return this._editGeometryOperations?.data.coordinateHelper??me(!!this.graphic.geometry?.hasZ,!!this.graphic.geometry?.hasM,this.view.spatialReference)}get _effectiveFilterVerticesEnabled(){return"2d"===this.view?.type&&this.filterVerticesEnabled}get test(){return{segmentLabels:this._segmentLabels}}get _selectedManipulator(){return 1===this.selectedManipulators.length?this.selectedManipulators.at(0):void 0}get _tooltipsContext(){const{sketchOptions:e,activeTooltipInfo:t,graphic:i}=this;return{sketchOptions:e,activeTooltipInfo:t,graphic:i,selectedVertex:this._selectedManipulator,measurementWorker:this._measurementWorker,updateGeometry:(e,t,i,s,o)=>{this._setUpGeometryHelper();const r=e===this.graphic;r?this._emitMoveStartEvent(0,0):this._emitReshapeStartEvent(e);const n=!0;if(this._syncGeometryAfterVertexMove(e,t,s,o,n),r){const{view:e}=this,s=e.toScreen(i),o=e.toScreen(t),r=(o?.x??0)-(s?.x??0),n=(o?.y??0)-(s?.y??0);this._emitMoveEvent(r,n),this._emitMoveStopEvent(r,n)}else this._emitReshapeEvent(e),this._emitReshapeStopEvent(e)}}}get state(){const e=this.view.ready,t=!(!this.graphic||!this.layer);return e&&t?"active":e?"ready":"disabled"}get updating(){return this._updatingHandles.updating||!!this._segmentLabels?.updating}isUIGraphic(e){return e===this.graphic||this._isMidpoint(e)||this._isCurveControlPoint(e)||this._isVertex(e)||this._isConstructionLine(e)}refresh(e){if(this._reset(),this._setup(),e){for(const t of this.vertexGraphics)e.has(Le(t))&&this._addToSelection(t);for(const t of this.curveControlPointGraphics)e.has(Le(t))&&this._addToSelection(t)}}reset(){this.graphic=null}clearSelection(){this._clearSelection()}removeSelectedVertices(){const{selectedManipulators:e}=this;e.length&&this._removeVertices(e)}_setup(){const{graphic:e,layer:t}=this;if(!t||null==e?.geometry)return;const i=e.geometry;"mesh"!==i.type&&"extent"!==i.type?("polygon"===i.type&&M(i),this._setUpHighlights(),this._setupGraphics(),this._setupMover(),this._setupConnectedReshapeManager(),this._setUpGeometryHelper()):this._logGeometryTypeError()}_setUpHighlights(){this.highlightsEnabled&&this.graphic&&this._highlightHelper?.add(this.graphic,this.highlightName)}_setUpGeometryHelper(){const e=this.graphic.geometry;if(null==e||"mesh"===e.type||"extent"===e.type)return this._segmentLabels=h(this._segmentLabels),void this._logGeometryTypeError();this._editGeometryOperations?this._syncEditGeometryOperations(e):this._editGeometryOperations=ue.fromGeometry(e,2,{allowCurves:!0}),this._updatingHandles.consumePromise(this._setupSegmentLabels())}_saveSnappingContextForHandle(e,t){this._snappingGraphicsLayer=new U({listMode:"hide",internal:!0,title:"Reshape snapping layer"}),this.view.map.layers.add(this._snappingGraphicsLayer);const i=this._editGeometryOperations;l(i),this._snappingContext=new _e({editGeometryOperations:i,elevationInfo:xe,pointer:t.viewEvent?.pointerType||"mouse",excludeFeature:this.graphic,feature:this.graphic,visualizer:new F(this._snappingGraphicsLayer),vertexHandle:this._getVertexFromEditGeometry(e)})}_reset(){this._clearSelection(),this._highlightHelper?.removeAll(),this._updateTooltip(),this._resetGraphics(),this._resetSnappingStateVars(),this._segmentLabelsImportTask=p(this._segmentLabelsImportTask),this._segmentLabels=h(this._segmentLabels),this._activeOperationInfo=null,this._mover=h(this._mover),this.removeHandles(be)}_resetSnappingStateVars(){null!=this.snappingManager&&this.snappingManager.doneSnapping(),null!=this._snappingGraphicsLayer&&(this.view?.map&&this.view.map.layers.remove(this._snappingGraphicsLayer),this._snappingGraphicsLayer.destroy()),this._snappingTask=p(this._snappingTask),this._snappingTask=null,this._snappingContext=null,this._stagedVertex=null}_resetGraphics(e){this._removeMidpointGraphics(e),this._removeVertexGraphics(e),this._removeCurveGraphics(e),this._updateTooltip()}_removeMidpointGraphics(e=this.layer){const{midpointGraphics:t}=this;e?.removeMany(t.items),t.drain(h)}_removeVertexGraphics(e=this.layer){const{vertexGraphics:t}=this;this._relatedGraphicIndex=null,e?.removeMany(t.items),t.drain(h)}_removeCurveGraphics(e=this.layer){const{curveControlPointGraphics:t,constructionLineGraphics:i}=this;e?.removeMany(t.items),e?.removeMany(i.items),t.drain(h),i.drain(h)}_setupGraphics(){const e=this.graphic.geometry;if(null!=e&&("polyline"===e.type||"polygon"===e.type||"multipoint"===e.type)){const t=Ce(e);this.enableMidpoints&&"multipoint"!==e.type&&this._setUpMidpointGraphics(t),this.enableVertices&&(this._setUpVertexGraphics(t),this._setupCurveGraphics(t))}}_setUpMidpointGraphics(e){this._removeMidpointGraphics();const t=Q(e,this.symbols,this._coordinateHelper,"polygon"===this.graphic.geometry?.type,this.filterVerticesEnabled?this.view.extent:null,this.filterVerticesEnabled?this.view.resolution:-1);this.midpointGraphics.addMany(t),this.layer.addMany(t)}_setUpVertexGraphics(e){if(this._removeVertexGraphics(),this._effectiveFilterVerticesEnabled){const t=ee(e,this.symbols,this._coordinateHelper,this.view.extent,this.view.resolution);this._relatedGraphicIndex=t.graphicIndex,this.vertexGraphics.addMany(t.graphics),this.layer.addMany(t.graphics)}else{const t=ee(e,this.symbols,this._coordinateHelper,null,-1).graphics;this.vertexGraphics.addMany(t),this._storeRelatedVertexIndices(),this.layer.addMany(t)}}_setupCurveGraphics(e){this._removeCurveGraphics();const t=te(e,this.symbols,this._coordinateHelper),i=ie(e,this.symbols,this._coordinateHelper);this.curveControlPointGraphics.addMany(t),this.constructionLineGraphics.addMany(i),this.layer.addMany(i),this.layer.addMany(t)}async _setupSegmentLabels(){const e=this._editGeometryOperations,t=this.sketchOptions.labels.enabled;if(e&&this._segmentLabels?.context?.editGeometryOperations===e&&t||(this._segmentLabels=h(this._segmentLabels)),!this._segmentLabels&&e&&t){const t=this._segmentLabelsImportTask??=i(async e=>{const t=import("../../2d/interactive/SegmentLabels2D.js"),{SegmentLabels2D:i}=await this._updatingHandles.addPromise(t);return e.aborted?null:i}),s=await t.promise;if(!s)return;this._segmentLabels=h(this._segmentLabels),this._segmentLabels=new s({context:{view:this.view,editGeometryOperations:e,elevationInfo:xe,labelOptions:this.sketchOptions.labels},visible:!0})}}_updateSymbolsForTheme(){const e=this.view.effectiveTheme.accentColor;this.symbols={vertices:{...this.symbols.vertices,default:this.symbols.vertices.default.clone().set("color",e),hover:this.symbols.vertices.hover?.clone().set("color",e)},controlPoints:{...this.symbols.controlPoints,default:this.symbols.controlPoints.default.clone().set("color",e),hover:this.symbols.controlPoints.hover?.clone().set("color",e)},midpoints:{...this.symbols.midpoints},constructionLines:this.symbols.constructionLines.clone().set("color",e)};for(const t of this.vertexGraphics)this._isSelected(t)?t.symbol=this.symbols.vertices.selected:this._hoverGraphic===t?t.symbol=this.symbols.vertices.hover:t.symbol=this.symbols.vertices.default;for(const t of this.curveControlPointGraphics)this._isSelected(t)?t.symbol=this.symbols.controlPoints.selected:this._hoverGraphic===t?t.symbol=this.symbols.controlPoints.hover:t.symbol=this.symbols.controlPoints.default;for(const t of this.constructionLineGraphics)t.symbol=this.symbols.constructionLines}_storeRelatedVertexIndices(){const e=this.vertexGraphics.items;if(!e)return;const t=e.map(({geometry:e})=>({x:e.x,y:e.y}));for(let i=0;i<t.length;i++){const s=[];for(let e=0;e<t.length;e++){if(i===e)continue;const o=t[i],r=t[e];o.x===r.x&&o.y===r.y&&s.push(e)}e[i].attributes[se.relatedGraphicIndices]=s}}_setupMover(){const{enableMovement:e,graphic:t,midpointGraphics:i,vertexGraphics:s,view:o}=this,r=s.concat(i,this.curveControlPointGraphics).toArray();e&&"multipoint"!==t.geometry?.type&&r.push(t),this._mover=new N({enableMoveAllGraphics:!1,highlightsEnabled:!1,indicatorsEnabled:!1,graphics:r,view:o,callbacks:{onGraphicClick:e=>this._onGraphicClickCallback(e),onGraphicMoveStart:e=>this._onGraphicMoveStartCallback(e),onGraphicMove:e=>this._onGraphicMoveCallback(e),onGraphicMoveStop:e=>this._onGraphicMoveStopCallback(e),onGraphicPointerOver:e=>this._onGraphicPointerOverCallback(e),onGraphicPointerOut:e=>this._onGraphicPointerOutCallback(e)}})}_setupConnectedReshapeManager(){const{connectedReshapeProviders:e}=this;null!=e&&0!==e.length&&(this._connectedReshapeManager=new D({providerFactories:e,view:this.view}))}_onGraphicClickCallback(e){e.viewEvent.stopPropagation();const t=e.graphic,i=this._isCurveControlPoint(t);if(t===this.graphic)this.clearSelection(),this.emit("graphic-click",e),this.callbacks.onGraphicClick?.(e);else if(this._isMidpoint(t)){if(2===e.viewEvent.button)return;const i=this.graphic.clone(),s=this._handleMidpointClickOrStartMove(e);this.refresh(),s.length&&this._emitVertexAddEvent([t],i,s)}else if(this._isVertex(t)||i){if(e.viewEvent.stopPropagation(),2===e.viewEvent.button)return void(i||this._removeVertices(t));e.viewEvent.native.shiftKey||this._clearSelection(),this.selectedManipulators.includes(t)?this._removeFromSelection(t,!0):this._addToSelection(t)}}_setUpOperation(e){const{graphic:t,dx:i,dy:s}=e,o=t===this.graphic;this._resetSnappingStateVars(),this._setUpGeometryHelper(),this._saveSnappingContextForHandle(t,e),this._activeOperationInfo={target:this.graphic,mover:t,operationType:o?"move":"reshape",totalDx:i,totalDy:s}}_onGraphicMoveStartCallback(e){const{dx:t,dy:i,graphic:s}=e,o=this._connectedReshapeManager,r=o?Te(this.graphic):null;if(s===this.graphic){const{geometry:n}=s;return this._primaryGraphicMoving=!0,this._setUpOperation(e),this._emitMoveStartEvent(t,i),r&&o?.startFeatureMove([r]),this._effectiveFilterVerticesEnabled&&this._resetGraphics(this.layer),void(null!=n&&"point"===n.type&&this._onHandleMove(s,t,i,e,()=>{this._updateTooltip(this.graphic,e.viewEvent),this._emitMoveEvent(t,i)}))}const{selectedManipulators:n}=this;if(!n.includes(s)){if(this._clearSelection(),this._isMidpoint(s)){const t=this.graphic.clone(),i=this._handleMidpointClickOrStartMove(e);i.length&&(this._emitVertexAddEvent([s],t,i),this._refreshGraphicIndicesAttributes(i[0]))}this._addToSelection(s)}if(this._setUpOperation(e),r){const e=n.filter(e=>this._isVertex(e));o?.startVertexMove(r,Re(e))}this._emitReshapeStartEvent(s),this._onHandleMove(s,t,i,e,()=>{this._updateTooltip(s,e.viewEvent),this._emitReshapeEvent(s)})}_onGraphicMoveCallback(e){const t=this._activeOperationInfo;if(!t)return;const{dx:i,dy:s,graphic:o}=e;t.totalDx+=i,t.totalDy+=s;const{operationType:r}=t,{geometry:n}=o;if(null!=n)if("move"!==r)this._onHandleMove(o,i,s,e,()=>{this._updateTooltip(o,e.viewEvent),this._emitReshapeEvent(o)});else{if("point"===n.type)this._onHandleMove(o,i,s,e,()=>{this._updateTooltip(this.graphic,e.viewEvent),this._emitMoveEvent(i,s)});else if("polyline"===n.type||"polygon"===n.type){const{dxMap:t,dyMap:o}=K(i,s,this.view);if(this._effectiveFilterVerticesEnabled){if(this.selectedManipulators.length>0){const e=this.selectedManipulators.toArray();this.selectedManipulators.removeAll();for(const t of e){if("point"===t.geometry?.type){const{pathIndex:e,pointIndex:i}=t.attributes,s=V(n)[e][i];if(s){const e=H(s);t.geometry=this._coordinateHelper.arrayToPoint(e)}}this._addToSelection(t.clone())}}}else{const e=Ce(n);this._updateVertexGraphicLocations(e)}this._connectedReshapeManager?.translate(t,o,0),this._updateTooltip(this.graphic,e.viewEvent),this._emitMoveEvent(i,s)}this._syncEditGeometryOperations(n)}}_onGraphicMoveStopCallback(e){const t=this._activeOperationInfo;if(this._primaryGraphicMoving=!1,!t)return;const{dx:i,dy:s,graphic:o}=e,{operationType:r}=t;if(t.totalDx+=i,t.totalDy+=s,this._onHandleMove(o,i,s,e,()=>"move"===r?this._emitMoveStopEvent():this._emitReshapeStopEvent(o)),this._effectiveFilterVerticesEnabled&&"move"===r){const e=new Set;for(const t of this.selectedManipulators)e.add(Le(t));return this.refresh(e),void this._updateTooltip()}if(this._isMidpoint(o)||o.getAttribute(se.curveFromStraightEdgeFlag))return this.refresh(),void this._connectedReshapeManager?.finish();this._updateTooltip(this._isVertex(o)?o:null),this._resetSnappingStateVars(),this._connectedReshapeManager?.finish(),this._activeOperationInfo=null}_updateVertexGraphicLocations(e){const{_coordinateHelper:t}=this;for(const i of this.vertexGraphics){const{pathIndex:s,pointIndex:o}=i.attributes;i.geometry=t.arrayToPoint(H(e[s][o]))}this._updateMidpointGraphicLocations(e),this._updateCurveGraphicLocations(e)}_updateMidpointGraphicLocations(e,t){const{_coordinateHelper:i}=this;if(t)for(const s of this.midpointGraphics){const{pathIndex:o,pointIndexStart:r,pointIndexEnd:n}=s.attributes;if(!t.has(o))continue;const a=t.get(o);if(!a.has(r)&&!a.has(n))continue;const h=e[o];s.geometry=new f(oe(h[r],h[n],i))}else for(const s of this.midpointGraphics){const{pathIndex:t,pointIndexStart:o,pointIndexEnd:r}=s.attributes,n=e[t];s.geometry=new f(oe(n[o],n[r],i))}}_updateCurveGraphicLocations(e){const{spatialReference:t}=this._coordinateHelper,i=new Map;for(const s of this.selectedManipulators){const[e,t]=ke(s);null!=e&&null!=t&&s.getAttribute(se.controlPointKind)&&a(i,e,()=>new Set)?.add(t)}for(const s of this.curveControlPointGraphics){const[t,o]=ke(s);if(i.get(t)?.has(o))continue;const r=e[t][o];if(O(r)||k(r)){const i=H(e[t][o-1]),n=O(r)?w(i,r):A(i,r),[a,h]=E(n,.25);s.geometry=new f({x:a,y:h,spatialReference:this._coordinateHelper.spatialReference})}else if(L(r)){const e=s.getAttribute(se.controlPointKind),[t,i]=e===re.bezier.cp1?r.b[1]:r.b[2];s.geometry=new f({x:t,y:i,spatialReference:this._coordinateHelper.spatialReference})}}for(const s of this.constructionLineGraphics){const i=s.getAttribute(se.controlPointKind),[o,r]=ke(s),n=e[o],a=H(n[r-1]),h=H(n[r]),p=e[o][r];i===re.bezier.line1?s.geometry=new G({paths:[[[a[0],a[1]],[...p.b[1]]]],spatialReference:t}):s.geometry=new G({paths:[[[h[0],h[1]],[...p.b[2]]]],spatialReference:t})}}_refreshGraphicIndicesAttributes(e){const{componentIndex:t,vertexIndex:i}=e,s=e=>{const[s,o]=ke(e);s===t&&o>=i&&e.setAttribute(se.pointIndex,o+1)};this.vertexGraphics.forEach(s),this.curveControlPointGraphics.forEach(s),this.constructionLineGraphics.forEach(s);for(const o of this.midpointGraphics){if(o.getAttribute(se.pathIndex)!==t)continue;const e=o.getAttribute(se.pointIndexStart);e>=i&&(o.setAttribute(se.pointIndexStart,e+1),o.setAttribute(se.pointIndexEnd,o.getAttribute(se.pointIndexEnd)+1))}}_getVertexFromEditGeometry(e){const[t,i]=ke(e);return l(this._editGeometryOperations),this._editGeometryOperations.data.parts[t].vertices[i]}_onHandleMove(e,t,s,o,r){p(this._snappingTask);const n=this._snappingContext;if(!n)return;const a=e.geometry,h="graphic-move-stop"===o.type;if(a&&S(a))if(null!=this.snappingManager&&this.selectedManipulators.length<2&&!h){const o=this.snappingManager;this._stagedVertex=o.update({point:a,context:n}),this._syncGeometryAfterVertexMove(e,new f(this._stagedVertex),t,s,h),r(),this._snappingTask=i(async i=>{const p=await o.snap({point:a,context:n,signal:i});p.valid&&(this._stagedVertex=p.apply(),this._syncGeometryAfterVertexMove(e,new f(this._stagedVertex),t,s,h),r())})}else{const i=null!=this._stagedVertex?new f(this._stagedVertex):a;this._syncGeometryAfterVertexMove(e,i,t,s,h),r()}else r()}_syncGeometryAfterVertexMove(e,t,i,s,o=!1){const r=ne(this._editGeometryOperations?.data.geometry);if(!r)return;const{_coordinateHelper:n}=this,a=n.pointToVector(t),h=this._getVertexFromEditGeometry(e);let p=null;if(h){const e=n.getZ(a);p=[h.pos[0],h.pos[1]];const t=a[0]-h.pos[0],i=a[1]-h.pos[1],s=null!=e?e-h.pos[2]:0;"point"!==r.type&&"mesh"!==r.type||this._editGeometryOperations?.moveVertices([h],t,i,s),this._connectedReshapeManager?.translate(t,i,s)}if("point"===r.type)e.geometry=t;else if("mesh"===r.type)e.geometry=r.centerAt(t);else{if(e!==this.graphic){p&&!this._isVertex(e)&&(p=null);const o=n.spatialReference,[a,h]=ke(e);let l=Se(r);const c=n.pointToArray(t);if(this._updateGeometryFromGraphic(e,l,a,h,c,o,"polygon"===r.type),this._isVertex(e)||this._isCurveControlPoint(e)){const t=new Map;t.set(a,new Set([h])),l=this._moveRelatedCoordinates(l,e,c,t,p),l=this._moveSelectedHandleCoordinates(l,e,i,s,"polygon"===r.type),this._updateMidpointGraphicLocations(l,t),this._updateCurveGraphicLocations(l)}else this._isMidpoint(e)&&this._updateCurveGraphicLocations(l);ae(r,l)}this._updateGraphicGeometry(r),this._syncEditGeometryOperations(r),o&&(this._mover?this._mover.updateGeometry(this._mover.graphics.indexOf(e),t):e.geometry=t)}}_syncEditGeometryOperations(e){const t=this._editGeometryOperations?.trySetGeometry(e);t||(this._editGeometryOperations=null,this._setUpGeometryHelper())}_moveRelatedCoordinates(e,t,i,s,o){if(this._effectiveFilterVerticesEnabled&&this._relatedGraphicIndex&&o){const r=this._relatedGraphicIndex.search({minX:o[0],maxX:o[0],minY:o[1],maxY:o[1]});for(const n of r)n.coordinate[0]===o[0]&&n.coordinate[1]===o[1]&&n.graphic&&(s&&a(s,n.pathIndex,()=>new Set).add(n.pointIndex),Oe(e,n.pathIndex,n.pointIndex,i,this._coordinateHelper.spatialReference),this._relatedGraphicIndex.remove(n),n.coordinate[0]=t.geometry.x,n.coordinate[1]=t.geometry.y,n.graphic.geometry=t.geometry,this._relatedGraphicIndex.insert(n));return e}const{relatedGraphicIndices:r}=t.attributes,n=this._coordinateHelper.spatialReference;if(!r?.length)return e;for(const h of r){const o=this.vertexGraphics.at(h),[r,p]=ke(o);s&&a(s,r,()=>new Set).add(p),Oe(e,r,p,i,n),o.geometry=t.geometry}return e}_moveSelectedHandleCoordinates(e,t,i,s,o){const r=this._coordinateHelper.spatialReference;for(const n of this.selectedManipulators)if(n!==t){const[t,a]=ke(n),h=n.getAttribute(se.relatedGraphicIndices),p=z(n.geometry,i,s,this.view),l=C(p);if(n.geometry=p,this._updateGeometryFromGraphic(n,e,t,a,l,r,o),h?.length)for(const i of h){const t=this.vertexGraphics.at(i),[s,o]=ke(t);Oe(e,s,o,l,r),t.geometry=p}}return e}_updateGeometryFromGraphic(e,t,i,s,o,r,n){const a=t[i].length-1;this._isCurveControlPoint(e)?we(t,i,s,[o[0],o[1]],e.getAttribute(se.controlPointKind)):(Oe(t,i,s,o,r),n&&(0===s?Oe(t,i,a,o,r):s===a&&(t[i][0]=o)))}_onGraphicPointerOverCallback(e){const t=e.graphic;this._hoverGraphic=t;const i=this._isVertex(t);i&&!this._isSelected(t)?t.symbol=this.symbols.vertices.hover:this._isCurveControlPoint(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.controlPoints.hover),this._updateTooltip(i?t:null),this._updateHoverCursor(t)}_onGraphicPointerOutCallback(e){const t=e.graphic;this._hoverGraphic=null,this._isVertex(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.vertices.default),this._isCurveControlPoint(t)&&!this._isSelected(t)&&(t.symbol=this.symbols.controlPoints.default),this.removeHandles(be),this._updateTooltip()}_handleMidpointClickOrStartMove(e){const{graphic:t}=e,i=this.graphic.geometry;if(null==i||"polygon"!==i.type&&"polyline"!==i.type)return[];const s=ne(i),o=[],{[se.pathIndex]:r,[se.pointIndexStart]:n,[se.pointIndexEnd]:a}=t.attributes,h=C(t.geometry),p=0===a?n+1:a;t.attributes={[se.tool]:he,[se.pathIndex]:r,[se.pointIndex]:p,[se.relatedGraphicIndices]:[]};const l=Se(s),c=l[r][a];if(P(c)){if(this.enableCurveOnMidpoint&&e.viewEvent.native.shiftKey){const e=H(l[r][p]);l[r].splice(p,1,{c:[e,[h[0],h[1]]]}),t.setAttribute(se.controlPointKind,re.circle.interior),t.setAttribute(se.curveFromStraightEdgeFlag,!0),this.midpointGraphics.remove(t),this.curveControlPointGraphics.push(t),ae(s,l)}else l[r].splice(p,0,h),o.push({coordinates:l[r][p],componentIndex:r,vertexIndex:p})}else{const e=H(l[r][n]),t=pe(e,c,.5,this._coordinateHelper);l[r].splice(a,1,...t),o.push({coordinates:H(l[r][p]),componentIndex:r,vertexIndex:p})}return this._updateGraphicGeometry(s),this._syncEditGeometryOperations(s),o}_addToSelection(e){const t=Pe(e);for(const i of t)this._isCurveControlPoint(i)?i.symbol=this.symbols.controlPoints.selected:i.symbol=this.symbols.vertices.selected,this.selectedManipulators.add(i),this._updateTooltip(i);this._emitSelectEvent(t)}_removeFromSelection(e,t){if(this._isVertex(e)){const{vertices:i}=this.symbols;e.symbol=t?i.hover:i.default}else if(this._isCurveControlPoint(e)){const{controlPoints:i}=this.symbols;e.symbol=t?i.hover:i.default}this.selectedManipulators.remove(e),this._emitDeselectEvent([e]),this._updateTooltip()}_clearSelection(){const e=this.selectedManipulators.toArray(),{controlPoints:t,vertices:i}=this.symbols;if(e.length>0){for(const s of e)this._isVertex(s)?s.symbol=i.default:this._isCurveControlPoint(s)&&(s.symbol=t.default);this.selectedManipulators.removeAll(),this._emitDeselectEvent(e),this._updateTooltip()}}_keyDownHandler(e){null==this._activeOperationInfo&&fe(e,this.tooltip)||ve.delete.includes(e.key)&&!e.repeat&&this.selectedManipulators.length&&(this._removeVertices(this.selectedManipulators),e.stopPropagation())}_removeVertices(e){const t=this.graphic.geometry,i=this.vertexGraphics.length;if(null==t||"polygon"!==t.type&&"polyline"!==t.type&&"multipoint"!==t.type)return;if("polygon"===t.type&&i<4||"multipoint"===t.type&&i<2||"polyline"===t.type&&i<3)return;const s=this.graphic.clone(),o=ne(t);let r=Se(o);const n=[],a=Pe(e);for(const h of a){if(this._isCurveControlPoint(h))continue;const{x:e,y:t}=h.geometry;for(let i=0;i<r.length;i++){const s=r[i];for(let o=0;o<s.length;o++){const[a,h]=H(s[o]);if(e===a&&t===h){n.push({coordinates:H(r[i][o]),componentIndex:i,vertexIndex:o}),r[i].splice(Number(o),1);const e=r[i][o];e&&!P(e)&&(r[i][o]=H(e))}}}}if("polygon"===o.type)r=r.filter(e=>{if(e.length<2)return!1;const[t,i]=H(e[0]),[s,o]=H(e[e.length-1]);return(2!==e.length||t!==s||i!==o)&&(t===s&&i===o||e.push(e[0]),!0)});else if("polyline"===o.type)for(const h of r)1===h.length&&r.splice(r.indexOf(h),1);ae(o,r),this._updateGraphicGeometry(o),this.refresh(),this._emitVertexRemoveEvent(a,s,n)}_isVertex(e){return this.vertexGraphics.includes(e)}_isCurveControlPoint(e){return this.curveControlPointGraphics.includes(e)}_isConstructionLine(e){return this.constructionLineGraphics.includes(e)}_isSelected(e){return(this._isVertex(e)||this.curveControlPointGraphics.includes(e))&&this.selectedManipulators.includes(e)}_isMidpoint(e){return this.midpointGraphics.includes(e)}_updateHoverCursor(e){const t=this._isMidpoint(e)?"copy":"move";this.addHandles(this.view.acquireCursor(t,"high"),be)}_updateTooltip(e,t){let i=null;const{graphic:s,view:o,tooltipInfos:r}=this,n=s?.geometry;"point"===n?.type?i=r.movePoint:this._selectedManipulator?i=r.selectedVertex:e===this.graphic?(i=r.translateGraphic,Z(i,o,this._tooltipsContext,this._updatingHandles,t)):e&&this.selectedManipulators.length>1&&(i=r.translateVertices,B(i,o,n,this._tooltipsContext,this._updatingHandles,t)),this.activeTooltipInfo=i}_updateGraphicGeometry(e){this._updateHandlesOnExternalGeometryChange?.pause(),this.graphic.geometry=e,this._updateHandlesOnExternalGeometryChange?.resume()}_emitMoveStartEvent(e,t){const i={type:"move-start",mover:this.graphic,dx:e,dy:t};this.emit("move-start",i),this.callbacks.onMoveStart?.(i)}_emitMoveEvent(e,t){const i={type:"move",mover:this.graphic,dx:e,dy:t};this.emit("move",i),this.callbacks.onMove?.(i)}_emitMoveStopEvent(e,t){if(null==e||null==t){const i=this._activeOperationInfo;if(!i)return;e=i.totalDx,t=i.totalDy}const i={type:"move-stop",mover:this.graphic,dx:e,dy:t};this.emit("move-stop",i),this.callbacks.onMoveStop?.(i)}_emitReshapeStartEvent(e){const t={type:"reshape-start",graphic:this.graphic,mover:e,selected:this.selectedManipulators.toArray()};this.emit("reshape-start",t),this.callbacks.onReshapeStart?.(t)}_emitReshapeEvent(e){const t={type:"reshape",graphic:this.graphic,mover:e,selected:this.selectedManipulators.toArray()};this.emit("reshape",t),this.callbacks.onReshape?.(t)}_emitReshapeStopEvent(e){const t={type:"reshape-stop",graphic:this.graphic,mover:e,selected:this.selectedManipulators.toArray()};this.emit("reshape-stop",t),this.callbacks.onReshapeStop?.(t)}_emitSelectEvent(e){const t={type:"vertex-select",added:e};this.emit("select",t),this.callbacks.onVertexSelect?.(t)}_emitDeselectEvent(e){const t={type:"vertex-deselect",removed:e};this.emit("deselect",t),this.callbacks.onVertexDeselect?.(t)}_emitVertexAddEvent(e,t,i){const s={type:"vertex-add",added:e,graphic:this.graphic,oldGraphic:t,vertices:i};this.emit("vertex-add",s),this.callbacks.onVertexAdd?.(s)}_emitVertexRemoveEvent(e,t,i){const s={type:"vertex-remove",removed:e,graphic:this.graphic,oldGraphic:t,vertices:i};this.emit("vertex-remove",s),this.callbacks.onVertexRemove?.(s)}_logGeometryTypeError(){n.getLogger(this).error(new o("reshape:invalid-geometry","Reshape operation not supported for the provided graphic. The geometry type is not supported."))}};function Ce(e){let t=Se(e);t=t.map(e=>e.slice());for(const i of t)for(let e=0;e<i.length;e++)i[e]=T(i[e]);if("polygon"===e.type)for(const i of t){const e=i[i.length-1];if(!P(e))continue;const t=i[0];t[0]===e[0]&&t[1]===e[1]&&i.length>2&&i.pop()}return t}function Se(e){return"polygon"===e.type?e.curveRings?.slice()??e.rings.slice():"polyline"===e.type?e.curvePaths?.slice()??e.paths.slice():e.points.map(e=>[e])}function Ee(e,t,i,s){const o=e[t][i];if(O(o))o.c[1]=s;else if(k(o)){const o=H(e[t][i]);e[t][i]={c:[o,s]}}}function we(e,t,i,s,o){switch(o){case re.circle.interior:Ee(e,t,i,s);break;case re.bezier.cp1:e[t][i].b[1]=s;break;case re.bezier.cp2:e[t][i].b[2]=s}}function Ie(e,t){return e<1e-8*t}function Ve(e,{cx:t,cy:i,isInvalid:s,thetaStart:o,thetaEnd:r},n,a){const[h,p]=e,[l,c]=n,d=l-h,m=c-p;t-=h,i-=p;const v=a?o>r:o<r,[u,y]=s?[t,i]:v?[-i,t]:[i,-t],[_,g]=[d,m],[f,G]=[u,y],b=_*G-g*f,x=(d**2+m**2)/2;if(Ie(Math.abs(b),x))return[(h+l)/2,(p+c)/2];const[M,C]=[G/b*x,-f/b*x],S=M**2+C**2,[E,w]=[d/2-M,m/2-C];if(Ie(E**2+w**2,S)){const[e,t]=v?[-C,M]:[C,-M];return[e+M+h,t+C+p]}const I=Math.sqrt((M**2+C**2)/(E**2+w**2))*Math.sign(d*u+m*y);return[E*I+M+h,w*I+C+p]}function He(e,t,i){const s=b(new G({curvePaths:[[e,t]],spatialReference:i})),{curvePaths:o}=x(s,i),r=o[0][1];return R(r)?r:I(e,r)}function Oe(e,t,i,s,o){const r=e[t][i],n=e[t].at(i+1);if(le(e,t)){const i=e[t][1];return e[t][0]=[...s],void(e[t][1]={a:[[...s],[...i.a[1]],0,0]})}if(ce(e,t)){const i=e[t][1],[o,r]=i.a[1],[n,a]=s,h=Math.hypot(n-o,a-r),[p,l]=[n-o,a-r],c=j(l,p);return e[t][0]=[...s],void(e[t][1]={a:[[...s],[...i.a[1]],0,0,c,h,i.a[6]]})}const a=H(r);if(P(r))r.splice(0,r.length,...s);else if(L(r))r.b[0].splice(0,r.b[0].length,...s);else if(O(r)||k(r)){const o=H(e[t][i-1]),n=O(r)?w(o,r):A(o,r);e[t].splice(i,1,{c:[[...s],Ve(o,n,s,!0)]})}else if(R(r)){r.a[0].splice(0,r.a[0].length,...s);const n=H(e[t][i-1]);r.a=He(n,r,o).a}if(n&&!P(n)&&!L(r))if(O(n)||k(n)){const o=H(n),r=O(n)?w(a,n):A(a,n);e[t].splice(i+1,1,{c:[o,Ve(o,r,s,!1)]})}else if(R(n)){const e=H(r);n.a=He(e,n,o).a}}function ke({attributes:e}){return[e?.[se.pathIndex]||0,e?.[se.pointIndex]||0]}function Le({attributes:e}){return`${e?.[se.pathIndex]}-${e?.[se.pointIndex]}-${e?.[se.controlPointKind]??"vertex"}`}function Pe(e){return e instanceof t?[e]:[...e]}function Te(e){const t=e.sourceLayer??e.layer;return q(t)?{graphic:e,layer:t}:null}function Re(e){return e.toArray().map(({attributes:e})=>({pathIndex:e[se.pathIndex],vertexIndex:e[se.pointIndex]}))}e([y()],Me.prototype,"_activeOperationInfo",void 0),e([y()],Me.prototype,"_connectedReshapeManager",void 0),e([y()],Me.prototype,"_coordinateHelper",null),e([y()],Me.prototype,"_editGeometryOperations",void 0),e([y()],Me.prototype,"_effectiveFilterVerticesEnabled",null),e([y()],Me.prototype,"_primaryGraphicMoving",void 0),e([y()],Me.prototype,"_segmentLabels",void 0),e([y()],Me.prototype,"test",null),e([y()],Me.prototype,"_segmentLabelsImportTask",void 0),e([y()],Me.prototype,"_updatingHandles",void 0),e([y()],Me.prototype,"_selectedManipulator",null),e([y()],Me.prototype,"_tooltipsContext",null),e([y()],Me.prototype,"callbacks",void 0),e([y()],Me.prototype,"connectedReshapeProviders",void 0),e([y()],Me.prototype,"enableMidpoints",void 0),e([y()],Me.prototype,"enableCurveOnMidpoint",void 0),e([y()],Me.prototype,"enableMovement",void 0),e([y()],Me.prototype,"enableVertices",void 0),e([y()],Me.prototype,"filterVerticesEnabled",void 0),e([y()],Me.prototype,"graphic",void 0),e([y()],Me.prototype,"highlightName",void 0),e([y()],Me.prototype,"highlightsEnabled",void 0),e([y()],Me.prototype,"layer",void 0),e([y()],Me.prototype,"snappingManager",void 0),e([y({readOnly:!0})],Me.prototype,"state",null),e([y()],Me.prototype,"symbols",void 0),e([y()],Me.prototype,"tooltip",void 0),e([y()],Me.prototype,"tooltipInfos",void 0),e([y()],Me.prototype,"activeTooltipInfo",void 0),e([y()],Me.prototype,"updating",null),e([y({type:ye})],Me.prototype,"sketchOptions",void 0),e([y({readOnly:!0})],Me.prototype,"type",void 0),e([y({readOnly:!0})],Me.prototype,"vertexGraphics",void 0),e([y({readOnly:!0})],Me.prototype,"curveControlPointGraphics",void 0),e([y({readOnly:!0})],Me.prototype,"constructionLineGraphics",void 0),e([y({readOnly:!0})],Me.prototype,"midpointGraphics",void 0),e([y({readOnly:!0})],Me.prototype,"selectedManipulators",void 0),e([y()],Me.prototype,"view",void 0),Me=e([_("esri.views.draw.support.Reshape")],Me);const Ae=Me;export{Ae as default};