@arcgis/core 6.0.0-next.34 → 6.0.0-next.36
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.
- package/Basemap.d.ts +2 -2
- package/analysis/ShadowCastAnalysis.d.ts +11 -5
- package/arcgisGlobal.d.ts +1 -0
- package/assets/esri/core/libs/libtess/libtess-f32.wasm +0 -0
- package/assets/esri/core/libs/libtess/libtess-f64.wasm +0 -0
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/01f55004d64309f8538b.js +1 -0
- package/assets/esri/core/workers/chunks/0202eb8c2b2865f99981.js +1 -0
- package/assets/esri/core/workers/chunks/{67e533748435253aaba6.js → 0284f608d25c654fcc11.js} +1 -1
- package/assets/esri/core/workers/chunks/{7810586c35dfe1437516.js → 06102715e9a8f218e07c.js} +1 -1
- package/assets/esri/core/workers/chunks/{6029773458ab98600f67.js → 07e5482e1fc69be5de09.js} +1 -1
- package/assets/esri/core/workers/chunks/08140725277de5d2e41a.js +1 -0
- package/assets/esri/core/workers/chunks/{2d9a1f23ec6ce90723ac.js → 0d99bfb75dcb9fa29080.js} +1 -1
- package/assets/esri/core/workers/chunks/10ad7b35b6800d40444e.js +1 -0
- package/assets/esri/core/workers/chunks/1132e28aaa5825b10b6e.js +1 -0
- package/assets/esri/core/workers/chunks/{dd30b02c5978c1c5f511.js → 155861fbd0e5fc2db80c.js} +1 -1
- package/assets/esri/core/workers/chunks/165ca7a97b611c8f26c4.js +1 -0
- package/assets/esri/core/workers/chunks/1ae0c9345626e70affd3.js +2 -0
- package/assets/esri/core/workers/chunks/{cd355baab983033c3ef0.js → 1ec772eaa63eb6937231.js} +1 -1
- package/assets/esri/core/workers/chunks/{5c04835b0b52461183cd.js → 1fd82fcba2758741996a.js} +1 -1
- package/assets/esri/core/workers/chunks/21e1d423ee33f916547e.js +1 -0
- package/assets/esri/core/workers/chunks/{e8e54faf947a582b4cf7.js → 247617c0dbae2386ab3b.js} +1 -1
- package/assets/esri/core/workers/chunks/{97ec46605f16333144b7.js → 26ea39dfdf887f357fce.js} +1 -1
- package/assets/esri/core/workers/chunks/{85de980c5b296ec69323.js → 279089a6a3f08022c678.js} +1 -1
- package/assets/esri/core/workers/chunks/{b657363113f4a37e634b.js → 3223f9fbc76ba9ef8d13.js} +1 -1
- package/assets/esri/core/workers/chunks/322b22a5d54e404bebd5.js +1 -0
- package/assets/esri/core/workers/chunks/{122e75b21699a4e83b15.js → 338d800d4efcc91cead1.js} +1 -1
- package/assets/esri/core/workers/chunks/3537fe95b83a13b156cc.js +1 -0
- package/assets/esri/core/workers/chunks/{f09bc86cd52224febfcb.js → 3b380e64566a6cce59e2.js} +1 -1
- package/assets/esri/core/workers/chunks/{a1e8209d00809c9520a0.js → 3fe4c89acd325d36618d.js} +1 -1
- package/assets/esri/core/workers/chunks/449a2dee17b54946f245.js +1 -0
- package/assets/esri/core/workers/chunks/{311e4969f19df63451dd.js → 4e5405134d079bdf9b7a.js} +1 -1
- package/assets/esri/core/workers/chunks/{d070fcb73ce274ab80e4.js → 5504ec9bd9ee4d10af07.js} +1 -1
- package/assets/esri/core/workers/chunks/552c36b40e5a5ec117fb.js +1 -0
- package/assets/esri/core/workers/chunks/5622f3faa59434772857.js +1 -0
- package/assets/esri/core/workers/chunks/59a1b637d2c107504a04.js +1 -0
- package/assets/esri/core/workers/chunks/59a88dd53f8806bbec06.js +1 -0
- package/assets/esri/core/workers/chunks/5c2fe67527c9d7b4dba3.js +1 -0
- package/assets/esri/core/workers/chunks/5d781c2c6204cffffd0d.js +1 -0
- package/assets/esri/core/workers/chunks/61d36730564c5ac5edab.js +1 -0
- package/assets/esri/core/workers/chunks/6604272ef6fe85279032.js +1 -0
- package/assets/esri/core/workers/chunks/{90c1d10eae7ae71889b0.js → 7400b8c454b47ee4fb3c.js} +1 -1
- package/assets/esri/core/workers/chunks/796c6195b6bf59dcc9bd.js +1 -0
- package/assets/esri/core/workers/chunks/7b45ac83e279fe9516a5.js +1 -0
- package/assets/esri/core/workers/chunks/{2de077c7b971f2c215a6.js → 7ddbde8fdd1cf3c53f50.js} +1 -1
- package/assets/esri/core/workers/chunks/804606b194dc9e71d088.js +1 -0
- package/assets/esri/core/workers/chunks/8102f0bf5707c3be3310.js +1 -0
- package/assets/esri/core/workers/chunks/{676c8c0329d68f9f3ac4.js → 81bcc495e6eaf2cf7474.js} +1 -1
- package/assets/esri/core/workers/chunks/{d1d6154b4af1c9cc497b.js → 934e1f2153e6fad6ed23.js} +1 -1
- package/assets/esri/core/workers/chunks/{e096c1d9d53af74d3207.js → 990e96139b5a1dccb061.js} +1 -1
- package/assets/esri/core/workers/chunks/{f28b63c1179366dac8a2.js → 9e2c30b67bab5795306e.js} +1 -1
- package/assets/esri/core/workers/chunks/{9184c947cdefe06bf551.js → a18c3cbe505a19d29569.js} +1 -1
- package/assets/esri/core/workers/chunks/aa6ee2aa4ff6e6d41efb.js +1 -0
- package/assets/esri/core/workers/chunks/{3fd5c3cd8457ddc68798.js → aa779896fd9e5c341349.js} +1 -1
- package/assets/esri/core/workers/chunks/ac10c7d2c4829a150037.js +1 -0
- package/assets/esri/core/workers/chunks/{e0a7a75709121a26f255.js → afc8a9847f31bb66b13b.js} +1 -1
- package/assets/esri/core/workers/chunks/c7adb7b77721c75891f4.js +1 -0
- package/assets/esri/core/workers/chunks/{bead830a677690eeb6fb.js → ce8ef2eec290e1df6b2a.js} +1 -1
- package/assets/esri/core/workers/chunks/d3369ffed19f4c264dcd.js +1 -0
- package/assets/esri/core/workers/chunks/d3412518a7b518860fbb.js +1 -0
- package/assets/esri/core/workers/chunks/{3048e74e6246324ce6fc.js → d5916500514a41a4758f.js} +1 -1
- package/assets/esri/core/workers/chunks/{c034c30e577d620b8e28.js → dac69c0047488fdf986d.js} +1 -1
- package/assets/esri/core/workers/chunks/dcc782e4bf9e8a8202f9.js +1 -0
- package/assets/esri/core/workers/chunks/dcdf837a452dc0cac582.js +1 -0
- package/assets/esri/core/workers/chunks/{19a4fa965b70fc6f78f6.js → e209cb1f3f14bf576ebe.js} +1 -1
- package/assets/esri/core/workers/chunks/e67ea2f1714e5abeae44.js +1 -0
- package/assets/esri/core/workers/chunks/e8fb2ba7b7a4f0916325.js +1 -0
- package/assets/esri/core/workers/chunks/efcd38aad9aa667001b2.js +1 -0
- package/assets/esri/core/workers/chunks/{3aafdb905c697bc9b1ad.js → f372f4eb5527238c46f5.js} +1 -1
- package/assets/esri/core/workers/chunks/f497968055af459c5da4.js +1 -0
- package/assets/esri/core/workers/chunks/f7123ba1286f64e13e91.js +1 -0
- package/assets/esri/core/workers/chunks/fcb4707c2e95099b9f30.js +1 -0
- package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
- package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
- package/chunks/BlurEmission.glsl.js +9 -4
- package/chunks/RibbonLine.glsl.js +158 -84
- package/chunks/Terrain.glsl.js +9 -9
- package/chunks/libtess-f32.js +1 -1
- package/chunks/libtess-f64.js +1 -1
- package/chunks/lyr3DMain.js +1 -1
- package/chunks/lyr3DWorker.js +2 -2
- package/config.d.ts +3 -3
- package/config.js +1 -1
- package/core/mathUtils.js +1 -1
- package/form/FormTemplate.d.ts +1 -1
- package/geometry/libtess.js +1 -1
- package/geometry/projection/projectors.js +1 -1
- package/identity/Credential.d.ts +1 -1
- package/identity/IdentityManager.d.ts +1 -1
- package/identity/OAuthInfo.d.ts +1 -1
- package/identity/ServerInfo.d.ts +1 -1
- package/kernel.js +1 -1
- package/layers/CSVLayer.js +1 -1
- package/layers/GaussianSplatLayer.js +1 -1
- package/layers/IntegratedMesh3DTilesLayer.js +1 -1
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/VectorTileLayer.d.ts +2 -2
- package/layers/VideoLayer.js +1 -1
- package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
- package/layers/graphics/sources/CSVSource.js +1 -1
- package/layers/graphics/sources/GeoJSONSource.js +1 -1
- package/layers/graphics/sources/MemorySource.js +2 -2
- package/layers/graphics/sources/support/ParquetSourceWorker.js +1 -1
- package/layers/graphics/sources/support/QueryTask.js +1 -1
- package/layers/graphics/sources/support/timeQueryUtils.js +2 -0
- package/layers/mixins/APIKeyMixin.d.ts +1 -1
- package/layers/ogc/types.d.ts +1 -1
- package/layers/support/TelemetryData.d.ts +28 -4
- package/layers/support/TimeInformation.js +1 -1
- package/layers/support/tiles3DUtils.js +1 -1
- package/layers/support/timeInfoUtils.js +2 -0
- package/layers/video/videoUtils.js +1 -1
- package/package.json +2 -2
- package/rest/query/executeAttributeBinsQuery.js +1 -1
- package/rest/query/executeForExtent.js +1 -1
- package/rest/query/executeForTopCount.js +1 -1
- package/rest/query/executeForTopExtents.js +1 -1
- package/rest/query/executeForTopIds.js +1 -1
- package/rest/query/executeTopFeaturesQuery.js +1 -1
- package/rest/query/operations/query.js +1 -1
- package/rest/query/operations/queryAttributeBins.js +1 -1
- package/rest/query/operations/queryTopFeatures.js +1 -1
- package/rest/support/timeUtils.js +1 -1
- package/support/timeUtils.js +1 -1
- package/views/2d/engine/webgl/FeatureDisplayList.js +1 -1
- package/views/2d/engine/webgl/GlyphMosaic.js +1 -1
- package/views/2d/engine/webgl/GlyphWorker.js +1 -1
- package/views/2d/engine/webgl/TextureManager.js +1 -1
- package/views/2d/engine/webgl/materialKeyUtils.js +2 -0
- package/views/2d/engine/webgl/mesh/MeshData.js +1 -1
- package/views/2d/engine/webgl/mesh/templates/shapingUtils.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedMarkerMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/animated/AnimatedPolyMeshWriters.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/fill/ComplexOutlineFillMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/fill/GradientFillMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternFillMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/fill/PatternOutlineFillMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/labels/LabelMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/line/GradientStrokeMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/line/TexturedLineMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/markers/MarkerMeshWriter.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
- package/views/2d/layers/VideoLayerView2D.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
- package/views/3d/analysis/LineOfSight/placementUtils.js +1 -1
- package/views/3d/analysis/ShadowCast/ShadowCastError.d.ts +40 -0
- package/views/3d/analysis/ShadowCast/ShadowCastError.js +2 -0
- package/views/3d/analysis/ShadowCast/sunlightUtils.js +2 -0
- package/views/3d/analysis/ShadowCastAnalysisView3D.d.ts +16 -1
- package/views/3d/analysis/ShadowCastAnalysisView3D.js +1 -1
- package/views/3d/analysis/Viewshed/placementUtils.js +1 -1
- package/views/3d/camera/constraintUtils/surfaceCollision.js +1 -1
- package/views/3d/camera/intersectionUtils.js +1 -1
- package/views/3d/interactive/Manipulator3D.js +1 -1
- package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
- package/views/3d/interactive/editingTools/originGeometryVisualElementUtils.js +1 -1
- package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
- package/views/3d/layers/Lyr3DWorker.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/i3s/LayerElevationProvider.js +1 -1
- package/views/3d/layers/support/FeatureMemory.js +1 -1
- package/views/3d/layers/support/FeatureTile.js +1 -1
- package/views/3d/layers/support/Tiles3DBVH.js +1 -1
- package/views/3d/layers/support/Tiles3DMeshIntersectionHandler.js +1 -1
- package/views/3d/navigation/modes/GroundNavigationMode3D.js +1 -1
- package/views/3d/state/Constraints.js +1 -1
- package/views/3d/state/NearFarHeuristic.js +1 -1
- package/views/3d/state/utils/groundNavigationUtils.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatFadeHelper.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatIntersectionHandler.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +1 -1
- package/views/3d/support/gaussianSplatting/GaussianTile.js +1 -1
- package/views/3d/support/orientedBoundingBox.js +1 -1
- package/views/3d/support/pointsOfInterest/SurfaceGeometryUpdates.js +1 -1
- package/views/3d/support/sphereExtentUtils.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/TileRenderer.js +1 -1
- package/views/3d/terrain/tileUtils.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObject.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
- package/views/3d/webgl.d.ts +1 -1
- package/views/draw/DrawTool.js +1 -1
- package/views/support/Scheduler.js +1 -1
- package/widgets/Directions.d.ts +1 -1
- package/widgets/OrientedImageryViewer/navigation/NavigationManager.js +1 -1
- package/widgets/OrientedImageryViewer/navigation/queries.js +1 -1
- package/widgets/OrientedImageryViewer/navigation/utils.js +1 -1
- package/widgets/OrientedImageryViewer.js +2 -2
- package/assets/esri/core/workers/chunks/0f6c0d42100c21367e5c.js +0 -1
- package/assets/esri/core/workers/chunks/176d0a06ebff5a29dedf.js +0 -1
- package/assets/esri/core/workers/chunks/18776a130d96879a68b1.js +0 -1
- package/assets/esri/core/workers/chunks/20a698709c3c11ff2c16.js +0 -1
- package/assets/esri/core/workers/chunks/24ada9511b074dc5ae27.js +0 -1
- package/assets/esri/core/workers/chunks/277263466837e1673f56.js +0 -1
- package/assets/esri/core/workers/chunks/2c8ca43563c4f3e94535.js +0 -1
- package/assets/esri/core/workers/chunks/379ef56f6b32494832a6.js +0 -1
- package/assets/esri/core/workers/chunks/38d852676677e5697864.js +0 -1
- package/assets/esri/core/workers/chunks/38df7b1d58c4bcf693d0.js +0 -1
- package/assets/esri/core/workers/chunks/507ecc3692e6d0700958.js +0 -1
- package/assets/esri/core/workers/chunks/5a9b7eb26f936f03d02e.js +0 -1
- package/assets/esri/core/workers/chunks/5f07f52bb8b7721f08d3.js +0 -1
- package/assets/esri/core/workers/chunks/661847f1b7044f21600f.js +0 -1
- package/assets/esri/core/workers/chunks/6b5c073dddd89d06ed80.js +0 -1
- package/assets/esri/core/workers/chunks/6ddc29a144640acb1192.js +0 -1
- package/assets/esri/core/workers/chunks/6ebe73f69ae822053b70.js +0 -1
- package/assets/esri/core/workers/chunks/6f6d1873753a9c6994aa.js +0 -1
- package/assets/esri/core/workers/chunks/7582654a0fc70910731c.js +0 -1
- package/assets/esri/core/workers/chunks/7e211d8a8ad6c6a7cf3e.js +0 -1
- package/assets/esri/core/workers/chunks/849f446c718e892f39ce.js +0 -1
- package/assets/esri/core/workers/chunks/8517d96fc8ba7b21d845.js +0 -2
- package/assets/esri/core/workers/chunks/a107f16cd004626b5018.js +0 -1
- package/assets/esri/core/workers/chunks/a65951f1d5702cfd996e.js +0 -1
- package/assets/esri/core/workers/chunks/bf62be00f3040f91aaee.js +0 -1
- package/assets/esri/core/workers/chunks/c570b90995c65bbb2e14.js +0 -1
- package/assets/esri/core/workers/chunks/c576bef77e34920af188.js +0 -1
- package/assets/esri/core/workers/chunks/caad4f475d6eb01c2850.js +0 -1
- package/assets/esri/core/workers/chunks/cf1ec61eb2ad147bb931.js +0 -1
- package/assets/esri/core/workers/chunks/daae21cf77864f3293ef.js +0 -1
- package/assets/esri/core/workers/chunks/dc2f93453dfa40f623ab.js +0 -1
- package/assets/esri/core/workers/chunks/e81173724e8de8c1e65b.js +0 -1
- package/assets/esri/core/workers/chunks/e83f9abee611c5b80009.js +0 -1
- package/assets/esri/core/workers/chunks/ec8b7476eac4718eb0ac.js +0 -1
- package/assets/esri/core/workers/chunks/f45064066e1ab041a0b2.js +0 -1
- package/assets/esri/core/workers/chunks/ffe49d9e7df081bef4a5.js +0 -1
- package/views/2d/engine/webgl/hashMosaic.js +0 -2
- package/views/3d/webgl-engine/lib/GaussianSplatPrepassDepthRenderer.js +0 -2
- /package/assets/esri/core/workers/chunks/{8517d96fc8ba7b21d845.js.LICENSE.txt → 1ae0c9345626e70affd3.js.LICENSE.txt} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,removeMaybe as r,destroyMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{watch as o,whenOnce as s,initial as c}from"../../../core/reactiveUtils.js";import{Milliseconds as l}from"../../../core/time.js";import{isUint32Array as u}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as d,convertUnit as f}from"../../../core/units.js";import{property as p,subclass as m}from"../../../core/accessorSupport/decorators.js";import{fromValues as h}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{getReferenceEllipsoid as g}from"../../../geometry/ellipsoidUtils.js";import _ from"../../../geometry/HeightModelInfo.js";import{create as v}from"../../../geometry/support/aaBoundingBox.js";import{isCompatible as y}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as b}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as x,isWebMercator as S,equals as C,isGeographic as w}from"../../../geometry/support/spatialReferenceUtils.js";import T from"../../../geometry/support/WKIDUnitConversion.js";import{validateEntity3D as E,makeCacheKey as D,getHeightModelInfoFromVCS as O}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as k}from"../../../support/elevationInfoUtils.js";import{getMetersPerUnit as A}from"../../../symbols/support/unitConversionUtils.js";import{GaussianSplatLayerViewPerformanceInfo as j}from"./GaussianSplatLayerViewPerformanceInfo.js";import{LayerView3D as M}from"./LayerView3D.js";import{addLayerViewToWasm as N,getLyr3DWasm as P,removeLayerViewFromWasm as F}from"./Lyr3DWasm.js";import{LayerElevationProvider as I}from"./i3s/LayerElevationProvider.js";import{ElevationRange as L}from"../support/ElevationRange.js";import{projectToBoundingBox as R}from"../support/extentUtils.js";import{Obb as z}from"../support/orientedBoundingBox.js";import{splatPageSizeInU32 as B,gaussiansPerPage as V,packedGaussianSizeInU32 as H,splatAtlasTextureWidth as U}from"../support/gaussianSplatting/GaussianSplatAtlasPages.js";import{GaussianSplatDataStore as W}from"../support/gaussianSplatting/GaussianSplatDataStore.js";import{GaussianSplatFadeHelper as G}from"../support/gaussianSplatting/GaussianSplatFadeHelper.js";import{GaussianSplatIntersectionHandler as K}from"../support/gaussianSplatting/GaussianSplatIntersectionHandler.js";import{GaussianTile as q}from"../support/gaussianSplatting/GaussianTile.js";import{GaussianSplatDepthRenderer as J}from"../webgl-engine/lib/GaussianSplatDepthRenderer.js";import{GaussianSplatRenderer as Y}from"../webgl-engine/lib/GaussianSplatRenderer.js";import{GaussianSplatShadows as X}from"../webgl-engine/lib/GaussianSplatShadows.js";import Z from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as ee}from"../../support/layerViewUtils.js";import{TaskPriority as te}from"../../support/Scheduler.js";var Q;const ne=()=>t.getLogger(`esri.views.3d.layers.GaussianSplatLayerView3D`),re=(()=>{let e=new Int16Array(256);e[0]=-255;for(let t=1;t<e.length;t++)e[t]=Math.round(16*Math.log(t/255));return e})();let $=class extends M(Z){static{Q=this}static{this.createRenderableBatchSize=64}static{this.uploadBatchPageCount=16}constructor(e){super(e),this.type=`gaussian-splat-3d`,this.ignoresMemoryFactor=!1,this._tileHandles=new Map,this._pageBuffer=new Uint32Array(B*Q.uploadBatchPageCount),this._tmpTilesWithChangedVisibility=[],this._renderablesBeingCreated=new Set,this._currentLyr3dVisibilityChange=0,this._tileFadeInsAwaitingInitialSort=new Set,this._pendingTileFadeOuts=new Map,this._pendingFadeDuration=l(0),this._createRenderableAbortController=new AbortController,this.skipHeightModelInfoValidation=!0,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this._usedTileMemory=0,this._cacheTileMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._suspendedHandle=null,this._conversionBuffer=new ArrayBuffer(4),this._u32View=new Uint32Array(this._conversionBuffer),this._f32View=new Float32Array(this._conversionBuffer);let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`GaussianSplat-${this.uid}`,e=>this._deleteTile(e)),this._frameTask=t.scheduler.registerTask(te.GAUSSIAN_SPLAT_TEXTURE_ATLAS)}get _clippingBox(){if(!this.view?.clippingArea)return null;let e=v();return R(this.view.clippingArea,e,this.view.renderSpatialReference)?e:null}get clippingBox(){return this._renderer?.clippingBox??null}initialize(){let{view:e}=this;this.addHandles([o(()=>e.qualitySettings.fadeDuration,e=>{this.data&&(this.fadeHelper.onFadeDurationChanged(e),this.updateFadingTexture())})]),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await s(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw ee(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await N(this,t),a(t),this._renderer=new Y({view:e,layerView:this}),this.data=new W(this._renderer,(e,t)=>this._onSortComplete(e,t),()=>this._freeInvisibleTiles()),this._shadows=new X({view:e,layerView:this}),this.fadeHelper=new G(this),this._prepassDepthRenderer=new J({view:e,layerView:this});let n=new K(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new I({view:e,layerElevationSource:this,intersectionHandler:n}),e.elevationProvider.register(2,this._elevationProvider),this.addHandles([o(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),o(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChanged(e),c)]),this._suspendedHandle=o(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),c),this.addHandles([o(()=>this._clippingBox,e=>{this._renderer&&(this._renderer.clippingBox=e)},c),o(()=>this.maximumGaussianCount,e=>this._wasm?.setMaximumGaussianSplatCount(Math.min(e,this.data.textureAtlas.maximumSupportedVisibleGaussians)),c)]),this._initializationController=null}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get tileHandles(){return this._tileHandles}updateFadingTexture(){this.data.fadingTexture.updateTexture(this.data.textureAtlas.pageAllocator.pageCount)}get _wasm(){return P(this.view)}get usedMemory(){return this._usedTileMemory+(this.data?.usedMemory??0)}get cachedMemory(){return this._cacheTileMemory}get unloadedMemory(){return 0}get useEsriCrs(){return this._useEsriCrs}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return k(this.layer.elevationInfo)}get elevationRange(){let e=this.fullExtent;return e?.zmin&&e?.zmax?new L(e.zmin,e.zmax):null}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get fullExtent(){return this.layer.fullExtent}get visibleAtCurrentScale(){return b(this.layer.effectiveScaleRange,this.view.scale)}isUpdating(){let e=this._wasm;return this._wasmLayerId<0||e==null?!1:e.isUpdating(this._wasmLayerId)||this.data.updating||this.fadeHelper.updating}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!E(t))throw Error(`entity3D not valid`);let n=t.desc.geometry.prims[t.validPrimitiveIndices[0]].atrbs[0],r=t.assets[n.assetId];if(!r)throw Error(`entity3D not valid`);let i=r.count;if(i===0)return ne().warnOnce(`encountered tile with zero Gaussians`),()=>({memUsageBytes:0,numGaussians:0});let a=null;if(r.dataType===`U32`&&u(r.data))a=r.data;else throw Error(`unexpected GaussianSplat Entity3D asset.data format`);let o=this.extractHeader(a),s=2.048,c=o.tileOrigin.x*s,l=o.tileOrigin.y*s,d=o.tileOrigin.z*s,f=t.desc,p=f.obb.quaternion,m=new z(f.obb.center,f.obb.halfSize,h(...p)),_=this.view.state.isGlobal,v=_?g(this.view.spatialReference).radius:0,y={handle:e.handle,bufferView:a,totalGaussians:i,packedHeader:o.packedHeader,tileOrigin:{x:c,y:l,z:d},invPosScale:o.invPosScale,obb:m,origin:{x:m.centerX,y:m.centerY,z:m.centerZ},isGlobal:_,ellipsoidRadius:v};this._renderablesBeingCreated.add(e.handle);let b;try{b=await this._frameTask.scheduleGenerator(e=>this._createRenderableTask(y,e),this._createRenderableAbortController.signal)}catch(t){throw this._renderablesBeingCreated.delete(e.handle),t}return this._renderablesBeingCreated.delete(e.handle),()=>b}*_createRenderableTask(e,t){let{handle:n,bufferView:r,totalGaussians:i,packedHeader:a,tileOrigin:o,invPosScale:s,obb:c,origin:l,isGlobal:u,ellipsoidRadius:d}=e,f=o.x,p=o.y,m=o.z,h=l.x,g=l.y,_=l.z,v=new Float32Array(i*3),y=new Uint32Array(i),b=new Uint32Array(i),x=[],S=Math.ceil(i/V),C=1/0,w=-1/0,T=1/0,E=-1/0,D=0,O=-1,k=0,A=0;for(let e=0;e<i;e++){let n=e*H,i=r[n],a=r[n+1],o=r[n+2],c=r[n+3],l=a&16383,d=a>>>14&16383,x=a>>>28&15|(o&1023)<<4,S=c>>>24,j=re[S],M=(o>>>10&255)+j,N=(o>>>18&255)+j,P=(o>>>26&63|(c&3)<<6)+j,F=M>0?M:0,I=N>0?N:0,L=P>0?P:0,R=F|I<<8|L<<16,z=Math.max(F,I,L),B=l*s+f,V=d*s+p,U=x*s+m;if(v[D]=B-h,v[D+1]=V-g,v[D+2]=U-_,u){let e=B*B+V*V+U*U;T=Math.min(T,e),E=Math.max(E,e)}else C=Math.min(C,U),w=Math.max(w,U);y[e]=i,b[e]=R,z>O&&(O=z),S>k&&(k=S),D+=3,A++,A===Q.createRenderableBatchSize&&(A=0,t.madeProgress()&&(t=yield))}A>0&&t.madeProgress()&&(t=yield),u&&(C=Math.sqrt(T)-d,w=Math.sqrt(E)-d);let j=this._extractGaussianSplatMbsRadiusSquared(O),{fullExtent:M}=this.layer;M?.hasZ&&M.zmax&&M.zmin&&(C=Math.max(C,M.zmin),w=Math.min(w,M.zmax));let N=new L(C,w),P=this.data.textureAtlas,F=this.data.headerTexture;try{for(let e=0;e<S;e+=Q.uploadBatchPageCount){let n=Math.min(S,e+Q.uploadBatchPageCount);for(let t=e;t<n;t++){let e=P.allocatePage();if(e===null&&(this._freeInvisibleTiles(),e=P.allocatePage()),e===null)throw Error(`ran out of gaussian splat memory`);x.push(e)}for(let t=e;t<n;){let e=x[t],o=t+1;for(;o<n&&x[o]===x[o-1]+1;)o++;let s=o-t,c=i-t*V,l=Math.min(c,s*V),u=t*B,d=l*H;this._pageBuffer.set(r.subarray(u,u+d));let f=e*V,p=f%U,m=Math.floor(f/U);P.update(p,m,this._pageBuffer,s),F.update(e,a,s),t=o}t.madeProgress()&&(t=yield)}}catch(e){throw P.freePages(x),e}let I=new q(n,c,x,v,y,b,i,j,k/255,N);return this._tileHandles.set(n,I),this._cacheTileMemory+=I.usedMemory,this._memCache.put(`${I.handle}`,I),{memUsageBytes:I.usedMemory,numGaussians:i}}_extractGaussianSplatMbsRadiusSquared(e){return Math.exp(e/8-20)*9}freeRenderable(e){this._tileFadeInsAwaitingInitialSort.delete(e),this._pendingTileFadeOuts.delete(e);let t=this.data?.textureAtlas,n=!1,r=this._tileHandles.get(e);if(r){let i=!1;for(let t of this._pendingTileFadeOuts.values())t.incomingTileHandles.has(e)&&(t.visibilityChange=this._currentLyr3dVisibilityChange+1,i=!0);i&&(this._currentLyr3dVisibilityChange++,n=!0),r.lifecycleState===0?this._cacheTileMemory-=r.usedMemory:(n=!0,this.fadeHelper.onTileDiscarded(r),this._usedTileMemory-=r.usedMemory,this._intersectionHandler.removeTile(r)),t&&r.pageIds.forEach(e=>t.freePage(e)),this.freeObject(r),this._tileHandles.delete(e)}n&&this.updateGaussians()}freeObject(e){this._memCache.pop(`${e.handle}`)}notifyTileObbsChanged(e){this._elevationProvider&&this._elevationProvider.notifyObjectsChangedFunctional(e.length,t=>{for(let{obb:n}of e)if(!t(n))break})}setRenderableVisibility(e,t,n){let r=this.fadeHelper.updateFadeDuration(),i=new ie(this._currentLyr3dVisibilityChange+1),a=new Set,o=!1;for(let s=0;s<n;s++){let n=this._tileHandles.get(e[s]);if(!n)continue;let c=t[s]?this._prepareTileFadeIn(n,r):this._prepareTileFadeOut(n,i);t[s]&&i.incomingTileHandles.add(n.handle),c&&a.add(n.handle),o||=c}if(o){if(this._currentLyr3dVisibilityChange++,this._pendingFadeDuration=r,this._updatePendingTileHandoffs(a,i),i.incomingTileHandles.size===0)for(let e of this._tileFadeInsAwaitingInitialSort)i.incomingTileHandles.add(e);this.updateGaussians()}}_updatePendingTileHandoffs(e,t){for(let n of new Set(this._pendingTileFadeOuts.values())){if(n===t)continue;let r=!1;for(let i of e)n.incomingTileHandles.has(i)&&(r=!0,t.incomingTileHandles.size>0&&n.incomingTileHandles.delete(i));if(r){n.visibilityChange=t.visibilityChange;for(let e of t.incomingTileHandles)n.incomingTileHandles.add(e)}}}_prepareTileFadeIn(e,t){let n=this._pendingTileFadeOuts.delete(e.handle);return e.lifecycleState===2?(this.fadeHelper.fadeTile(e,0,t),!1):this._tileFadeInsAwaitingInitialSort.has(e.handle)?n:(e.lifecycleState===0&&this._popTileFromCache(e),e.lifecycleState=1,this._tileFadeInsAwaitingInitialSort.add(e.handle),!0)}_prepareTileFadeOut(e,t){let n=this._tileFadeInsAwaitingInitialSort.delete(e.handle);return n&&e.lifecycleState===1&&(this.moveTileToCache(e),e.lifecycleState=0),e.lifecycleState===2?this._pendingTileFadeOuts.has(e.handle)?n:(this._pendingTileFadeOuts.set(e.handle,t),!0):n}_onSortComplete(e,t){let n=this._tmpTilesWithChangedVisibility;n.length=0,this._triggerFadeIns(e,n);let r=this._triggerFadeOuts(t,n);n.length>0&&this.notifyTileObbsChanged(n),r&&this.updateGaussians()}_triggerFadeIns(e,t){for(let n of e)this._tileHandles.get(n.handle)===n&&this._tileFadeInsAwaitingInitialSort.delete(n.handle)&&(n.lifecycleState=2,t.push(n),this.fadeHelper.fadeTile(n,0,this._pendingFadeDuration))}_triggerFadeOuts(e,t){let n=!1;for(let t of this._pendingTileFadeOuts.values())if(e>=t.visibilityChange){n=!0;break}if(!n)return!1;let r=this._pendingFadeDuration,i=this._pendingFadeDuration;for(let e of this._tileHandles.values()){let{fadeDirection:t,fadeDuration:n,fadeProgress:a}=e;if(t!==0||n==null||a==null)continue;let o=n*(1-a);r=l(Math.max(r,o)),i=l(Math.max(i,n))}let a=!1;for(let[n,o]of this._pendingTileFadeOuts){if(e<o.visibilityChange)continue;this._pendingTileFadeOuts.delete(n);let s=this._tileHandles.get(n);if(s){let e=s.lifecycleState===2,n=s.opacityModifier===1?r:i;this.fadeHelper.fadeTile(s,1,n),e&&s.lifecycleState===0&&(t.push(s),a=!0)}}return a}_popTileFromCache(e){this._usedTileMemory+=e.usedMemory,this._cacheTileMemory-=e.usedMemory,this._intersectionHandler.addTile(e),this._memCache.pop(D(e.handle))}moveTileToCache(e){this._usedTileMemory-=e.usedMemory,this._cacheTileMemory+=e.usedMemory,this._intersectionHandler.removeTile(e),this._memCache.put(D(e.handle),e)}destroy(){this._initializationController=n(this._initializationController),this._createRenderableAbortController.abort(),F(this),this._suspendedHandle&&=r(this._suspendedHandle),this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),null),this._elevationProvider&&this.view.elevationProvider&&(this._elevationProvider.notifyObjectsChangedFunctional(this._tileHandles.size,e=>{for(let{obb:t}of this._tileHandles.values())if(!e(t))break}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null),this._frameTask.remove(),this._shadows=i(this._shadows),this._prepassDepthRenderer=i(this._prepassDepthRenderer),this._renderer=i(this._renderer),this._memCache.destroy(),this.data=i(this.data)}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||x(this.view.renderSpatialReference)||S(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&C(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=O(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=w(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=d(T.units[T[t.wkid]])),r&&(e=new _({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=y(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=f(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}_elevationInfoChanged(e){if(!e?.offset)this._wasm?.setLayerOffset(this,0);else if(!this._useEsriCrs)this._wasm?.setLayerOffset(this,k(e));else{let t=A(e?.unit)/this._metersPerVCSUnit,n=e?.offset??0;this._wasm?.setLayerOffset(this,n*t)}}_slicePlaneEnabledChanged(e){this._renderer&&(this._renderer.slicePlaneEnabled=e),this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e)}updateGaussians(){let e=[];for(let t of this._tileHandles.values())t.lifecycleState!==0&&e.push(t);this.data.updateGaussianVisibility(e,this._currentLyr3dVisibilityChange),this.notifyChange(`updating`)}get maximumGaussianCount(){return this.view.qualitySettings.gaussianSplat.maximumNumberOfGaussians*this.view.quality}set maximumGaussianCount(e){this._set(`maximumGaussianCount`,e)}_freeInvisibleTiles(){for(let e of this._tileHandles.values())e.lifecycleState===0&&!this._renderablesBeingCreated.has(e.handle)&&this._deleteTile(e)}extractHeader(e){let t=e.length-4,n=this.reinterpretU32AsFloat(e[t]),r=this.reinterpretU32AsFloat(e[t+1]),i=this.reinterpretU32AsFloat(e[t+2]),a=1/(1<<(e[t+3]&255));return{packedHeader:e.subarray(t,t+4),tileOrigin:{x:n,y:r,z:i},invPosScale:a}}_deleteTile(e){this._renderablesBeingCreated.has(e.handle)||this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}reinterpretU32AsFloat(e){return this._u32View[0]=e,this._f32View[0]}get performanceInfo(){let e=0,t=0;this._tileHandles.forEach(n=>{n.lifecycleState===0?t++:e++});let n=this.data?.textureAtlasMemory??0,r=this.data?.headerTextureMemory??0,i=this.data?.orderTextureMemory??0,a=this.data?.fadingTextureMemory??0,o=this.data?.sortBufferMemory??0;return new j(this.usedMemory,e,this._usedTileMemory,t,this._cacheTileMemory,n,r,i,a,o)}get test(){}};e([p()],$.prototype,`layer`,void 0),e([p({readOnly:!0})],$.prototype,`_clippingBox`,null),e([p()],$.prototype,`elevationOffset`,null),e([p({readOnly:!0})],$.prototype,`visibleAtCurrentScale`,null),e([p()],$.prototype,`fullExtentInLocalViewSpatialReference`,void 0),e([p()],$.prototype,`maximumGaussianCount`,null),$=Q=e([m(`esri.views.3d.layers.GaussianSplatLayerView3D`)],$);class ie{constructor(e){this.visibilityChange=e,this.incomingTileHandles=new Set}}const ae=$;export{ae as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,removeMaybe as r,destroyMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{watch as o,whenOnce as s,initial as c}from"../../../core/reactiveUtils.js";import{Milliseconds as l}from"../../../core/time.js";import{isUint32Array as u}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as d,convertUnit as f}from"../../../core/units.js";import{property as p,subclass as m}from"../../../core/accessorSupport/decorators.js";import{fromValues as h}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{getReferenceEllipsoid as g}from"../../../geometry/ellipsoidUtils.js";import _ from"../../../geometry/HeightModelInfo.js";import{create as v}from"../../../geometry/support/aaBoundingBox.js";import{isCompatible as y}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as b}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as x,isWebMercator as S,equals as C,isGeographic as w}from"../../../geometry/support/spatialReferenceUtils.js";import T from"../../../geometry/support/WKIDUnitConversion.js";import{validateEntity3D as E,makeCacheKey as D,getHeightModelInfoFromVCS as O}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as k}from"../../../support/elevationInfoUtils.js";import{getMetersPerUnit as A}from"../../../symbols/support/unitConversionUtils.js";import{GaussianSplatLayerViewPerformanceInfo as j}from"./GaussianSplatLayerViewPerformanceInfo.js";import{LayerView3D as M}from"./LayerView3D.js";import{addLayerViewToWasm as N,getLyr3DWasm as P,removeLayerViewFromWasm as F}from"./Lyr3DWasm.js";import{LayerElevationProvider as I}from"./i3s/LayerElevationProvider.js";import{ElevationRange as L}from"../support/ElevationRange.js";import{projectToBoundingBox as R}from"../support/extentUtils.js";import{Obb as z}from"../support/orientedBoundingBox.js";import{splatPageSizeInU32 as B,gaussiansPerPage as V,packedGaussianSizeInU32 as H,splatAtlasTextureWidth as U}from"../support/gaussianSplatting/GaussianSplatAtlasPages.js";import{GaussianSplatDataStore as W}from"../support/gaussianSplatting/GaussianSplatDataStore.js";import{GaussianSplatFadeHelper as G}from"../support/gaussianSplatting/GaussianSplatFadeHelper.js";import{GaussianSplatIntersectionHandler as K}from"../support/gaussianSplatting/GaussianSplatIntersectionHandler.js";import{GaussianTile as q}from"../support/gaussianSplatting/GaussianTile.js";import{GaussianSplatDepthRenderer as J}from"../webgl-engine/lib/GaussianSplatDepthRenderer.js";import{GaussianSplatRenderer as Y}from"../webgl-engine/lib/GaussianSplatRenderer.js";import{GaussianSplatShadows as X}from"../webgl-engine/lib/GaussianSplatShadows.js";import Z from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as ee}from"../../support/layerViewUtils.js";import{TaskPriority as te}from"../../support/Scheduler.js";var Q;const ne=()=>t.getLogger(`esri.views.3d.layers.GaussianSplatLayerView3D`),re=(()=>{let e=new Int16Array(256);e[0]=-255;for(let t=1;t<e.length;t++)e[t]=Math.round(16*Math.log(t/255));return e})();let $=class extends M(Z){static{Q=this}static{this.createRenderableBatchSize=64}static{this.uploadBatchPageCount=16}constructor(e){super(e),this.type=`gaussian-splat-3d`,this.ignoresMemoryFactor=!1,this._tileHandles=new Map,this._pageBuffer=new Uint32Array(B*Q.uploadBatchPageCount),this._tmpTilesWithChangedVisibility=[],this._renderablesBeingCreated=new Set,this._currentLyr3dVisibilityChange=0,this._tileFadeInsAwaitingInitialSort=new Set,this._pendingTileFadeOuts=new Map,this._pendingFadeDuration=l(0),this._createRenderableAbortController=new AbortController,this.skipHeightModelInfoValidation=!0,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this._usedTileMemory=0,this._cacheTileMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._suspendedHandle=null,this._conversionBuffer=new ArrayBuffer(4),this._u32View=new Uint32Array(this._conversionBuffer),this._f32View=new Float32Array(this._conversionBuffer);let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`GaussianSplat-${this.uid}`,e=>this._deleteTile(e)),this._frameTask=t.scheduler.registerTask(te.GAUSSIAN_SPLAT_TEXTURE_ATLAS)}get _clippingBox(){if(!this.view?.clippingArea)return null;let e=v();return R(this.view.clippingArea,e,this.view.renderSpatialReference)?e:null}get clippingBox(){return this._renderer?.clippingBox??null}initialize(){let{view:e}=this;this.addHandles([o(()=>e.qualitySettings.fadeDuration,e=>{this.data&&(this.fadeHelper.onFadeDurationChanged(e),this.updateFadingTexture())})]),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await s(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw ee(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await N(this,t),a(t),this._renderer=new Y({view:e,layerView:this}),this.data=new W(this._renderer,(e,t)=>this._onSortComplete(e,t),()=>this._freeInvisibleTiles()),this._shadows=new X({view:e,layerView:this}),this.fadeHelper=new G(this),this._prepassDepthRenderer=new J({view:e,layerView:this});let n=new K(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new I({view:e,layerElevationSource:this,intersectionHandler:n}),e.elevationProvider.register(2,this._elevationProvider),this.addHandles([o(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),o(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChanged(e),c)]),this._suspendedHandle=o(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),c),this.addHandles([o(()=>this._clippingBox,e=>{this._renderer&&(this._renderer.clippingBox=e)},c),o(()=>this.maximumGaussianCount,e=>this._wasm?.setMaximumGaussianSplatCount(Math.min(e,this.data.textureAtlas.maximumSupportedVisibleGaussians)),c)]),this._initializationController=null}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get tileHandles(){return this._tileHandles}updateFadingTexture(){this.data.fadingTexture.updateTexture(this.data.textureAtlas.pageAllocator.pageCount)}get _wasm(){return P(this.view)}get usedMemory(){return this._usedTileMemory+(this.data?.usedMemory??0)}get cachedMemory(){return this._cacheTileMemory}get unloadedMemory(){return 0}get useEsriCrs(){return this._useEsriCrs}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return k(this.layer.elevationInfo)}get elevationRange(){return this._intersectionHandler?.elevationRange}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get fullExtent(){return this.layer.fullExtent}get visibleAtCurrentScale(){return b(this.layer.effectiveScaleRange,this.view.scale)}isUpdating(){let e=this._wasm;return this._wasmLayerId<0||e==null?!1:e.isUpdating(this._wasmLayerId)||this.data.updating||this.fadeHelper.updating}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!E(t))throw Error(`entity3D not valid`);let n=t.desc.geometry.prims[t.validPrimitiveIndices[0]];if(n.atrbs.length<1||n.atrbs[0].sem!==`GSplatPacked`)throw Error(`entity3D not valid`);let r=n.atrbs[0],i=t.assets[r.assetId];if(!i)throw Error(`entity3D not valid`);let a=i.count;if(a===0)return ne().warnOnce(`encountered tile with zero Gaussians`),()=>({memUsageBytes:0,numGaussians:0});let o=null;if(i.dataType===`U32`&&u(i.data))o=i.data;else throw Error(`unexpected GaussianSplat Entity3D asset.data format`);let s=this.extractHeader(o),c=2.048,l=s.tileOrigin.x*c,d=s.tileOrigin.y*c,f=s.tileOrigin.z*c,p=t.desc,m=p.obb.quaternion,_=new z(p.obb.center,p.obb.halfSize,h(...m)),v=this.view.state.isGlobal,y=v?g(this.view.spatialReference).radius:0,b={handle:e.handle,bufferView:o,totalGaussians:a,packedHeader:s.packedHeader,tileOrigin:{x:l,y:d,z:f},invPosScale:s.invPosScale,obb:_,origin:{x:_.centerX,y:_.centerY,z:_.centerZ},isGlobal:v,ellipsoidRadius:y};this._renderablesBeingCreated.add(e.handle);let x;try{x=await this._frameTask.scheduleGenerator(e=>this._createRenderableTask(b,e),this._createRenderableAbortController.signal)}finally{this._renderablesBeingCreated.delete(e.handle)}return()=>x}*_createRenderableTask(e,t){let{handle:n,bufferView:r,totalGaussians:i,packedHeader:a,tileOrigin:o,invPosScale:s,obb:c,origin:l,isGlobal:u,ellipsoidRadius:d}=e,f=o.x,p=o.y,m=o.z,h=l.x,g=l.y,_=l.z,v=new Float32Array(i*3),y=new Uint32Array(i),b=new Uint32Array(i),x=[],S=Math.ceil(i/V),C=1/0,w=-1/0,T=1/0,E=-1/0,D=0,O=-1,k=0,A=0;for(let e=0;e<i;e++){let n=e*H,i=r[n],a=r[n+1],o=r[n+2],c=r[n+3],l=a&16383,d=a>>>14&16383,x=a>>>28&15|(o&1023)<<4,S=c>>>24,j=re[S],M=(o>>>10&255)+j,N=(o>>>18&255)+j,P=(o>>>26&63|(c&3)<<6)+j,F=M>0?M:0,I=N>0?N:0,L=P>0?P:0,R=F|I<<8|L<<16,z=Math.max(F,I,L),B=l*s+f,V=d*s+p,U=x*s+m;if(v[D]=B-h,v[D+1]=V-g,v[D+2]=U-_,u){let e=B*B+V*V+U*U;T=Math.min(T,e),E=Math.max(E,e)}else C=Math.min(C,U),w=Math.max(w,U);y[e]=i,b[e]=R,z>O&&(O=z),S>k&&(k=S),D+=3,A++,A===Q.createRenderableBatchSize&&(A=0,t.madeProgress()&&(t=yield))}A>0&&t.madeProgress()&&(t=yield),u&&(C=Math.sqrt(T)-d,w=Math.sqrt(E)-d);let j=this._extractGaussianSplatMbsRadiusSquared(O),M=new L(C,w),N=this.data.textureAtlas,P=this.data.headerTexture;try{for(let e=0;e<S;e+=Q.uploadBatchPageCount){let n=Math.min(S,e+Q.uploadBatchPageCount);for(let t=e;t<n;t++){let e=N.allocatePage();if(e===null&&(this._freeInvisibleTiles(),e=N.allocatePage()),e===null)throw Error(`ran out of gaussian splat memory`);x.push(e)}for(let t=e;t<n;){let e=x[t],o=t+1;for(;o<n&&x[o]===x[o-1]+1;)o++;let s=o-t,c=i-t*V,l=Math.min(c,s*V),u=t*B,d=l*H;this._pageBuffer.set(r.subarray(u,u+d));let f=e*V,p=f%U,m=Math.floor(f/U);N.update(p,m,this._pageBuffer,s),P.update(e,a,s),t=o}t.madeProgress()&&(t=yield)}}catch(e){throw N.freePages(x),e}let F=new q({handle:n,obb:c,pageIds:x,relativePositions:v,packedRotations:y,packedOpacityScaledScales:b,gaussianCount:i,maxSplatMbsRadiusSquared:j,maxGaussianOpacity:k/255,elevationRange:M});return this._tileHandles.set(n,F),this._cacheTileMemory+=F.usedMemory,this._memCache.put(`${F.handle}`,F),{memUsageBytes:F.usedMemory,numGaussians:i}}_extractGaussianSplatMbsRadiusSquared(e){return Math.exp(e/8-20)*9}freeRenderable(e){this._tileFadeInsAwaitingInitialSort.delete(e),this._pendingTileFadeOuts.delete(e);let t=this.data?.textureAtlas,n=!1,r=this._tileHandles.get(e);if(r){let i=!1;for(let t of this._pendingTileFadeOuts.values())t.incomingTileHandles.has(e)&&(t.visibilityChange=this._currentLyr3dVisibilityChange+1,i=!0);i&&(this._currentLyr3dVisibilityChange++,n=!0),r.lifecycleState===0?this._cacheTileMemory-=r.usedMemory:(n=!0,this.fadeHelper.onTileDiscarded(r),this._usedTileMemory-=r.usedMemory,this._intersectionHandler.removeTile(r)),t&&r.pageIds.forEach(e=>t.freePage(e)),this._removeTileCacheEntry(r),this._tileHandles.delete(e)}n&&this.updateActiveTileVisibility()}_removeTileCacheEntry(e){this._memCache.pop(`${e.handle}`)}notifyTileObbsChanged(e){this._elevationProvider&&this._elevationProvider.notifyObjectsChangedFunctional(e.length,t=>{for(let{obb:n}of e)if(!t(n))break})}setRenderableVisibility(e,t,n){let r=this.fadeHelper.updateFadeDuration(),i=new ie(this._currentLyr3dVisibilityChange+1),a=new Set,o=!1;for(let s=0;s<n;s++){let n=this._tileHandles.get(e[s]);if(!n)continue;let c=t[s]?this._prepareTileFadeIn(n,r):this._prepareTileFadeOut(n,i);t[s]&&i.incomingTileHandles.add(n.handle),c&&a.add(n.handle),o||=c}if(o){if(this._currentLyr3dVisibilityChange++,this._pendingFadeDuration=r,this._updatePendingTileHandoffs(a,i),i.incomingTileHandles.size===0)for(let e of this._tileFadeInsAwaitingInitialSort)i.incomingTileHandles.add(e);this.updateActiveTileVisibility()}}_updatePendingTileHandoffs(e,t){for(let n of new Set(this._pendingTileFadeOuts.values())){if(n===t)continue;let r=!1;for(let i of e)n.incomingTileHandles.has(i)&&(r=!0,t.incomingTileHandles.size>0&&n.incomingTileHandles.delete(i));if(r){n.visibilityChange=t.visibilityChange;for(let e of t.incomingTileHandles)n.incomingTileHandles.add(e)}}}_prepareTileFadeIn(e,t){let n=this._pendingTileFadeOuts.delete(e.handle);return e.lifecycleState===2?(this.fadeHelper.fadeTile(e,0,t),!1):this._tileFadeInsAwaitingInitialSort.has(e.handle)?n:(e.lifecycleState===0&&this._popTileFromCache(e),e.lifecycleState=1,this._tileFadeInsAwaitingInitialSort.add(e.handle),!0)}_prepareTileFadeOut(e,t){let n=this._tileFadeInsAwaitingInitialSort.delete(e.handle);return n&&e.lifecycleState===1&&(this.moveTileToCache(e),e.lifecycleState=0),e.lifecycleState===2?this._pendingTileFadeOuts.has(e.handle)?n:(this._pendingTileFadeOuts.set(e.handle,t),!0):n}_onSortComplete(e,t){let n=this._tmpTilesWithChangedVisibility;n.length=0,this._triggerFadeIns(e,n);let r=this._triggerFadeOuts(t,n);n.length>0&&this.notifyTileObbsChanged(n),r&&this.updateActiveTileVisibility()}_triggerFadeIns(e,t){for(let n of e)this._tileHandles.get(n.handle)===n&&this._tileFadeInsAwaitingInitialSort.delete(n.handle)&&(n.lifecycleState=2,t.push(n),this.fadeHelper.fadeTile(n,0,this._pendingFadeDuration))}_triggerFadeOuts(e,t){let n=!1;for(let t of this._pendingTileFadeOuts.values())if(e>=t.visibilityChange){n=!0;break}if(!n)return!1;let r=this._pendingFadeDuration,i=this._pendingFadeDuration;for(let e of this._tileHandles.values()){let{fadeDirection:t,fadeDuration:n,fadeProgress:a}=e;if(t!==0||n==null||a==null)continue;let o=n*(1-a);r=l(Math.max(r,o)),i=l(Math.max(i,n))}let a=!1;for(let[n,o]of this._pendingTileFadeOuts){if(e<o.visibilityChange)continue;this._pendingTileFadeOuts.delete(n);let s=this._tileHandles.get(n);if(s){let e=s.lifecycleState===2,n=s.opacityModifier===1?r:i;this.fadeHelper.fadeTile(s,1,n),e&&s.lifecycleState===0&&(t.push(s),a=!0)}}return a}_popTileFromCache(e){this._usedTileMemory+=e.usedMemory,this._cacheTileMemory-=e.usedMemory,this._intersectionHandler.addTile(e),this._memCache.pop(D(e.handle))}moveTileToCache(e){this._usedTileMemory-=e.usedMemory,this._cacheTileMemory+=e.usedMemory,this._intersectionHandler.removeTile(e),this._memCache.put(D(e.handle),e)}destroy(){this._initializationController=n(this._initializationController),this._createRenderableAbortController.abort(),F(this),this._suspendedHandle&&=r(this._suspendedHandle),this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),null),this._elevationProvider&&this.view.elevationProvider&&(this._elevationProvider.notifyObjectsChangedFunctional(this._tileHandles.size,e=>{for(let{obb:t}of this._tileHandles.values())if(!e(t))break}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null),this._frameTask.remove(),this._shadows=i(this._shadows),this._prepassDepthRenderer=i(this._prepassDepthRenderer),this._renderer=i(this._renderer),this._memCache.destroy(),this.data=i(this.data)}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||x(this.view.renderSpatialReference)||S(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&C(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=O(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=w(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=d(T.units[T[t.wkid]])),r&&(e=new _({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=y(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=f(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}_elevationInfoChanged(e){if(!e?.offset)this._wasm?.setLayerOffset(this,0);else if(!this._useEsriCrs)this._wasm?.setLayerOffset(this,k(e));else{let t=A(e?.unit)/this._metersPerVCSUnit,n=e?.offset??0;this._wasm?.setLayerOffset(this,n*t)}}_slicePlaneEnabledChanged(e){this._renderer&&(this._renderer.slicePlaneEnabled=e),this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e)}updateActiveTileVisibility(){let e=[];for(let t of this._tileHandles.values())t.lifecycleState!==0&&e.push(t);this.data.updateGaussianVisibility(e,this._currentLyr3dVisibilityChange),this.notifyChange(`updating`)}get maximumGaussianCount(){return this.view.qualitySettings.gaussianSplat.maximumNumberOfGaussians*this.view.quality}set maximumGaussianCount(e){this._set(`maximumGaussianCount`,e)}_freeInvisibleTiles(){for(let e of this._tileHandles.values())e.lifecycleState===0&&!this._renderablesBeingCreated.has(e.handle)&&this._deleteTile(e)}extractHeader(e){let t=e.length-4,n=this.reinterpretU32AsFloat(e[t]),r=this.reinterpretU32AsFloat(e[t+1]),i=this.reinterpretU32AsFloat(e[t+2]),a=1/(1<<(e[t+3]&255));return{packedHeader:e.subarray(t,t+4),tileOrigin:{x:n,y:r,z:i},invPosScale:a}}_deleteTile(e){this._renderablesBeingCreated.has(e.handle)||this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}reinterpretU32AsFloat(e){return this._u32View[0]=e,this._f32View[0]}get performanceInfo(){let e=0,t=0;this._tileHandles.forEach(n=>{n.lifecycleState===0?t++:e++});let n=this.data?.textureAtlasMemory??0,r=this.data?.headerTextureMemory??0,i=this.data?.orderTextureMemory??0,a=this.data?.fadingTextureMemory??0,o=this.data?.sortBufferMemory??0;return new j(this.usedMemory,e,this._usedTileMemory,t,this._cacheTileMemory,n,r,i,a,o)}get test(){}};e([p()],$.prototype,`layer`,void 0),e([p({readOnly:!0})],$.prototype,`_clippingBox`,null),e([p()],$.prototype,`elevationOffset`,null),e([p({readOnly:!0})],$.prototype,`visibleAtCurrentScale`,null),e([p()],$.prototype,`fullExtentInLocalViewSpatialReference`,void 0),e([p()],$.prototype,`maximumGaussianCount`,null),$=Q=e([m(`esri.views.3d.layers.GaussianSplatLayerView3D`)],$);class ie{constructor(e){this.visibilityChange=e,this.incomingTileHandles=new Set}}const ae=$;export{ae as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import t from"../../../Color.js";import n from"../../../Graphic.js";import{removeUnordered as r,isSome as i}from"../../../core/arrayUtils.js";import has from"../../../core/has.js";import a from"../../../core/Logger.js";import{equals as o}from"../../../core/MapUtils.js";import{destroyMaybe as s}from"../../../core/maybe.js";import c from"../../../core/PooledArray.js";import{ignoreAbortErrors as l,isAbortError as u,throwIfAborted as d}from"../../../core/promiseUtils.js";import{initial as f,watch as p}from"../../../core/reactiveUtils.js";import{schedule as m}from"../../../core/scheduling.js";import{equals as h}from"../../../core/SetUtils.js";import{isArrayBuffer as g}from"../../../core/typedArrayUtil.js";import{property as _,subclass as v}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as y,exactEquals as b,invert as ee}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as te,IDENTITY as ne}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{multiply as re,getTranslation as ie}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{clone as ae,create as oe}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as se}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{set as x,transformMat4 as S,transformMat3 as ce,sub as le,add as C,scale as ue,subtract as w}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as T}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as E}from"../../../core/libs/gl-matrix-2/math/vec4.js";import{fromValues as de}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as D}from"../../../core/support/UpdatingHandles.js";import{getSphericalPCPF as O}from"../../../geometry/spatialReferenceEllipsoidUtils.js";import{localLinearScaleFactors as fe}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectBoundingSphere as pe}from"../../../geometry/projection/projectBoundingSphere.js";import{projectBuffer as me}from"../../../geometry/projection/projectBuffer.js";import{getProjectorName as k}from"../../../geometry/projection/projectors.js";import{projectVectorToVector as A}from"../../../geometry/projection/projectVectorToVector.js";import{create as j,fromBuffer as he,toRect as ge}from"../../../geometry/support/aaBoundingBox.js";import{create as M,intersects as N}from"../../../geometry/support/aaBoundingRect.js";import{newDoubleArray as P,ensurePackedMat4f64 as _e}from"../../../geometry/support/DoubleArray.js";import{compactFloatArray as ve}from"../../../geometry/support/FloatArray.js";import{compactIndices as ye}from"../../../geometry/support/Indices.js";import{Sphere as F}from"../../../geometry/support/sphere.js";import{newUByteArray as I}from"../../../geometry/support/UByteArray.js";import{fallbackObjectIDAttribute as L}from"../../../layers/LayerConstants.js";import be from"../../../layers/graphics/controllers/I3SOnDemandController.js";import{fixFields as xe}from"../../../layers/support/fieldUtils.js";import{I3SExtractChanges as Se}from"../../../layers/support/I3SExtractChanges.js";import R from"../../../layers/support/SceneModification.js";import{getColor as Ce,getOpacity as we}from"../../../renderers/visualVariables/support/visualVariableUtils.js";import{isBasemapLayerView as z}from"../../../support/basemapUtils.js";import{getElevationOffset as B}from"../../../support/elevationInfoUtils.js";import{loadArcade as Te}from"../../../support/loadArcade.js";import V from"../../../symbols/MeshSymbol3D.js";import Ee from"../../../symbols/SimpleFillSymbol.js";import{ContentGeometryUpdateEvent as De}from"./ContentGeometryLayerView.js";import Oe from"./I3SMeshViewLabeler.js";import{I3SMeshViewPerformanceInfo as ke}from"./I3SMeshViewPerformanceInfo.js";import{initialize as Ae,setModificationsSync as je,filterObbsForModificationsSync as Me,interpretObbModificationResults as Ne}from"./SceneLayerWorker.js";import{SceneLayerWorkerHandle as Pe,toWasmModification as Fe}from"./SceneLayerWorkerHandle.js";import{overrideColor as Ie}from"./graphics/graphicUtils.js";import{areLabelsVisible as Le}from"./graphics/Labeler.js";import Re from"./i3s/Highlights.js";import{I3SAsyncElevationUpdater as ze}from"./i3s/I3SAsyncElevationUpdater.js";import{getCachedAttributeValue as H}from"./i3s/I3SBinaryReader.js";import{I3SCrossfadeHelper as Be,NodeCrossfadeMetaData as Ve}from"./i3s/I3SCrossfadeHelper.js";import{boundingBoxCornerPoints as He}from"./i3s/I3SGeometryUtil.js";import{I3SIntersectionHandler as Ue,TraversedIntersectionNode as We}from"./i3s/I3SIntersectionHandler.js";import{getSupportedEncodings as Ge,selectEncoding as Ke,defaultMaterial as qe,createTexture as Je,configureMaterial as Ye}from"./i3s/I3SMaterialUtil.js";import{I3SOverrides as Xe}from"./i3s/I3SOverrides.js";import{computeGlobalTransformation as Ze}from"./i3s/I3SProjectionUtil.js";import{rendererNeedsTextures as Qe,checkSceneLayerValid as $e,checkSceneLayerCompatibleWithView as et,whenGraphicAttributes as tt,computeVisibilityObb as nt,filterInPlace as rt,intersectBoundingRectWithMbs as it,addWraparound as U,getSymbolInfo as at,transparentEdgeMaterial as W,getClipRect as ot}from"./i3s/I3SUtil.js";import{IDBCache as st}from"./i3s/IDBCache.js";import{IDBMockCache as ct}from"./i3s/IDBMockCache.js";import{LayerElevationProvider as lt}from"./i3s/LayerElevationProvider.js";import{SymbologyInfo as ut}from"./i3s/SymbologyInfo.js";import{attributeLookup as G}from"./support/attributeUtils.js";import{normalizeHighlightTarget as dt,emptyHighlightHandle as ft}from"./support/highlightUtils.js";import{makeScheduleFunction as pt}from"./support/makeScheduleFunction.js";import{debugFlags as K}from"../support/debugFlags.js";import{ElevationRange as q}from"../support/ElevationRange.js";import{toBoundingRect as mt}from"../support/extentUtils.js";import{Obb as J,ensurePackedObbData as ht}from"../support/orientedBoundingBox.js";import{updatingProgress as gt}from"../support/updatingProperties.js";import{glLayout as _t}from"../support/buffer/glUtil.js";import{ObjectParameters as vt}from"../webgl-engine/collections/Component/ObjectParameters.js";import{createVertexBufferLayout as yt,ComponentGeometryParameters as bt,SourceGeometry as xt,VertexBufferLayoutCreationParameters as St}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as Ct}from"../webgl-engine/collections/Component/Transform.js";import{emissiveStrengthDefault as Y}from"../webgl-engine/core/shaderLibrary/output/getEmissions.glsl.js";import{getHighlightName as wt}from"../../support/highlightOptionsUtils.js";import{TextureCompressionTracker as Tt}from"../../support/TextureCompressionTracker.js";import{alphaCutoff as Et}from"../../../webscene/support/AlphaCutoff.js";const Dt=[1,1,1,1];class Ot extends Ve{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this.node=e,this.featureIds=t,this.objectHandle=n,this.cachedRendererVersion=r,this.attributeInfo=i,this.material=a,this.textures=o,this.anchorIds=s,this.anchors=c,this._elevationAlignmentRange=new q,this._geometryElevationRange=new q,this.cachedElevationAnchors=null,this.cachedEdgeMaterials=[],this.edgeMemoryUsage=0,this.cachedSymbologyStride=5,this.elevationAlignmentOffset=0,this._baseGeometryElevationRange=new q(l,u),this.updateGeometryElevationRange()}get geometryElevationRange(){return this._geometryElevationRange}updateGeometryElevationRange(){let e=this._baseGeometryElevationRange;if(!e.elevationRangeValid||e.isEmpty){this._elevationAlignmentRange.invalidateElevationRange(),this._geometryElevationRange.invalidateElevationRange();return}let t=this.elevationOffsets;if(!t||t.length===0){let t=this.elevationAlignmentOffset;this._elevationAlignmentRange.setElevationRangeValues(t,t),this._geometryElevationRange.setElevationRangeValues(e.minElevation+t,e.maxElevation+t);return}let n=1/0,r=-1/0;for(let e=0;e<t.length;++e){let i=this.elevationAlignmentOffset+(t[e]??0);n=Math.min(n,i),r=Math.max(r,i)}this._elevationAlignmentRange.setElevationRangeValues(n,r),this._geometryElevationRange.setElevationRangeValues(e.minElevation+n,e.maxElevation+r)}get usedMemory(){return this.node.memory}get featureExtents(){return this._featureExtents??=new Float64Array(6*this.featureIds.length).fill(1/0),this._featureExtents}}const kt=t=>{let g=t,F=class extends g{constructor(){super(...arguments),this._extractChanges=null,this._applySSAO=!0,this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._updatingHandles=new D,this._highlights=null,this._nodeId2Meta=new Map,this._nodeId2MetaReloading=new Map,this._i3sWasmLoaded=!1,this._snappingSourcesTrackers=[],this._compressionTracker=new Tt,this._hasLoadedPBRTextures=!1,this._asyncModuleLoading=0,this._addTasks=new Map,this._currentRenderer=null,this._rendererVersion=0,this._colorVariable=null,this._opacityVariable=null,this._rendererFields=null,this._symbologyFields=null,this._symbologyOverride=null,this._symbologyOverrideFields=null,this._symbolInfos=new Map,this._visibleGeometryChangedSchedulerHandle=null,this._hasComponentData=!1,this._hasVertexColors=!1,this._nodeColorOverride=null,this.updating=!0,this.holeFilling=`auto`,this._hasColors=!1,this._hasTextures=!1,this._hasData=!1,this.slicePlaneEnabled=!1,this._modifications=[],this.ignoresMemoryFactor=!1,this._layerUrl=``,this._cacheKeySuffix=null,this._meshUtilsImporterModule=null,this._meshUtilsImporterPromise=null,this._planetRadiusInGlobalMode=0,this._elevationTask=null,this._needFilterResolve=!1,this._filters=[],this._arcade=null,this._tmpAttributeOnlyGraphic=new n,this._crossfadeHelper=new Be(this)}get lodCrossfadeoutDuration(){return 0}get lodCrossfadeinDuration(){return 0}get lodCrossfadeUncoveredDuration(){return 0}get extractChanges(){return this._extractChanges?.layer!==this.layer&&(this._extractChanges?.destroy(),this._extractChanges=new Se({layer:this.layer})),this._extractChanges}get layerViewUid(){return this.uid}get layerId(){return this.layer.id}get sublayerId(){return null}get _isIntegratedMesh(){return this.layer.type===`integrated-mesh`}get contentVisible(){return!this.suspended&&this._controller?.rootNodeVisible&&this.fullOpacity>Et}get legendEnabled(){return this.contentVisible&&this.layer?.legendEnabled===!0}get updatingProgressValue(){return this._controller?.updatingProgress??0}get hasTexturesOrVertexColors(){return this._hasData?this._hasTextures||this._hasColors?`yes`:`probably-not`:`unknown`}get rendererTextureUsage(){return Qe(this._currentRenderer)?this._usePBR||this._hasLoadedPBRTextures?63:53:this._usePBR||this._hasLoadedPBRTextures?44:36}get elevationOffset(){let e=this.layer?.elevationInfo;return e?.mode===`absolute-height`?B(e,this.layer.spatialReference):0}get elevationInfo(){let e=this.layer?.elevationInfo;switch(e?.mode){case`absolute-height`:return new Z(0,B(e,this.layer.spatialReference));case`relative-to-ground`:return new Z(1,B(e,this.layer.spatialReference));case`on-the-ground`:return new Z(2,0);default:return new Z(0,0)}}get supportedTextureEncodings(){return Ge(this.view.stage.renderView.capabilities)}get clientGeometry(){return this.i3sOverrides.geometryOverrides}get elevationRange(){let e=this._nodeId2Meta,t=new q;for(let n of e.values()){let e=n?.geometryElevationRange;e?.elevationRangeValid&&!e.isEmpty&&t.expandElevationRange(e)}return t.elevationRangeValid&&!t.isEmpty?t:null}get fullExtent(){return this.layer.fullExtent}initialize(){let e=has(`enable-feature:idb-mock-cache`);this._idbCache=e?new ct(this.view,e):new st(`esri-scenelayer-cache`,`geometries`),this.addResolvingPromise(this.layer.indexInfo);let t=this.view.resourceController,n=t.memoryController;this.i3sOverrides=new Xe({view:this.view,layer:this.layer,memoryController:n,extractChanges:this.extractChanges}),this._workerHandle=new Pe(pt(t)),this.addResolvingPromise(this._workerHandle.promise),$e(this.layer),et(this.layer,this.view);let r=this.layer.store.defaultGeometrySchema;if(this.addResolvingPromise(this._workerHandle.setLegacySchema(this.uid,r).catch(l)),this._layerUrl=this.layer.parsedUrl.path,this._controller=new be({layerView:this,worker:this._workerHandle}),this._gpuMemoryEstimate=0,this._texMemoryEstimate=0,this._geoMemoryEstimate=0,this._stage=this.view.stage,this._collection=this._stage.renderView.componentObjectCollection,this._isIntegratedMesh||!r)this._hasComponentData=!1;else{let e=r.featureAttributes;this._hasComponentData=!!(e&&e.faceRange&&e.id)}this._hasVertexColors=(r?.vertexAttributes.color??null)!=null&&!this.layer.cachedDrawingInfo?.color;let i=this.view.resourceController.memoryController.newCache(`sl-${this.uid}`,e=>this._deleteComponentObject(e));this._memCache=i;let o=this._controller,c=this._nodeId2Meta,u=this._nodeId2MetaReloading;function*d(e){let t=o.index;if(!t)return;let n=t.rootNode;if(!n)return;let r=null;for(let i of t.traverseValues(n,t=>(r=(c.get(t.index)||u.get(t.index))?.objectHandle??null,e(t,r))))yield new We(i,r)}this._intersectionHandler=new Ue({layerViewUid:this.layerViewUid,sublayerId:this.sublayerId,collection:this._collection,slicePlaneEnabled:this.slicePlaneEnabled,isGround:has(`enable-feature:im-as-ground`)?this.layer.isUsedAsGroundLayer:this._isIntegratedMesh,traverseNodeHierarchy:d}),this._elevationProvider=new lt({view:this.view,layerElevationSource:this,intersectionHandler:this._intersectionHandler}),this._hasLoadedPBRTextures=this._usePBR,this._updatingHandles.add(()=>this.view.clippingArea,()=>this._clippingAreaChanged(),f),this._updatingHandles.add(()=>this.fullOpacity,e=>this._opacityChange(e)),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this.elevationOffset,(e,t)=>{this._reloadAll(t),this._controller.invalidateVisibilityObbs()}),this._updatingHandles.add(()=>this.elevationInfo,(e,t)=>this._elevationInfoChanged(e,t),f),this._updatingHandles.add(()=>!this.suspended&&this.elevationInfo.mode!==0,(e,t)=>{e?this.addHandles(this.view.groundView.on(`elevation-change`,({extent:e})=>this._ensureElevationTask().addExtent(e)),Wt):t&&this.removeHandles(Wt)},f),this._updatingHandles.add(()=>this._usePBR,e=>this._updatePBR(e)),this._updatingHandles.add(()=>this.rendererTextureUsage,()=>{this._reloadAll(),this.clearMemCache()}),this._updatingHandles.add(()=>this.contentVisible,e=>this._contentVisibleChanged(e),f),this._updatingHandles.add(()=>this.layer.labelsVisible,()=>this._labelingChanged(),f),this._updatingHandles.add(()=>this.layer.labelingInfo,()=>this._labelingChanged(),f),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged(),f),this.addHandles([p(()=>K.I3S_TREE_SHOW_TILES,e=>{if(e&&!this._treeDebugger){let e=this._controller.crsIndex;import(`./support/I3STreeDebugger.js`).then(({I3STreeDebugger:t})=>{!this._treeDebugger&&K.I3S_TREE_SHOW_TILES&&(this._treeDebugger=new t({lv:this,view:this.view,nodeSR:e}))})}else!e&&!K.I3S_TREE_SHOW_TILES&&(this._treeDebugger=s(this._treeDebugger))},f),p(()=>K.I3S_SHOW_MODIFICATIONS,()=>this._showModifications(),f)]),this._cacheKeySuffix=this._getCacheKeySuffix(),this._idbCache.init().catch(e=>a.getLogger(this).warn(`Failed to initialize IndexedDB cache: ${e}`));let{view:m}=this,{viewingMode:h,renderCoordsHelper:g}=m;this._planetRadiusInGlobalMode=h===`local`?0:g.referenceEllipsoid.radius}destroy(){this._clearAddTasks(),this._elevationTask=s(this._elevationTask),this.i3sOverrides=s(this.i3sOverrides),this._extractChanges=s(this._extractChanges),this._elevationProvider&&=(this._elevationProvider.notifyObjectsChanged(this.getVisibleObbs()),this.view.elevationProvider.unregister(this._elevationProvider),null),this._intersectionHandler&&=(this._stage.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),null);let e=this._workerHandle;e&&(e.destroyContextAndSelf(this.uid),this._workerHandle=null),this._removeAllNodeDataFromStage(),this._memCache=s(this._memCache),this._collection=null,this._stage=null,this._edgeView=null,this._labeler=s(this._labeler),this._treeDebugger=s(this._treeDebugger),this._controller=s(this._controller),this._highlights=s(this._highlights),this._nodeId2Meta.clear(),this._nodeId2MetaReloading.clear(),this._crossfadeHelper=s(this._crossfadeHelper),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle&&=(this._visibleGeometryChangedSchedulerHandle.remove(),null),this._updatingHandles=s(this._updatingHandles)}_memEstimateTextureAdded(e){let t=e.usedMemory;return this._gpuMemoryEstimate+=t,this._texMemoryEstimate+=t,t}_memEstimateTextureRemoved(e){if(e!=null){let t=e.usedMemory;this._gpuMemoryEstimate-=t,this._texMemoryEstimate-=t}}_memEstimateGeometryAdded(e){let t=this._collection.getObjectGPUMemoryUsage(e);return this._gpuMemoryEstimate+=t,this._geoMemoryEstimate+=t,t}_memEstimateGeometryRemoved(e){let t=this._collection.getObjectGPUMemoryUsage(e);this._gpuMemoryEstimate-=t,this._geoMemoryEstimate-=t}isNodeLoaded(e){return this._nodeId2Meta.has(e)}isNodeReloading(e){return this._nodeId2MetaReloading.has(e)}get usedMemory(){let e=this._labeler==null?0:this._labeler.usedMemory;return this._nodeId2Meta.forEach(t=>e+=t==null?0:t.node.memory),this._nodeId2MetaReloading.forEach(t=>e+=t==null?0:t.node.memory),e}get unloadedMemory(){return(this._controller==null?0:this._controller.unloadedMemoryEstimate)+(this._labeler==null?0:this._labeler.unloadedMemoryEstimate)}_labelingChanged(){if(!(Le(this.layer)&&this._supportsLabeling)){this._labeler!=null&&(this._labeler.destroy(),this._labeler=null);return}if(this._labeler!=null)return;let e=new Oe({view:this.view,layer:this.layer,collection:this._collection,overrides:this.i3sOverrides,layerViewUid:this.uid});this._nodeId2Meta.forEach(t=>t!=null&&this._addMetaToLabeler(e,t)),this._labeler=e}_loadAsyncModule(e){return++this._asyncModuleLoading,e.then(e=>(--this._asyncModuleLoading,e),e=>{throw--this._asyncModuleLoading,e})}_modificationsChanged(){if(!this._i3sWasmLoaded&&this.hasModifications){this._i3sWasmLoaded=Ae().then(()=>{this._i3sWasmLoaded=!0,this._modificationsChanged(),this.notifyUpdate()},()=>{}),this.notifyUpdate();return}if(this._i3sWasmLoaded!==!0)return;let e=e=>a.getLogger(this).error(`set-modifications-error`,`Error when setting modifications:`,e),t=this.uid,n=this.layer.spatialReference,r=n.isGeographic,i=Fe(this._layerClippingArea,this._modifications,n,this.view.state.isGlobal);this._workerHandle.setModifications(t,i,r).catch(e);try{je({context:t,modifications:i,isGeodetic:r})}catch(t){e(t)}this._controller.modificationsChanged();let o=this.hasModifications?new c:null;this._nodeId2Meta.forEach((e,t)=>{e==null?(this._nodeId2Meta.delete(t),this._controller.updateLoadStatus(t,!1)):e.node.hasModifications?(this._updateFeatureIdCounts(e,-1),this._nodeId2Meta.delete(t),this._nodeId2MetaReloading.set(t,e)):o?.push(e.node)}),this.notifyChange(`elevationRange`),o!=null&&this._nodeId2MetaReloading.forEach(e=>o.push(e.node)),o!=null&&o.length>0&&(this.updateNodeModificationStatus(o),o.forAll(e=>{if(e.imModificationImpact!==2){let t=this._nodeId2Meta.get(e.index);this._controller.invalidateGeometryVisibility(e.index),t==null?this._nodeId2Meta.has(e.index)&&(this._nodeId2Meta.delete(e.index),this._controller.updateLoadStatus(e.index,!1)):(this._updateFeatureIdCounts(t,-1),this._nodeId2Meta.delete(e.index),this._nodeId2MetaReloading.set(e.index,t),this.notifyChange(`elevationRange`))}})),this.clearMemCache(),this._controller.restartNodeLoading(),this._showModifications()}_showModifications(){if(this._modificationGraphics!=null&&(this.view.graphics.removeMany(this._modificationGraphics),this._modificationGraphics=null),!K.I3S_SHOW_MODIFICATIONS||this._modifications.length===0)return;let e={clip:[227,227,79,.8],mask:[227,139,79,.8],replace:[139,227,79,.8]},t={outline:{color:[255,255,255],width:1}};this._modificationGraphics=[];for(let r of this._modifications){let i=r.geometry;i.spatialReference=this.layer.spatialReference;let a=new Ee({...t,color:e[r.type]});this._modificationGraphics.push(new n({geometry:i,symbol:a}))}this.view.graphics.addMany(this._modificationGraphics)}_addMetaToLabeler(e,t){e.addNodeMeta(t,(e,t)=>this._createAttributes(e,t))}_contentVisibleChanged(e){e?(this.view.elevationProvider.register(this._elevationContext,this._elevationProvider),this._stage.view.sceneIntersectionHelper.addIntersectionHandler(this._intersectionHandler)):(this._removeAllNodeDataFromStage(),this.view.elevationProvider&&this.view.elevationProvider.unregister(this._elevationProvider),this._stage.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler))}getLoadedAttributes(e){let t=this._nodeId2Meta.get(e);if(t?.attributeInfo!=null)return t.attributeInfo.loadedAttributes}getAttributeData(e){let t=this._nodeId2Meta.get(e);if(t?.attributeInfo!=null)return t.attributeInfo.attributeData}setAttributeData(e,t){let n=this._nodeId2Meta.get(e);n?.attributeInfo!=null&&(n.attributeInfo.attributeData=t,this._attributeValuesChanged(n))}async updateAttributes(e,t,n){let r=this._nodeId2Meta.get(e);r!=null&&(await this.i3sOverrides.applyAttributeOverrides(r.featureIds,t,n,this._controller.requiredAttributes),r.attributeInfo=t,this._controller.reschedule(()=>{this._nodeId2Meta.get(e)===r&&this._attributeValuesChanged(r)},n).catch(e=>{u(e)||a.getLogger(this).warn(`Error while updating attribute values. Layer might not display correctly.`,e)}))}_attributeValuesChanged(e){e.cachedRendererVersion=this._getInvalidRendererVersion(),e.appliedFilters=null,this._labeler!=null&&this._labeler.setNodeMetaAttributes(e,(e,t)=>this._createAttributes(e,t)),this._updateEngineObject(e)}clearMemCache(){this._memCache!=null&&this._memCache.clear(),this._addTasks.forEach(e=>e.allowMemCache=!1)}getVisibleNodes(){let e=[];return this._nodeId2Meta.forEach(t=>t!=null&&e.push(t.node)),e}getVisibleObbs(){let e=[];return this._nodeId2Meta.forEach(t=>t&&e.push(this._collection.getComponentObb(t.objectHandle))),e}getLoadedNodeIndices(e){this._nodeId2Meta.forEach((t,n)=>e.push(n)),this._nodeId2MetaReloading.forEach((t,n)=>e.push(n))}_getVertexBufferLayout(e,t){return _t(yt(this._getGeometryParameters({hasTexture:It(e.params.material),hasNormals:t.normal,hasRegions:t.uvRegion})))}_getObjectIdField(){return this.layer.objectIdField||L}_getGlobalIdField(){return this.layer.globalIdField}_findGraphicNodeAndIndex(e){let t=G(this.layer.fieldsIndex,e.attributes,this._getObjectIdField());for(let e of this._nodeId2Meta.values()){let n=e?.featureIds.indexOf(t);if(n!=null&&n>=0)return{node:e.node,index:n}}return null}_getGraphicIndices(e,t){let n=this._nodeId2Meta.get(e.index);if(n==null)return[];let r=[],i=this._getObjectIdField(),a=this.layer.fieldsIndex;for(let e of t){let t=G(a,e.attributes,i),o=n.featureIds.indexOf(t);o!==-1&&r.push(o)}return r}whenGraphicBounds(e){let t=this._findGraphicNodeAndIndex(e);if(!t)return Promise.reject();let n=this.getAABB(t.node.index,t.index);return n==null?Promise.reject():Promise.resolve({boundingBox:n,screenSpaceObjects:[]})}getAABBFromIntersectorTarget(e){return e.nodeIndex==null||e.componentIndex==null?null:this.getAABB(e.nodeIndex,e.componentIndex)}getAABB(e,t){let n=this._nodeId2Meta.get(e);if(n?.featureIds==null||t>=n.featureIds.length)return null;let r=n.objectHandle,i=He(t,this._collection,r,P(24),0),a=this.view.renderSpatialReference,o=this.view.spatialReference;return me(i,a,0,i,o,0)?he(i):null}whenGraphicAttributes(e,t){return tt(this.layer,e,this._getObjectIdField(),t,()=>this._nodeId2Meta.values().filter(i).toArray())}getGraphicFromIntersectorTarget(e,t){if(e.nodeIndex==null||e.componentIndex==null)return null;let n=this._nodeId2Meta.get(e.nodeIndex);if(n?.featureIds==null||e.componentIndex>=n.featureIds.length)return null;let r=this._createLayerGraphic(this._createAttributes(e.componentIndex,n));return r?this._meshUtilsImporterModule?(r.geometry=this._meshUtilsImporterModule.createMesh({layerView:this,nodeIndex:e.nodeIndex,featureIndex:e.componentIndex}),r):t.defer?(t.defer(async()=>(r.geometry=(await this._meshUtilsImporter).createMesh({layerView:this,nodeIndex:e.nodeIndex,featureIndex:e.componentIndex}),r)),null):r:null}_getCacheKey(e){return`${this._layerUrl}/v30/${e}${this._cacheKeySuffix}`}get _meshUtilsImporter(){return this._meshUtilsImporterPromise||(this._meshUtilsImporterPromise=import(`./i3s/meshUtils.js`),this._meshUtilsImporterPromise.then(e=>this._meshUtilsImporterModule=e,()=>{})),this._meshUtilsImporterPromise}_getCacheKeySuffix(){let e=this.view.renderSpatialReference;return e==null?Kt:e===O(e)?qt:this.layer.spatialReference.equals(e)?Gt:e.wkid==null?null:`@${e.wkid}`}_getMemCacheKey(e,t=this.elevationOffset){return e+`#`+t}get _idbCacheEnabled(){return!this._controller.disableIDBCache&&!this.hasModifications&&this.elevationOffset===0&&this._cacheKeySuffix!=null}loadCachedGPUData(e){return this._memCache==null?null:this._memCache.pop(this._getMemCacheKey(e))}deleteCachedGPUData(e){e!=null&&this._deleteComponentObject(e)}_cacheGPUData(e,t=this.elevationOffset){if(this._memCache==null){this._deleteComponentObject(e);return}let n=this._controller.indexDepth-e.node.level;this._memCache.put(this._getMemCacheKey(e.node.index,t),e,n)}loadMissingTextures(e,t,n,r){let i=e?.filter((e,n)=>{if((e.usage&this.rendererTextureUsage)===0)return!1;if(t==null)return!0;let r=Ke(e.encodings,this.supportedTextureEncodings),i=t[n];return!!(i?.data==null||r&&i.encoding!==r.encoding)})??[];return i.length===0?Promise.resolve(!1):n(i,r).then(n=>{let r=0;for(let i=0;i<e.length;i++)r<n.length&&n[r].id===e[i].id&&(t[i]=n[r],r++);return!0})}loadCachedNodeData(e,t,n){return this._idbCacheEnabled?this._idbCache.get(this._getCacheKey(e.id),t).then(r=>r==null?null:(r.globalTrafo=_e(r.globalTrafo),r.nodeVersion===e.version?(this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=J.fromData(r.geometryObbData)),this.loadMissingTextures(r.requiredTextures,r.textureData,n,t).then(n=>(n&&this._idbCache.initialized&&r.textureData!=null&&(r.byteSize=zt(r.transformedGeometry,r.textureData),r.textureData.every(Rt)&&this._indexedDbSizeCheck(e,r)&&this._idbCache.put(this._getCacheKey(e.id),r).catch(t=>a.getLogger(this).warn(`Failed to update node with textures in IndexedDB cache: ${e.id}: ${t}`))),d(t),r))):(this._idbCache.remove(this._getCacheKey(e.id)),null))):Promise.resolve(null)}addNode(e,t,n){return Lt(t)?t.geometryBuffer==null?(this._addNodeMeta(e.index,null),Promise.resolve()):this._addData(e,t.attributeDataInfo,()=>this._transformNode(e,t,n).then(r=>this._safeReschedule(()=>{if(r==null)return e.hasModifications=!1,this._addCachedNodeData(e,null,n);let{obb:i,componentOffsets:o,featureIds:s,anchorIds:c,anchors:l,transformedGeometry:u,geometryMinElevation:d,geometryMaxElevation:f}=r;e.hasModifications=u.hasModifications;let p=_e(r.globalTrafo),m=x(Ht,i.center.x,i.center.y,i.center.z);S(m,m,p);let h=new J(m,[i.extents.x,i.extents.y,i.extents.z],se(i.orientation.x,i.orientation.y,i.orientation.z,i.orientation.w));this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=h),t.geometryData.componentOffsets=o,s&&(t.geometryData.featureIds=Array.from(s)),t.geometryData.anchorIds=c,t.geometryData.anchors=l;let g={nodeVersion:e.version,geometryData:t.geometryData,requiredTextures:t.requiredTextures,textureData:t.textureData,transformedGeometry:u,globalTrafo:p,geometryObbData:h.data,geometryMinElevation:d,geometryMaxElevation:f,byteSize:zt(u,t.textureData)};if(this._idbCacheEnabled&&this._idbCache.initialized&&this._indexedDbSizeCheck(e,g)){let t=g.textureData==null?null:g.textureData.map(e=>Rt(e)?e:null);this._idbCache.put(this._getCacheKey(e.id),{...g,textureData:t}).catch(t=>a.getLogger(this).warn(`Failed to store node in IndexedDB cache: ${e.id}: ${t}`))}return this._addCachedNodeData(e,g,n)},n))):Promise.reject()}getElevationRange(e){let t=new q,n=this._controller,{index:r}=n;if(!r)return t;let{rootNode:i}=r;if(!i)return t;let a=this._nodeId2Meta,o=n.viewportQueries;return r.traverse(i,n=>{let{childrenLoaded:r}=n;if(r===0)return!1;let i=o.getAndUpdateVisibilityObbInRenderSR(n),s=null;if(i){if(!i.intersectSphereWithMBS(e,i.radius))return!1}else if(s=o.calculateServiceMbsInRenderSRElevationAdjusted(n),s?.isValid&&!e.intersects(s))return!1;let c=a.get(n.index);if(c){let{geometryObbInRenderSR:r}=n;if(!r||r.intersectSphereWithMBS(e)){let e=c.geometryElevationRange;e.elevationRangeValid&&!e.isEmpty&&t.expandElevationRange(e)}}return r-+!!c>0}),t}computeVisibilityObb(e){return nt(e,this.view.renderSpatialReference,this._controller.crsIndex,this.layer.spatialReference,this.elevationOffset,this._modifications,this.view.renderCoordsHelper.sphericalPCPF)}_transformNode(e,t,n){let r=t.geometryData.geometries??[],i=Array(r.length);for(let e=0;e<r.length;++e)i[e]=this._getVertexBufferLayout(r[e],t.geometryDescriptor);let a=this.layer.normalReferenceFrame,o=t.normalReferenceFrame??a??`none`,s=e.serviceMbsInIndexSR,c=this.elevationOffset,l=this._controller.crsIndex,u=this._controller.crsVertex,d=this.view.renderSpatialReference,f=Ze(s,c,o,l,d),p=k(l,u),m=k(u,d);if(p==null||m==null)return Promise.resolve(null);let h={context:this.uid,geometryBuffer:t.geometryBuffer,geometryData:t.geometryData,geometryDescriptor:t.geometryDescriptor,layouts:i,globalTrafo:f,geometryElevationOffset:c,mbs:s.toJSON(),obbData:e.serviceObbInIndexSR?.data,elevationOffset:c,planetRadiusInGlobalMode:this._planetRadiusInGlobalMode,needNormals:this._controller.isMeshPyramid||this._imVertexNormals,computeNormals:this._isIntegratedMesh&&this._imVertexNormals,normalReferenceFrame:o,indexToVertexProjector:p,vertexToRenderProjector:m};return this._workerHandle.invoke(h,n)}get _supportsNodeCrossFading(){return!this.view?.stage?.renderer.shadowsEnabled}get nodeCrossfadingEnabled(){return this._supportsNodeCrossFading&&(this.lodCrossfadeinDuration>0||this.lodCrossfadeoutDuration>0||this.lodCrossfadeUncoveredDuration>0)}get nodeFadeoutEnabled(){return this._supportsNodeCrossFading&&this.lodCrossfadeoutDuration>0}_setNewNodeOpacity(e){let t=this.nodeCrossfadingEnabled?0:this.fullOpacity;this._setNodeOpacity(e,t)}addCachedGPUData(e,t,n){if(this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=this._collection.getComponentObb(t.objectHandle).clone()),!this._controller.isGeometryVisible(e)){this._cacheGPUData(t);return}let r=e.index;this._addNodeMeta(r,t),this.updateNodeState(r,n),this._collection.setObjectVisibility(t.objectHandle,!0),this._updateElevationOffsets(t),this._labeler!=null&&this._addMetaToLabeler(this._labeler,t),this._updateMaterial(t),this._setNewNodeOpacity(t),this.elevationInfo.mode!==0&&this._ensureElevationTask().schedule(r),this._updateEngineObject(t),this._highlights?.objectCreated(t),this._treeDebugger!=null&&this._treeDebugger.update()}addCachedNodeData(e,t,n,r){return this._addData(e,n,()=>this._addCachedNodeData(e,t,r))}async deleteCachedNodeData(e){if(this._idbCacheEnabled)return this._idbCache.remove(this._getCacheKey(e))}async _addCachedNodeData(e,t,n){if(!this.contentVisible||!this._controller.isGeometryVisible(e)){this._removeNodeStageData(e.index,this.elevationOffset,this._nodeId2MetaReloading);return}if(t==null){this._addNodeMeta(e.index,null);return}let r=this._addTasks.get(e.index),{geometryData:i,transformedGeometry:o}=t;await this.i3sOverrides.applyAttributeOverrides(i.featureIds,r.attributeInfo,n,this._controller.requiredAttributes);let s=t.textureData==null?[]:t.textureData.filter(e=>e!=null&&(e.usage&this.rendererTextureUsage)!==0);e.memory=0;let{componentOffsets:c,geometries:l,featureIds:u,anchorIds:d,anchors:f}=i,p=this._collection,m=l[0],{layout:h,indices:g,interleavedVertexData:_,positionData:v,hasColors:se}=o,{material:x,geometryParameters:S}=this._materialParameters(m,h),C=_.byteLength/h[0].stride,ue=c||new Uint32Array([0,g?g.length:C]),w=m.transformation?ae(m.transformation):oe(),E=_e(t.globalTrafo);re(w,E,w);let D=ie(T(),w),O=y(te(),w),pe=this._isIntegratedMesh?this._imShading?2:0:1,me=S.textureCoordinateType,k=!b(O,ne),j=new bt(h,pe,me,+!!k),he=new xt({interleavedVertexData:_,vertexCount:C,indexData:g},{positions:ve(v.data),indices:ye(v.indices)},ue,j),ge=this.view.renderSpatialReference,M=this.view.groundView.spatialReference,N=J.fromData(ht(t.geometryObbData)).getCenter(Xt),P=[1,1,1];fe(N,ge,P,M)||a.getLogger(this).errorOnce(`Unsupported coordinate system for IM overlay`);let F=T();A(N,ge,F,M);let I=te();ee(I,O);let L=T();ce(L,le(L,N,D),I);let be=F[0]-L[0]*P[0],xe=F[1]-L[1]*P[1],Se=S.textureCoordinateType===2,{textures:R,texturePromise:Ce,materialParameters:we}=this._initMaterialAndTextures(x,s,Se,e),z=p.createObject(new vt(de(be,xe,P[0],P[1]),new Ct(D,O),J.fromData(ht(t.geometryObbData)),he,has(`enable-feature:im-as-ground`)?!this.layer.isUsedAsGroundLayer:!this._isIntegratedMesh),we);e.memory+=this._memEstimateGeometryAdded(z),e.memory+=R.reduce((e,t)=>e+(t==null?0:this._memEstimateTextureAdded(t)),0);let B=!!x.hasParametersFromSource,Te=x.alphaMode!==`blend`&&x.metallicRoughness.baseColorFactor[3]>=1,V=new Ot(e,u,z,this._getInvalidRendererVersion(),r.attributeInfo,{hasParametersFromSource:B,isOpaque:Te},R,d,f,t.geometryMinElevation,t.geometryMaxElevation);r.meta=V,this._hasTextures||=t.requiredTextures?.some(({usage:e})=>!!(e&19))||!!e.resources.texture,this._hasData=!0,this._hasColors||=se,this.notifyChange(`hasTexturesOrVertexColors`);let Ee=this.slicePlaneEnabled;return Promise.all([this._addOrUpdateEdgeRendering(V),Ce]).then(([t,r])=>(this._addTasks.has(e.index)&&t?.updateObjectVisibility(V.objectHandle,!1).catch(e=>this._logEdgeViewError(e,this.layer.title)),this._safeReschedule(()=>{let n=this._addTasks.get(e.index);if(!n)return;if(this._addNodeMeta(e.index,V),n.meta=null,!this.contentVisible){this._removeNodeStageData(e.index,this.elevationOffset);return}p.setObjectVisibility(z,!0),t?.updateObjectVisibility(V.objectHandle,!0).catch(e=>this._logEdgeViewError(e,this.layer.title)),V.attributeInfo=n.attributeInfo;let r=V.cachedRendererVersion!==this._rendererVersion,i=Ee!==this.slicePlaneEnabled;this._updateElevationOffsets(V);let a=V.elevationOffsets;this._updateComponentData(V);let o=this._applyFiltersToNode(V);(r||t!=null&&(i||o||a))&&this._addOrUpdateEdgeRendering(V).catch(()=>{}),this._labeler!=null&&this._addMetaToLabeler(this._labeler,V),this._visibleGeometryChanged(V,0),this._highlights?.objectCreated(V),this._updateMaterial(V),this._setNewNodeOpacity(V),this._treeDebugger!=null&&this._treeDebugger.update()},n))).catch(e=>{let{meta:t,allowMemCache:n}=r;throw r.meta=null,t&&n?this._cacheGPUData(t):t&&this._deleteComponentObject(t),e})}_addNodeMeta(e,t){if(this._removeNodeStageData(e,this.elevationOffset,this._nodeId2MetaReloading),this._nodeId2Meta.has(e)){a.getLogger(this).error(`Removing duplicated node`);let t=this._nodeId2Meta.get(e);t&&(this._deleteComponentObject(t),this._updateFeatureIdCounts(t,-1))}else this._controller.updateLoadStatus(e,!0);t&&(t.lodCrossfadeProgress=null,this.nodeCrossfadingEnabled&&X(t.cachedEdgeMaterials,0),this._updateFeatureIdCounts(t,1)),this._nodeId2Meta.set(e,t),this.notifyChange(`elevationRange`)}_updateElevationOffsets(e){if(!e.node.serviceMbsInIndexSR)return;let{view:t,elevationInfo:n}=this,r=this._controller.crsIndex,{groundView:i,groundSpatialReference:a,renderSpatialReference:o}=t,s=n.mode;if(s===0){e.elevationAlignmentOffset=n.offset,e.elevationOffsets=null,e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`);return}if(e.elevationAlignmentOffset=0,o==null||a==null){e.elevationOffsets=null,e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`);return}let c=this._collection.getObjectTransform(e.objectHandle);e.elevationOffsets=e.elevationOffsets??[];let l=Ht,u=Ut,d=s===2,f=this.view.renderCoordsHelper,p=e.featureIds.length,m=(()=>{if(e.cachedElevationAnchors)return e.cachedElevationAnchors;let t=P(p*3);e.cachedElevationAnchors=t;let{center:n}=e.node.serviceMbsInIndexSR;for(let i=0;i<p;i++){let s=i*3,d=e.anchorIds?.indexOf(i)??-1;e.anchors&&d>=0?(x(l,e.anchors[d*3],e.anchors[d*3+1],e.anchors[d*3+2]),C(l,l,n),A(l,r,l,a),t[s]=l[0],t[s+1]=l[1],t[s+2]=f.getAltitude(l)):(this._collection.getComponentAabb(e.objectHandle,i,u,!0),x(l,(u[0]+u[3])/2,(u[1]+u[4])/2,u[2]),ce(l,l,c.rotationScale),C(l,l,c.position),t[s+2]=f.getAltitude(l),A(l,o,l,a),t[s]=l[0],t[s+1]=l[1])}return t})(),h=n.offset,g=e.elevationOffsets;i.getElevations(m,p,(e,t)=>{let n=d?m[e*3+2]:0;g[e]=h+(t??0)-n}),e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`)}_ensureElevationTask(){return this._elevationTask??=new ze(this.view.resourceController.scheduler,e=>this._controller.updateElevationChanged(e,this.view.groundView.spatialReference)?.filterInPlace(e=>this._nodeId2Meta.get(e)!=null),e=>this._nodeElevationAlignmentChanged(this._nodeId2Meta.get(e)),()=>this.elevationInfo?.mode),this._elevationTask}_elevationInfoChanged(e,t){let n=e.mode!==0,r=!!t&&t!==e&&t.mode!==0;this._intersectionHandler.updateElevationAlignState(n,this.view.state.viewingMode),n&&!r&&this._controller.removeAllGeometryObbs(),this._nodeId2Meta.forEach(e=>this._nodeElevationAlignmentChanged(e))}_nodeElevationAlignmentChanged(e){e!=null&&(this._updateElevationOffsets(e),this._updateComponentData(e),this._updateEdgeRendering(e),this._labeler!=null&&this._labeler.updateLabelPositions(e),this._updateSnappingSources(e,2),this._elevationProvider.notifyObjectChanged(this._collection.getComponentObb(e.objectHandle)))}_safeReschedule(e,t){return d(t),this._controller.reschedule(e,t)}_materialParameters(e,t){let n=e.params.material==null?qe():e.params.material,r=t.some(({name:e})=>e===`uvRegion`),i=t.some(({name:e})=>e===`normalCompressed`),a=It(n);return{geometryParameters:this._getGeometryParameters({hasTexture:a,hasNormals:i,hasRegions:r}),material:n}}_initMaterialAndTextures(e,t,n,r){let i=this._stage.renderView,a=e=>{this._gpuMemoryEstimate-=e,this._texMemoryEstimate-=e,r.memory-=e},o=t.map(t=>Je(t,e,n,i,this._compressionTracker,a));this._stage.addTextures(o);let{materialParameters:s,texturePromise:c}=Ye(e,o,t,this.view.stage.renderView.textures,{rendererTextureUsage:this.rendererTextureUsage,usePBR:this._usePBR,isIntegratedMesh:this._isIntegratedMesh,isGround:this.layer.isUsedAsGroundLayer,slicePlaneEnabled:this.slicePlaneEnabled,viewSpatialReference:this.view.spatialReference,applySSAO:this._applySSAO});return{textures:o,texturePromise:c,materialParameters:s}}_getGeometryParameters(e){return new St(this._hasVertexColors,e.hasNormals,e.hasTexture?e.hasRegions?2:1:0)}_addData(e,t,n){let r=this._addTasks.get(e.index);if(r)r.attributeInfo=t;else{let i=Promise.withResolvers();r=new Vt(t,null,i.promise),this._addTasks.set(e.index,r),n().then(i.resolve,i.reject).then(()=>this._addTasks.delete(e.index)).catch(t=>{throw this._addTasks.delete(e.index),t})}return r.promise}_clearAddTasks(){this._addTasks.forEach(e=>{e.meta!=null&&(this._cacheGPUData(e.meta),e.meta=null)}),this._addTasks.clear()}_clippingAreaChanged(){let e=this.view.renderSpatialReference,t=this.layer.spatialReference,n=M();this._renderClippingArea=mt(this.view.clippingArea,n,e)?n:null;let r=M();this._layerClippingArea=mt(this.view.clippingArea,r,t)?r:null,this._filterChange(),this._controller&&this._controller.updateClippingArea(this.view.clippingArea),this._isIntegratedMesh&&this._modificationsChanged()}get hasGeometryFilter(){return!1}_geometryFilterChange(){let e=this.hasGeometryFilter;this._controller.geometryFilterChanged(e),this._applyFilters(e),this._assertFeatureIdNodeCounts(e)}_assertFeatureIdNodeCounts(e){e&&!this._featureIdCounts?(this._featureIdCounts=$(this._nodeId2Meta.values()),this._filteredIdCounts=$(this._nodeId2Meta.values(),1),this._weaklyRemovedIdCounts=$(this._nodeId2Meta.values(),2),this.addHandles(p(()=>this._controller.updating,e=>{!e&&this._needFilterResolve&&(this.multiGeometryFilterResolve(),this._needFilterResolve=!1,this.notifyUpdate())},{sync:!0}),`updateFinished`)):!e&&this._featureIdCounts&&(this._featureIdCounts=null,this._filteredIdCounts=null,this._weaklyRemovedIdCounts=null,this._mismatchShow=null,this._mismatchHide=null,this.removeHandles(`updateFinished`),this._needFilterResolve=!1,this.notifyUpdate())}_updateFeatureIdCounts(e,t){this._featureIdCounts&&(this._needFilterResolve=!0,Q(this._featureIdCounts,e.featureIds,t),Q(this._filteredIdCounts,e.filteredIds,t),Q(this._weaklyRemovedIdCounts,e.weaklyRemovedIds,t))}_updateFilteredIdCounts(e,t,n){this._filteredIdCounts&&(this._needFilterResolve=!0,Q(this._filteredIdCounts,t,-1),Q(this._filteredIdCounts,e.filteredIds,1),Q(this._weaklyRemovedIdCounts,n,-1),Q(this._weaklyRemovedIdCounts,e.weaklyRemovedIds,1))}_checkFeatureIdNodeCountInvariant(){let e=this._featureIdCounts!=null;if(this.hasGeometryFilter!==e&&a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`LayerView should have feature id node counts if and only if it has a geometry filter`,{layerView:this,hasNodeCounts:e}),!this._featureIdCounts||!this._filteredIdCounts)return;let t=$(this._nodeId2Meta.values());o(this._featureIdCounts,t)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _featureIdCounts`,{layerView:this,counts:this._featureIdCounts,expected:t});let n=$(this._nodeId2Meta.values(),1);o(this._filteredIdCounts,n)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _filteredIdCounts`,{layerView:this,counts:this._filteredIdCounts,expected:n});let r=$(this._nodeId2Meta.values(),2);o(this._weaklyRemovedIdCounts,r)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _weaklyRemovedIdCounts`,{layerView:this,counts:this._weaklyRemovedIdCounts,expected:n})}multiGeometryFilterResolve(){if(!this._featureIdCounts||!this._filteredIdCounts)return;let e=null,t=null;for(let[n,r]of this._filteredIdCounts){let i=this._featureIdCounts.get(n);i!==r&&(r+(this._weaklyRemovedIdCounts?.get(n)??0)===i?(e??=new Set,e.add(n)):(t??=new Set,t.add(n)))}h(e,this._mismatchShow)&&h(t,this._mismatchHide)||(this._mismatchShow=e,this._mismatchHide=t,this._nodeId2Meta.forEach(e=>{if(!e?.filteredIds)return;let t=Yt(e,this._mismatchShow,this._mismatchHide);this._collection.setAllComponentVisibilities(e.objectHandle,t),this._visibleGeometryChanged(e,2)}))}_filterChange(){this._applyFilters(this.hasGeometryFilter)}_applyFilters(e){this._filters=this.getFilters(),e?this._controller&&this._controller.requestUpdate():this._nodeId2Meta.forEach(e=>{e&&this._applyFiltersToNode(e)&&(this._addOrUpdateEdgeRendering(e).catch(()=>{}),this._visibleGeometryChanged(e,2))})}getFilters(){let e=[],t=this._renderClippingArea;return t!=null&&e.push((e,n)=>this._boundingRectFilter(e,n,t)),e}addSqlFilter(e,t,n){if(t!=null){let r=t.fieldNames;e.push((e,i)=>this._sqlFilter(e,i,t,r,n))}}_sqlFilter(e,t,n,r,i){let a={},o=this._createLayerGraphic(a);if(!o)return;let s=this.layer.objectIdField,c=t.featureIds,l=t.attributeInfo?.attributeData;r.every(e=>e===s||l?.[e]!=null)&&rt(e,c,e=>{a[s]=c[e];for(let t of r)t!==s&&(a[t]=l?H(l[t],e):null);try{return n.testFeature(o)}catch(e){return i(e),!1}})}_boundingRectNodeTest(e,t){return pe(e.node.serviceMbsInIndexSR,this._controller.crsIndex,Ft,this.view.renderSpatialReference),it(t,Ft)}_boundingRectFeatureTest(e,t,n){return this._collection.getComponentAabb(e.objectHandle,t,At),ge(At,jt),N(n,jt)}_boundingRectFilter(e,t,n){let r=this._collection,i=this._boundingRectNodeTest(t,n);if(i===3)return;if(i===0){e.length=0;return}let a=r.getComponentCount(t.objectHandle);if(a.invisible+a.visible!==t.featureIds.length)return;let o=this._transformClippingArea(Mt,n,t.objectHandle);rt(e,t.featureIds,e=>this._boundingRectFeatureTest(t,e,o))}_transformClippingArea(e,t,n){let r=this._collection.getObjectTransform(n),i=r.position,a=r.rotationScale;return e[0]=(t[0]-i[0])/a[0],e[1]=(t[1]-i[1])/a[4],e[2]=(t[2]-i[0])/a[0],e[3]=(t[3]-i[1])/a[4],e}async _addOrUpdateEdgeRendering(e,t=!0){let n=e.objectHandle,{hasEdges:r,perFeatureEdgeMaterials:i}=this._getFilteredEdgeMaterials(e);if(r&&!this._edgeView)try{this._edgeView=await this._stage.renderer.loadEdgeView()}catch(e){if(!u(e))throw e}let a=this._edgeView;if(!a)return null;let o=a.hasObject(n);if(r){if(o)return this.nodeCrossfadingEnabled&&X(i,this.getNodeOpacity(e)),a.updateAllComponentMaterials(n,i,this.slicePlaneEnabled,t).catch(e=>this._logEdgeViewError(e,this.layer.title)),a.updateObjectVisibility(n,!0).catch(e=>this._logEdgeViewError(e,this.layer.title)),a.updateAllVerticalOffsets(n,e.elevationOffsets).catch(e=>this._logEdgeViewError(e,this.layer.title)),a;let r=await this._collection.addEdges(n,a,i,this.slicePlaneEnabled,e.elevationOffsets);return e.edgeMemoryUsage=r,e.node.memory+=r,a}return o&&(e.node.memory-=e.edgeMemoryUsage,e.edgeMemoryUsage=0,a.removeObject(n)),null}_applyFiltersToNode(e){let{filteredIds:t,weaklyRemovedIds:n}=e,r=this._applyFiltersToNodeComponents(e);return this._updateFilteredIdCounts(e,t,n),r&&this._labeler?.applyFilterChange(e),r}_applyFiltersToNodeComponents(e){let t=this._collection,n=t.getComponentCount(e.objectHandle),r=e.filteredIds!=null,i=n.invisible===0;if(t.setAllComponentVisibilities(e.objectHandle,`all`),this._filters.length===0)return e.filteredIds=null,!i;if((e.filteredIds==null||e.appliedFilters!==this._filters)&&(e.weaklyRemovedIds=null,e.filteredIds=Jt(e,this._filters),e.appliedFilters=this._filters),r&&e.filteredIds===e.featureIds&&(!this._mismatchHide||e.filteredIds.every(e=>!this._mismatchHide?.has(e))))return!i;let a=Yt(e,this._mismatchShow,this._mismatchHide);return t.setAllComponentVisibilities(e.objectHandle,a),!0}_removeAllNodeDataFromStage(e=this.elevationOffset){this._nodeId2Meta.forEach((t,n)=>this._removeNodeStageData(n,e)),this._nodeId2MetaReloading.forEach((t,n)=>this._removeNodeStageData(n,e,this._nodeId2MetaReloading)),this._elevationTask=s(this._elevationTask)}removeNode(e){let t=this.elevationOffset;this._removeNodeStageData(e,t),this._removeNodeStageData(e,t,this._nodeId2MetaReloading),this._elevationTask!=null&&this._elevationTask.remove(e)}_removeNodeStageData(e,t,n=this._nodeId2Meta){n.has(e)&&this._controller.updateLoadStatus(e,!1);let r=n.get(e);r==null?n.delete(e):(this._collection.setObjectVisibility(r.objectHandle,!1),this._edgeView!=null&&this._edgeView.hasObject(r.objectHandle)&&this._edgeView.updateObjectVisibility(r.objectHandle,!1).catch(e=>this._logEdgeViewError(e,this.layer.title)),this._visibleGeometryChanged(r,1),this._labeler!=null&&this._labeler.removeNodeMeta(r),n.delete(e),this._highlights?.objectDeleted(r),n===this._nodeId2Meta?(this._updateFeatureIdCounts(r,-1),this._cacheGPUData(r,t),this.nodeCrossfadingEnabled&&this._crossfadeHelper.stopNodeFading(r)):this._deleteComponentObject(r),this._treeDebugger!=null&&this._treeDebugger.update())}_deleteComponentObject(e){if(this._edgeView!=null&&this._edgeView.removeObject(e.objectHandle),this._memEstimateGeometryRemoved(e.objectHandle),this._collection.destroyObject(e.objectHandle),e.textures)for(let t of e.textures)this._memEstimateTextureRemoved(t),this._stage.removeTexture(t)}updateNodeState(e,t){this._nodeId2Meta.get(e)?.objectHandle.updateMaterial({polygonOffset:+(t===0)})}updateNodeIndex(e,t){if(this._nodeId2Meta.has(e)){let n=this._nodeId2Meta.get(e);this._nodeId2Meta.delete(e),this._nodeId2Meta.set(t,n),this.notifyChange(`elevationRange`)}let n=this._nodeId2MetaReloading.get(e);n&&(this._nodeId2MetaReloading.delete(e),this._nodeId2MetaReloading.set(t,n))}_invalidateAllSymbols(){this._rendererVersion=U(this._rendererVersion,1),this._controller?.requestUpdate()}_getInvalidRendererVersion(){return U(this._rendererVersion,-1)}async _rendererChange(e){if(this._currentRenderer=e,this.notifyChange(`rendererTextureUsage`),this._rendererVersion=U(this._rendererVersion,1),this._rendererFields=null,this._colorVariable=null,this._opacityVariable=null,this._invalidateAllSymbols(),e&&(this._rendererFields=await e.getRequiredFields(this.layer.fieldsIndex)),this._updateSymbologyFields(),!this._arcade&&e&&`arcadeRequired`in e&&e.arcadeRequired&&(this._arcade=await Te()),e&&`visualVariables`in e&&e.visualVariables)for(let t of e.visualVariables)t.type===`color`?this._colorVariable=t:t.type===`opacity`?this._opacityVariable=t:a.getLogger(this).warn(`Unsupported visual variable type for 3D Object Scene Services: ${t.type}`);if(e)for(let t of e.symbols)t.type!==`mesh-3d`&&a.getLogger(this).error(`Symbols of type '${t.type}' are not supported for 3D Object Scene Services.`);this._controller&&this._controller.requestUpdate()}_getCachedEdgeMaterials(e){return this._hasComponentData&&e.cachedRendererVersion!==this._rendererVersion&&this._updateCachedRendererData(e),e.cachedEdgeMaterials}_getComponentParameters(e){this._hasComponentData&&e.cachedRendererVersion!==this._rendererVersion&&this._updateCachedRendererData(e);let t=e.cachedSymbology;return(n,r)=>{let i=n*e.cachedSymbologyStride;E(r.externalColor,t[i]/255,t[i+1]/255,t[i+2]/255,t[i+3]/255);let a=this._stage.renderView.olidRenderHelper;if(a){let t=e.featureIds[n],i=this.sublayerId?`${this.layerViewUid}_${this.sublayerId}`:this.layerViewUid,o=z(this.view,this.uid);a.setUidToObjectAndLayerId(t,t,this.layerId,i,this.layerPopupEnabledAndHasTemplate&&!o,e.node.resources.attributes,n,this.sublayerId),r.olidColor=a.getObjectAndLayerIdColor({graphicUid:t,layerViewUid:i})}r.externalColorMixMode=t[i+4]&15,r.castShadows=!!(t[i+4]&16),r.pickable=!!(t[i+4]&32),r.elevationOffset=e.elevationOffsets?.[n]??0,r.emissiveStrength=e.emissiveStrengths?.[n]??1,r.emissiveSource=e.emissiveSources?.[n]??0}}_getSymbolInfo(e,t){let n=e?.getSymbol(t,{arcade:this._arcade});if(!(n instanceof V))return null;let r=n.id;if(this._symbolInfos.has(r))return this._symbolInfos.get(r);let i=at(n);return this._symbolInfos.set(r,i),i}_setSymbologyOverride(e,t){this._symbologyOverride!==e&&(this._symbologyOverride=e,this._symbologyOverrideFields=t,this._invalidateAllSymbols(),this._updateSymbologyFields())}_updateSymbologyFields(){this._symbologyFields=this._symbologyOverrideFields!=null&&this._symbologyOverrideFields.length>0?this._rendererFields!=null&&this._rendererFields.length>0?xe(this.layer.fieldsIndex,[...this._rendererFields,...this._symbologyOverrideFields]):this._symbologyOverrideFields:this._rendererFields}_updateCachedRendererData(e){if(e.cachedRendererVersion=this._rendererVersion,!this._hasComponentData)return;let t=this._tmpAttributeOnlyGraphic,n={};t.attributes=n;let r=this._currentRenderer,i=e.attributeInfo?.attributeData,a=e.featureIds?this.layer.objectIdField:null,o=i!=null&&this._symbologyFields!=null&&this._symbologyFields.length>0,s=null,c=null;if(o&&this._symbologyFields!=null){s=[],c=[];for(let e of this._symbologyFields){let t=i[e];t&&(s.push(e),c.push(t))}}e.cachedSymbology||=I(e.featureIds.length*e.cachedSymbologyStride);let l=new ut,u=this.fullOpacity,d=this.nodeCrossfadingEnabled?this.getNodeOpacity(e):u,f=null,p=1,m=W,h=0;for(let i=0;i<e.featureIds.length;i++){if(a!=null&&(n[a]=e.featureIds[i]),o&&s)for(let e=0;e<s.length;e++)n[s[e]]=H(c[e],i);let u=r?this._getSymbolInfo(r,t):null,g,_;if(l.pickable=!0,r&&`visualVariables`in r){if(this._colorVariable){let e=Ce(this._colorVariable,t,{color:Pt,arcade:this._arcade});e&&(g=l.color,g[0]=e.r/255,g[1]=e.g/255,g[2]=e.b/255,g[3]=e.a??1,!this._opacityVariable&&e.a!==null&&(_=e.a))}this._opacityVariable&&(_=we(this._opacityVariable,t,{arcade:this._arcade}))}if(u?.material){let e=u.material;g=g==null||_==null?Ie(g,_,e.color,e.alpha,Dt,l.color):Ie(g,_,null,null,Dt,l.color)}g??=E(l.color,1,1,1,1);let v=u?.material;if(l.colorMixMode=v?.colorMixMode??1,l.edgeMaterial=u?.edgeMaterial,this._symbologyOverride?.(t,l),this._nodeColorOverride!=null&&(this._nodeColorOverride(e.node,g),l.colorMixMode=3),l.pickable&&=g[3]>=Et,l.castShadows=u?u.castShadows:l.pickable,l.edgeMaterial!=null){let t=g[3]>=1&&(e.material.isOpaque||l.colorMixMode===3)?1:0;(l.edgeMaterial!==f||t!==p)&&(m={...l.edgeMaterial,opacity:d,objectTransparency:t},f=l.edgeMaterial,p=t),e.cachedEdgeMaterials[i]=m}else e.cachedEdgeMaterials[i]=W;e.cachedSymbology[h++]=Math.round(g[0]*255),e.cachedSymbology[h++]=Math.round(g[1]*255),e.cachedSymbology[h++]=Math.round(g[2]*255),e.cachedSymbology[h++]=Math.round(g[3]*255),e.cachedSymbology[h++]=l.colorMixMode|l.castShadows<<4|l.pickable<<5;let y=v?.emissive?.strength==null?Y:v?.emissive?.strength;y!==Y&&!e.emissiveStrengths&&(e.emissiveStrengths=Array(e.featureIds.length).fill(Y)),e.emissiveStrengths&&(e.emissiveStrengths[i]=y);let b=v?.emissive?.source||0;b!==0&&!e.emissiveSources&&(e.emissiveSources=Array(e.featureIds.length).fill(0)),e.emissiveSources&&(e.emissiveSources[i]=b)}}_getFilteredEdgeMaterials(e){let t=this._getCachedEdgeMaterials(e);this.nodeCrossfadingEnabled||X(t,this.fullOpacity);let n=e.filteredIds;if(n==null)return{hasEdges:t.some(e=>e!==W),perFeatureEdgeMaterials:t};let r=0,i=!1,a=t.map((t,a)=>e.featureIds[a]===n[r]?(i||=t!==W,r++,t):W);return{hasEdges:i,perFeatureEdgeMaterials:a}}_updateComponentData(e){if(!this._hasComponentData)return;let{objectHandle:t}=e,n=this._getComponentParameters(e);this._collection.setComponentData(t,n),this._stage.renderView.requestRender()}_reloadAll(e=this.elevationOffset){this._removeAllNodeDataFromStage(e),this._controller!=null&&this._controller.restartNodeLoading()}_refreshGroundUsage(){this._intersectionHandler.isGround=has(`enable-feature:im-as-ground`)?this.layer.isUsedAsGroundLayer:this._isIntegratedMesh,this.contentVisible&&(this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(this._elevationContext,this._elevationProvider)),this._reloadAll(),this.clearMemCache()}_opacityChange(e){this.nodeCrossfadingEnabled&&this._crossfadeHelper.stopAllNodeFading(),this._nodeId2Meta.forEach(t=>{t!=null&&(this._collection.updateObjectOpacity(t.objectHandle,e),X(t.cachedEdgeMaterials,e),this._updateEdgeRendering(t))})}_updateMaterial(e){e.objectHandle.updateMaterial({slicePlaneEnabled:this.slicePlaneEnabled,usePBR:this._usePBR})}_updateEngineObject(e){this._updateComponentData(e),this._applyFiltersToNode(e),this._addOrUpdateEdgeRendering(e).catch(()=>{}),this._visibleGeometryChanged(e,2)}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e),this._labeler!=null&&(this._labeler.slicePlaneEnabled=e),this._foreachMeta(t=>{t.objectHandle.updateMaterial({slicePlaneEnabled:e}),this._updateEdgeRendering(t,!1)})}_updatePBR(e){this._foreachMeta(t=>t.objectHandle.updateMaterial({usePBR:e})),this._hasLoadedPBRTextures=!0}_foreachMeta(e){this._nodeId2Meta.forEach(t=>{t!=null&&e(t)})}get _usePBR(){return this._imShading&&this.view.qualitySettings.physicallyBasedRenderingEnabled}_updateEdgeRendering(e,t=!0){this._edgeView!=null&&this._edgeView.hasObject(e.objectHandle)&&this._addOrUpdateEdgeRendering(e,t).catch(()=>{})}_forAllNodes(e){this._nodeId2Meta.forEach(e)}_ignoreClientNodeOverriddenFeatures(e){return this.i3sOverrides.hasGeometryChanges?(t,n,r)=>r.node.index>=0&&this.i3sOverrides.featureHasGeometryChanges(t)?0:e(t,n,r):e}_forAllFeatures(e,t,n){for(let r of this._nodeId2Meta.values())if(r!=null&&!(t&&r.node.serviceMbsInIndexSR&&t(r.node.serviceMbsInIndexSR)===1))switch(n){case 1:this._forAllFeaturesOfNode(r,e);break;case 0:this._forAllVisibleFeaturesOfNode(r,e);break;case 2:this._forAllQueryableFeaturesOfNode(r,e)}}_forAllFeaturesOfNode(e,t){e.featureIds.forEach((n,r)=>t(n,r,e))}_forAllVisibleFeaturesOfNode(e,t){let n=e.featureIds;this._collection.forEachVisibleComponent(e.objectHandle,r=>t(n[r],r,e)===0)}_forAllQueryableFeaturesOfNode(e,t){let n=this._ignoreClientNodeOverriddenFeatures(t);if(this._renderClippingArea==null)return this._forAllFeaturesOfNode(e,n);let r=this._boundingRectNodeTest(e,this._renderClippingArea);if(r===0)return;if(r===3)return this._forAllFeaturesOfNode(e,n);let i=e.featureIds,a=e.objectHandle,o=ot(this._renderClippingArea,this._collection.getObjectTransform(a));for(let t=0;t<i.length;t++)this._boundingRectFeatureTest(e,t,o)&&n(i[t],t,e)}_createAttributes(e,t){let n={};t.featureIds!=null&&(n[this._getObjectIdField()]=t.featureIds[e]);let r=t.attributeInfo?.attributeData;if(r!=null)for(let t of Object.keys(r))n[t]=H(r[t],e);return n}_createGraphic(e,t){return this._createLayerGraphic(this._createAttributes(e,t))}highlight(e,t){let r=dt(e);if(r.length===0)return ft;let i=wt(t),a=r[0]instanceof n?this._featureIdsFromGraphics(r):typeof r[0]==`number`?r:null;if(!a)return ft;let o=this._ensureHighlights(),{set:s,handle:c}=o.acquireSet(i);return o.setFeatureIds(s,a),c}_featureIdsFromGraphics(e){let t=this.layer.fieldsIndex,n=this._getObjectIdField();return e.map(e=>G(t,e.attributes,n))}_ensureHighlights(){return this._highlights??=new Re({collection:this._collection,forAllFeatures:e=>this._forAllFeatures(e,null,1),forAllFeaturesOfNode:(e,t)=>this._forAllFeaturesOfNode(e,t)}),this._highlights}resetHighlights(){this._highlights=s(this._highlights)}_visibleGeometryChanged(e,t){this._elevationProvider&&(this._visibleGeometryChangedSchedulerHandle??=m(()=>{let{node:t}=e,n=t.visibilityObbInRenderSR??t.geometryObbInRenderSR??t.serviceObbInRenderSR;if(n!=null){let e=j();n.toAaBoundingBox(e),this.emit(`visible-geometry-changed`,new De(e))}else this.emit(`visible-geometry-changed`);this._visibleGeometryChangedSchedulerHandle=null}),this._updateSnappingSources(e,t),this._elevationProvider.notifyObjectChanged(this._collection.getComponentObb(e.objectHandle)))}get performanceInfo(){return new ke(this.usedMemory,this._nodeId2Meta.size,Math.round(this._gpuMemoryEstimate/1048576),Math.round(this._geoMemoryEstimate/1048576),Math.round(this._texMemoryEstimate/1048576),Math.round(this.unloadedMemory/1048576),this._idbCacheEnabled?Math.round(this._idbCache.getHitRate()*100):0)}checkInvariants(){}get test(){}getNodeOpacityByIndex(e){let t=this._nodeId2Meta.get(e);return this.getNodeOpacity(t)}getNodeOpacity(e){return e==null?0:this._collection.getObjectOpacity(e.objectHandle)}isNodeFullyFadedIn(e){return this._crossfadeHelper.isNodeFullyFadedIn(e)}getNodeCrossfadeMetaData(e){return this._nodeId2Meta.get(e)}getNodeComponentHandle(e){return this._nodeId2Meta.get(e)?.objectHandle}markNodeToRemove(e){this._controller&&this._controller.markNodeToRemove(e)}removeMarkedNodes(){this._controller&&this._controller.removeMarkedNodes()}foreachCrossfadeNode(e){this._nodeId2Meta.forEach(e)}fadeNode(e,t,n){if(!this.nodeCrossfadingEnabled)return;let r=this._nodeId2Meta.get(e);r!=null&&this._crossfadeHelper.fadeNode(e,r,t,n)}setNodeOpacityByIndex(e,t){let n=this._nodeId2Meta.get(e);n!=null&&this._setNodeOpacity(n,t)}_setNodeOpacity(e,t){this._collection.updateObjectOpacity(e.objectHandle,t),this._setNodeEdgeOpacity(e,t)}_setNodeEdgeOpacity(e,t){if(this._edgeView==null||!e.cachedEdgeMaterials)return;X(e.cachedEdgeMaterials,t);let n=e.objectHandle;this._edgeView.hasObject(n)&&this._edgeView.updateAllComponentOpacities(n,t).catch(e=>this._logEdgeViewError(e,this.layer.title))}get hasModifications(){return this._isIntegratedMesh&&this._layerClippingArea!=null||this._modifications&&this._modifications.length>0}updateNodeModificationStatus(e){let t=e.length;if(!this.hasModifications||t<=0||this._i3sWasmLoaded!==!0)return;let n=this.uid,r=Bt(e);if(r){let t={context:n,buffer:r.buffer};Me(t);let i=new Float64Array(r.buffer);e.forAll((e,t)=>{let n=i[t],r=Ne(n);e.imModificationImpact=r,r!==0&&this._controller.invalidateGeometryVisibility(e.index)})}}notifyUpdate(){this.notifyChange(`updating`)}notifyLODUpdate(){this._controller.notifyLODUpdate()}isUpdating(){return!!(this._controller&&this._controller.updating)||!!this._visibleGeometryChangedSchedulerHandle||this._labeler!=null&&this._labeler.updating||this._crossfadeHelper?.updating||this._i3sWasmLoaded instanceof Promise||this._asyncModuleLoading>0||this._elevationTask!=null&&this._elevationTask.readyToRun||this._needFilterResolve||this._compressionTracker.compressing}trackSnappingSources(e){let t={events:e,fetchEdgeLocations:async(e,t,n)=>{let r=this._nodeId2Meta.get(e);if(r==null)throw Error(`invalid-node`);let{origin:i,buffer:a}=await this._collection.extractEdgeInformation(r.objectHandle,t,n);return this._snappingLocationsApplyElevation(r,a,i),{type:`components`,objectIds:r.featureIds,locations:a,origin:i}},remove:()=>r(this._snappingSourcesTrackers,t)};return this._snappingSourcesTrackers.push(t),this._nodeId2Meta.forEach((t,n)=>{if(t==null)return;let r=this._controller.getRenderMbs(t.node);r&&e.add(n,r)}),t}_snappingLocationsApplyElevation(e,t,n){if(!e.elevationOffsets||this.elevationInfo.mode===0)return;let r=t.position0,i=t.position1,a=t.componentIndex,o=T(),s=T(),c=(e,t)=>{C(e,e,n),this.view.renderCoordsHelper.worldUpAtPosition(e,s),C(e,e,ue(s,s,t)),w(e,e,n)};for(let t=0;t<r.count;t++){let n=e.elevationOffsets[a.get(t)];r.getVec(t,o),c(o,n),r.setVec(t,o),i.getVec(t,o),c(o,n),i.setVec(t,o)}}_updateSnappingSources(e,t){let{index:n}=e.node,r=this._controller.getRenderMbs(e.node);if(r!=null)for(let e of this._snappingSourcesTrackers)(t===1||t===2)&&e.events.remove(n),(t===0||t===2)&&e.events.add(n,r)}_logEdgeViewError(e,t){u(e)||a.getLogger(this).warn(`Error while processing edges. Edges on this layer might not display correctly`,t,e)}_indexedDbSizeCheck(e,t){return t.byteSize>104857600?(a.getLogger(this).warn(`Node is too big to store in IndexedDB cache: ${e.id} (${t.byteSize} bytes)`),!1):t.byteSize>0}get elevationProvider(){return this._elevationProvider}};return e([_()],F.prototype,`extractChanges`,null),e([_()],F.prototype,`_hasLoadedPBRTextures`,void 0),e([_()],F.prototype,`_asyncModuleLoading`,void 0),e([_()],F.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([_()],F.prototype,`view`,void 0),e([_()],F.prototype,`layer`,void 0),e([_()],F.prototype,`_controller`,void 0),e([_()],F.prototype,`_labeler`,void 0),e([_()],F.prototype,`updating`,void 0),e([_()],F.prototype,`suspended`,void 0),e([_()],F.prototype,`contentVisible`,null),e([_({readOnly:!0})],F.prototype,`legendEnabled`,null),e([_(gt)],F.prototype,`updatingProgress`,void 0),e([_()],F.prototype,`updatingProgressValue`,null),e([_()],F.prototype,`hasTexturesOrVertexColors`,null),e([_()],F.prototype,`rendererTextureUsage`,null),e([_()],F.prototype,`elevationOffset`,null),e([_()],F.prototype,`elevationInfo`,null),e([_({type:Boolean})],F.prototype,`slicePlaneEnabled`,void 0),e([_()],F.prototype,`supportedTextureEncodings`,null),e([_({type:[R]})],F.prototype,`_modifications`,void 0),e([_({readOnly:!0})],F.prototype,`clientGeometry`,null),e([_()],F.prototype,`elevationRange`,null),e([_()],F.prototype,`fullExtent`,null),e([_()],F.prototype,`_elevationTask`,void 0),e([_({readOnly:!0})],F.prototype,`_usePBR`,null),F=e([v(`esri.views.3d.layers.I3SMeshView3D`)],F),F},At=j(),jt=M(),Mt=M(),Nt=new J,Pt=new t([0,0,0,0]),Ft=new F(0,0,0,0);function It(e){if(e==null)return!1;let t=e.metallicRoughness;return t&&t.baseColorTextureId>=0||t&&t.metallicRoughnessTextureId>=0||e.normalTextureId>=0||e.emissiveTextureId>=0||e.occlusionTextureId>=0}function Lt(e){return`geometryData`in e}function Rt(e){return e!=null&&g(e.data)}function zt(e,t){let n=1024+e.interleavedVertexData.byteLength+(e.indices?e.indices.byteLength:0)+e.positionData.data.byteLength+e.positionData.indices.byteLength;if(t!=null)for(let e of t)e!=null&&g(e.data)&&(n+=e.data.byteLength);return n}function Bt(e){if(e.length===0)return;let t=e.length*10,n=new Float64Array(t),r=0;return e.forAll(e=>{let t=e.serviceObbInIndexSR;t??(t=Nt,e.serviceMbsInIndexSR?(t.setCenter(e.serviceMbsInIndexSR.center),t.setHalfSizeFromValues(e.serviceMbsInIndexSR.radius,e.serviceMbsInIndexSR.radius,e.serviceMbsInIndexSR.radius)):t.invalidate());let i=t.data;n[r++]=i[0],n[r++]=i[1],n[r++]=i[2],n[r++]=i[3],n[r++]=i[4],n[r++]=i[5],n[r++]=i[6],n[r++]=i[7],n[r++]=i[8],n[r++]=i[9]}),n}class Vt{constructor(e,t,n){this.attributeInfo=e,this.meta=t,this.promise=n,this.allowMemCache=!0}}function X(e,t){e.forEach(e=>e.opacity=t)}class Z{constructor(e,t){this.mode=e,this.offset=t}}const Ht=T(),Ut=j(),Wt=`elevation-change`,Gt=``,Kt=`@null`,qt=`@ECEF`;function Jt(e,t){let n=e.featureIds.slice();for(let r of t)if(r(n,e),n.length===0)break;return n.length===e.featureIds.length?e.featureIds:n}function Yt(e,t,n){let r=[],i=e.filteredIds;if(i!=null&&!t?.size&&!n?.size)e.featureIds.forEach((e,t)=>{i[r.length]===e&&r.push(t)});else if(i!=null){let a=0;e.featureIds.forEach((e,o)=>{if(i[a]===e)++a;else if(!t?.has(e))return;n?.has(e)||r.push(o)})}return r}function Q(e,t,n){if(e&&t)for(let r of t){let t=(e.get(r)??0)+n;t>0?e.set(r,t):e.delete(r)}}function $(e,t=0){let n=new Map;for(let r of e)Q(n,t===0?r?.featureIds:t===1?r?.filteredIds:r?.weaklyRemovedIds,1);return n}const Xt=T();export{kt as I3SMeshView3D};
|
|
2
|
+
import{__decorate as e}from"tslib";import t from"../../../Color.js";import n from"../../../Graphic.js";import{removeUnordered as r,isSome as i}from"../../../core/arrayUtils.js";import has from"../../../core/has.js";import a from"../../../core/Logger.js";import{equals as o}from"../../../core/MapUtils.js";import{destroyMaybe as s}from"../../../core/maybe.js";import c from"../../../core/PooledArray.js";import{ignoreAbortErrors as l,isAbortError as u,throwIfAborted as d}from"../../../core/promiseUtils.js";import{initial as f,watch as p}from"../../../core/reactiveUtils.js";import{schedule as m}from"../../../core/scheduling.js";import{equals as h}from"../../../core/SetUtils.js";import{isArrayBuffer as g}from"../../../core/typedArrayUtil.js";import{property as _,subclass as v}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as y,exactEquals as ee,invert as te}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as ne,IDENTITY as re}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{multiply as ie,getTranslation as ae}from"../../../core/libs/gl-matrix-2/math/mat4.js";import{clone as oe,create as se}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as ce}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{set as b,transformMat4 as x,transformMat3 as le,sub as ue,add as S,scale as de,subtract as C}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{set as T}from"../../../core/libs/gl-matrix-2/math/vec4.js";import{fromValues as fe}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{UpdatingHandles as E}from"../../../core/support/UpdatingHandles.js";import{getSphericalPCPF as D}from"../../../geometry/spatialReferenceEllipsoidUtils.js";import{localLinearScaleFactors as pe}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectBoundingSphere as me}from"../../../geometry/projection/projectBoundingSphere.js";import{projectBuffer as he}from"../../../geometry/projection/projectBuffer.js";import{getProjectorName as O}from"../../../geometry/projection/projectors.js";import{projectVectorToVector as k}from"../../../geometry/projection/projectVectorToVector.js";import{create as A,fromBuffer as ge,toRect as j}from"../../../geometry/support/aaBoundingBox.js";import{create as M,intersects as N}from"../../../geometry/support/aaBoundingRect.js";import{newDoubleArray as P,ensurePackedMat4f64 as _e}from"../../../geometry/support/DoubleArray.js";import{compactFloatArray as ve}from"../../../geometry/support/FloatArray.js";import{compactIndices as ye}from"../../../geometry/support/Indices.js";import{Sphere as F}from"../../../geometry/support/sphere.js";import{newUByteArray as I}from"../../../geometry/support/UByteArray.js";import{fallbackObjectIDAttribute as L}from"../../../layers/LayerConstants.js";import be from"../../../layers/graphics/controllers/I3SOnDemandController.js";import{fixFields as xe}from"../../../layers/support/fieldUtils.js";import{I3SExtractChanges as Se}from"../../../layers/support/I3SExtractChanges.js";import R from"../../../layers/support/SceneModification.js";import{getColor as Ce,getOpacity as we}from"../../../renderers/visualVariables/support/visualVariableUtils.js";import{isBasemapLayerView as z}from"../../../support/basemapUtils.js";import{getElevationOffset as B}from"../../../support/elevationInfoUtils.js";import{loadArcade as Te}from"../../../support/loadArcade.js";import V from"../../../symbols/MeshSymbol3D.js";import Ee from"../../../symbols/SimpleFillSymbol.js";import{ContentGeometryUpdateEvent as De}from"./ContentGeometryLayerView.js";import Oe from"./I3SMeshViewLabeler.js";import{I3SMeshViewPerformanceInfo as ke}from"./I3SMeshViewPerformanceInfo.js";import{initialize as Ae,setModificationsSync as je,filterObbsForModificationsSync as Me,interpretObbModificationResults as Ne}from"./SceneLayerWorker.js";import{SceneLayerWorkerHandle as Pe,toWasmModification as Fe}from"./SceneLayerWorkerHandle.js";import{overrideColor as Ie}from"./graphics/graphicUtils.js";import{areLabelsVisible as Le}from"./graphics/Labeler.js";import Re from"./i3s/Highlights.js";import{I3SAsyncElevationUpdater as ze}from"./i3s/I3SAsyncElevationUpdater.js";import{getCachedAttributeValue as H}from"./i3s/I3SBinaryReader.js";import{I3SCrossfadeHelper as Be,NodeCrossfadeMetaData as Ve}from"./i3s/I3SCrossfadeHelper.js";import{boundingBoxCornerPoints as He}from"./i3s/I3SGeometryUtil.js";import{I3SIntersectionHandler as Ue,TraversedIntersectionNode as We}from"./i3s/I3SIntersectionHandler.js";import{getSupportedEncodings as Ge,selectEncoding as Ke,defaultMaterial as qe,createTexture as Je,configureMaterial as Ye}from"./i3s/I3SMaterialUtil.js";import{I3SOverrides as Xe}from"./i3s/I3SOverrides.js";import{computeGlobalTransformation as Ze}from"./i3s/I3SProjectionUtil.js";import{rendererNeedsTextures as Qe,checkSceneLayerValid as $e,checkSceneLayerCompatibleWithView as et,whenGraphicAttributes as tt,computeVisibilityObb as nt,filterInPlace as rt,intersectBoundingRectWithMbs as it,addWraparound as U,getSymbolInfo as at,transparentEdgeMaterial as W,getClipRect as ot}from"./i3s/I3SUtil.js";import{IDBCache as st}from"./i3s/IDBCache.js";import{IDBMockCache as ct}from"./i3s/IDBMockCache.js";import{LayerElevationProvider as lt}from"./i3s/LayerElevationProvider.js";import{SymbologyInfo as ut}from"./i3s/SymbologyInfo.js";import{attributeLookup as G}from"./support/attributeUtils.js";import{normalizeHighlightTarget as dt,emptyHighlightHandle as ft}from"./support/highlightUtils.js";import{makeScheduleFunction as pt}from"./support/makeScheduleFunction.js";import{debugFlags as K}from"../support/debugFlags.js";import{ElevationRange as q}from"../support/ElevationRange.js";import{toBoundingRect as mt}from"../support/extentUtils.js";import{Obb as J,ensurePackedObbData as ht}from"../support/orientedBoundingBox.js";import{updatingProgress as gt}from"../support/updatingProperties.js";import{glLayout as _t}from"../support/buffer/glUtil.js";import{ObjectParameters as vt}from"../webgl-engine/collections/Component/ObjectParameters.js";import{createVertexBufferLayout as yt,ComponentGeometryParameters as bt,SourceGeometry as xt,VertexBufferLayoutCreationParameters as St}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as Ct}from"../webgl-engine/collections/Component/Transform.js";import{emissiveStrengthDefault as Y}from"../webgl-engine/core/shaderLibrary/output/getEmissions.glsl.js";import{getHighlightName as wt}from"../../support/highlightOptionsUtils.js";import{TextureCompressionTracker as Tt}from"../../support/TextureCompressionTracker.js";import{alphaCutoff as Et}from"../../../webscene/support/AlphaCutoff.js";const Dt=[1,1,1,1];class Ot extends Ve{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this.node=e,this.featureIds=t,this.objectHandle=n,this.cachedRendererVersion=r,this.attributeInfo=i,this.material=a,this.textures=o,this.anchorIds=s,this.anchors=c,this._elevationAlignmentRange=new q,this._geometryElevationRange=new q,this.cachedElevationAnchors=null,this.cachedEdgeMaterials=[],this.edgeMemoryUsage=0,this.cachedSymbologyStride=5,this.elevationAlignmentOffset=0,this._baseGeometryElevationRange=new q(l,u),this.updateGeometryElevationRange()}get geometryElevationRange(){return this._geometryElevationRange}updateGeometryElevationRange(){let e=this._baseGeometryElevationRange;if(!e.elevationRangeValid||e.isEmpty){this._elevationAlignmentRange.invalidateElevationRange(),this._geometryElevationRange.invalidateElevationRange();return}let t=this.elevationOffsets;if(!t||t.length===0){let t=this.elevationAlignmentOffset;this._elevationAlignmentRange.setElevationRangeValues(t,t),this._geometryElevationRange.setElevationRangeValues(e.minElevation+t,e.maxElevation+t);return}let n=1/0,r=-1/0;for(let e=0;e<t.length;++e){let i=this.elevationAlignmentOffset+(t[e]??0);n=Math.min(n,i),r=Math.max(r,i)}this._elevationAlignmentRange.setElevationRangeValues(n,r),this._geometryElevationRange.setElevationRangeValues(e.minElevation+n,e.maxElevation+r)}get usedMemory(){return this.node.memory}get featureExtents(){return this._featureExtents??=new Float64Array(6*this.featureIds.length).fill(1/0),this._featureExtents}}const kt=t=>{let g=t,F=class extends g{constructor(){super(...arguments),this._extractChanges=null,this._applySSAO=!0,this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._updatingHandles=new E,this._highlights=null,this._nodeId2Meta=new Map,this._nodeId2MetaReloading=new Map,this._i3sWasmLoaded=!1,this._snappingSourcesTrackers=[],this._compressionTracker=new Tt,this._hasLoadedPBRTextures=!1,this._asyncModuleLoading=0,this._addTasks=new Map,this._currentRenderer=null,this._rendererVersion=0,this._colorVariable=null,this._opacityVariable=null,this._rendererFields=null,this._symbologyFields=null,this._symbologyOverride=null,this._symbologyOverrideFields=null,this._symbolInfos=new Map,this._visibleGeometryChangedSchedulerHandle=null,this._hasComponentData=!1,this._hasVertexColors=!1,this._nodeColorOverride=null,this.updating=!0,this.holeFilling=`auto`,this._hasColors=!1,this._hasTextures=!1,this._hasData=!1,this.slicePlaneEnabled=!1,this._modifications=[],this.ignoresMemoryFactor=!1,this._layerUrl=``,this._cacheKeySuffix=null,this._meshUtilsImporterModule=null,this._meshUtilsImporterPromise=null,this._planetRadiusInGlobalMode=0,this._elevationTask=null,this._needFilterResolve=!1,this._filters=[],this._arcade=null,this._tmpAttributeOnlyGraphic=new n,this._crossfadeHelper=new Be(this)}get lodCrossfadeoutDuration(){return 0}get lodCrossfadeinDuration(){return 0}get lodCrossfadeUncoveredDuration(){return 0}get extractChanges(){return this._extractChanges?.layer!==this.layer&&(this._extractChanges?.destroy(),this._extractChanges=new Se({layer:this.layer})),this._extractChanges}get layerViewUid(){return this.uid}get layerId(){return this.layer.id}get sublayerId(){return null}get _isIntegratedMesh(){return this.layer.type===`integrated-mesh`}get contentVisible(){return!this.suspended&&this._controller?.rootNodeVisible&&this.fullOpacity>Et}get legendEnabled(){return this.contentVisible&&this.layer?.legendEnabled===!0}get updatingProgressValue(){return this._controller?.updatingProgress??0}get hasTexturesOrVertexColors(){return this._hasData?this._hasTextures||this._hasColors?`yes`:`probably-not`:`unknown`}get rendererTextureUsage(){return Qe(this._currentRenderer)?this._usePBR||this._hasLoadedPBRTextures?63:53:this._usePBR||this._hasLoadedPBRTextures?44:36}get elevationOffset(){let e=this.layer?.elevationInfo;return e?.mode===`absolute-height`?B(e,this.layer.spatialReference):0}get elevationInfo(){let e=this.layer?.elevationInfo;switch(e?.mode){case`absolute-height`:return new Z(0,B(e,this.layer.spatialReference));case`relative-to-ground`:return new Z(1,B(e,this.layer.spatialReference));case`on-the-ground`:return new Z(2,0);default:return new Z(0,0)}}get supportedTextureEncodings(){return Ge(this.view.stage.renderView.capabilities)}get clientGeometry(){return this.i3sOverrides.geometryOverrides}get elevationRange(){let e=this._nodeId2Meta,t=new q;for(let n of e.values()){let e=n?.geometryElevationRange;e?.elevationRangeValid&&!e.isEmpty&&t.expandElevationRange(e)}return t.elevationRangeValid&&!t.isEmpty?t:null}get fullExtent(){return this.layer.fullExtent}initialize(){let e=has(`enable-feature:idb-mock-cache`);this._idbCache=e?new ct(this.view,e):new st(`esri-scenelayer-cache`,`geometries`),this.addResolvingPromise(this.layer.indexInfo);let t=this.view.resourceController,n=t.memoryController;this.i3sOverrides=new Xe({view:this.view,layer:this.layer,memoryController:n,extractChanges:this.extractChanges}),this._workerHandle=new Pe(pt(t)),this.addResolvingPromise(this._workerHandle.promise),$e(this.layer),et(this.layer,this.view);let r=this.layer.store.defaultGeometrySchema;if(this.addResolvingPromise(this._workerHandle.setLegacySchema(this.uid,r).catch(l)),this._layerUrl=this.layer.parsedUrl.path,this._controller=new be({layerView:this,worker:this._workerHandle}),this._gpuMemoryEstimate=0,this._texMemoryEstimate=0,this._geoMemoryEstimate=0,this._stage=this.view.stage,this._collection=this._stage.renderView.componentObjectCollection,this._isIntegratedMesh||!r)this._hasComponentData=!1;else{let e=r.featureAttributes;this._hasComponentData=!!(e&&e.faceRange&&e.id)}this._hasVertexColors=(r?.vertexAttributes.color??null)!=null&&!this.layer.cachedDrawingInfo?.color;let i=this.view.resourceController.memoryController.newCache(`sl-${this.uid}`,e=>this._deleteComponentObject(e));this._memCache=i;let o=this._controller,c=this._nodeId2Meta,u=this._nodeId2MetaReloading;function*d(e){let t=o.index;if(!t)return;let n=t.rootNode;if(!n)return;let r=null;for(let i of t.traverseValues(n,t=>(r=(c.get(t.index)||u.get(t.index))?.objectHandle??null,e(t,r))))yield new We(i,r)}this._intersectionHandler=new Ue({layerViewUid:this.layerViewUid,sublayerId:this.sublayerId,collection:this._collection,slicePlaneEnabled:this.slicePlaneEnabled,isGround:has(`enable-feature:im-as-ground`)?this.layer.isUsedAsGroundLayer:this._isIntegratedMesh,traverseNodeHierarchy:d}),this._elevationProvider=new lt({view:this.view,layerElevationSource:this,intersectionHandler:this._intersectionHandler}),this._hasLoadedPBRTextures=this._usePBR,this._updatingHandles.add(()=>this.view.clippingArea,()=>this._clippingAreaChanged(),f),this._updatingHandles.add(()=>this.fullOpacity,e=>this._opacityChange(e)),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this.elevationOffset,(e,t)=>{this._reloadAll(t),this._controller.invalidateVisibilityObbs()}),this._updatingHandles.add(()=>this.elevationInfo,(e,t)=>this._elevationInfoChanged(e,t),f),this._updatingHandles.add(()=>!this.suspended&&this.elevationInfo.mode!==0,(e,t)=>{e?this.addHandles(this.view.groundView.on(`elevation-change`,({extent:e})=>this._ensureElevationTask().addExtent(e)),Wt):t&&this.removeHandles(Wt)},f),this._updatingHandles.add(()=>this._usePBR,e=>this._updatePBR(e)),this._updatingHandles.add(()=>this.rendererTextureUsage,()=>{this._reloadAll(),this.clearMemCache()}),this._updatingHandles.add(()=>this.contentVisible,e=>this._contentVisibleChanged(e),f),this._updatingHandles.add(()=>this.layer.labelsVisible,()=>this._labelingChanged(),f),this._updatingHandles.add(()=>this.layer.labelingInfo,()=>this._labelingChanged(),f),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged(),f),this.addHandles([p(()=>K.I3S_TREE_SHOW_TILES,e=>{if(e&&!this._treeDebugger){let e=this._controller.crsIndex;import(`./support/I3STreeDebugger.js`).then(({I3STreeDebugger:t})=>{!this._treeDebugger&&K.I3S_TREE_SHOW_TILES&&(this._treeDebugger=new t({lv:this,view:this.view,nodeSR:e}))})}else!e&&!K.I3S_TREE_SHOW_TILES&&(this._treeDebugger=s(this._treeDebugger))},f),p(()=>K.I3S_SHOW_MODIFICATIONS,()=>this._showModifications(),f)]),this._cacheKeySuffix=this._getCacheKeySuffix(),this._idbCache.init().catch(e=>a.getLogger(this).warn(`Failed to initialize IndexedDB cache: ${e}`));let{view:m}=this,{viewingMode:h,renderCoordsHelper:g}=m;this._planetRadiusInGlobalMode=h===`local`?0:g.referenceEllipsoid.radius}destroy(){this._clearAddTasks(),this._elevationTask=s(this._elevationTask),this.i3sOverrides=s(this.i3sOverrides),this._extractChanges=s(this._extractChanges),this._elevationProvider&&=(this._elevationProvider.notifyObjectsChanged(this.getVisibleObbs()),this.view.elevationProvider.unregister(this._elevationProvider),null),this._intersectionHandler&&=(this._stage.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),null);let e=this._workerHandle;e&&(e.destroyContextAndSelf(this.uid),this._workerHandle=null),this._removeAllNodeDataFromStage(),this._memCache=s(this._memCache),this._collection=null,this._stage=null,this._edgeView=null,this._labeler=s(this._labeler),this._treeDebugger=s(this._treeDebugger),this._controller=s(this._controller),this._highlights=s(this._highlights),this._nodeId2Meta.clear(),this._nodeId2MetaReloading.clear(),this._crossfadeHelper=s(this._crossfadeHelper),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle&&=(this._visibleGeometryChangedSchedulerHandle.remove(),null),this._updatingHandles=s(this._updatingHandles)}_memEstimateTextureAdded(e){let t=e.usedMemory;return this._gpuMemoryEstimate+=t,this._texMemoryEstimate+=t,t}_memEstimateTextureRemoved(e){if(e!=null){let t=e.usedMemory;this._gpuMemoryEstimate-=t,this._texMemoryEstimate-=t}}_memEstimateGeometryAdded(e){let t=this._collection.getObjectGPUMemoryUsage(e);return this._gpuMemoryEstimate+=t,this._geoMemoryEstimate+=t,t}_memEstimateGeometryRemoved(e){let t=this._collection.getObjectGPUMemoryUsage(e);this._gpuMemoryEstimate-=t,this._geoMemoryEstimate-=t}isNodeLoaded(e){return this._nodeId2Meta.has(e)}isNodeReloading(e){return this._nodeId2MetaReloading.has(e)}get usedMemory(){let e=this._labeler==null?0:this._labeler.usedMemory;return this._nodeId2Meta.forEach(t=>e+=t==null?0:t.node.memory),this._nodeId2MetaReloading.forEach(t=>e+=t==null?0:t.node.memory),e}get unloadedMemory(){return(this._controller==null?0:this._controller.unloadedMemoryEstimate)+(this._labeler==null?0:this._labeler.unloadedMemoryEstimate)}_labelingChanged(){if(!(Le(this.layer)&&this._supportsLabeling)){this._labeler!=null&&(this._labeler.destroy(),this._labeler=null);return}if(this._labeler!=null)return;let e=new Oe({view:this.view,layer:this.layer,collection:this._collection,overrides:this.i3sOverrides,layerViewUid:this.uid});this._nodeId2Meta.forEach(t=>t!=null&&this._addMetaToLabeler(e,t)),this._labeler=e}_loadAsyncModule(e){return++this._asyncModuleLoading,e.then(e=>(--this._asyncModuleLoading,e),e=>{throw--this._asyncModuleLoading,e})}_modificationsChanged(){if(!this._i3sWasmLoaded&&this.hasModifications){this._i3sWasmLoaded=Ae().then(()=>{this._i3sWasmLoaded=!0,this._modificationsChanged(),this.notifyUpdate()},()=>{}),this.notifyUpdate();return}if(this._i3sWasmLoaded!==!0)return;let e=e=>a.getLogger(this).error(`set-modifications-error`,`Error when setting modifications:`,e),t=this.uid,n=this.layer.spatialReference,r=n.isGeographic,i=Fe(this._layerClippingArea,this._modifications,n,this.view.state.isGlobal);this._workerHandle.setModifications(t,i,r).catch(e);try{je({context:t,modifications:i,isGeodetic:r})}catch(t){e(t)}this._controller.modificationsChanged();let o=this.hasModifications?new c:null;this._nodeId2Meta.forEach((e,t)=>{e==null?(this._nodeId2Meta.delete(t),this._controller.updateLoadStatus(t,!1)):e.node.hasModifications?(this._updateFeatureIdCounts(e,-1),this._nodeId2Meta.delete(t),this._nodeId2MetaReloading.set(t,e)):o?.push(e.node)}),this.notifyChange(`elevationRange`),o!=null&&this._nodeId2MetaReloading.forEach(e=>o.push(e.node)),o!=null&&o.length>0&&(this.updateNodeModificationStatus(o),o.forAll(e=>{if(e.imModificationImpact!==2){let t=this._nodeId2Meta.get(e.index);this._controller.invalidateGeometryVisibility(e.index),t==null?this._nodeId2Meta.has(e.index)&&(this._nodeId2Meta.delete(e.index),this._controller.updateLoadStatus(e.index,!1)):(this._updateFeatureIdCounts(t,-1),this._nodeId2Meta.delete(e.index),this._nodeId2MetaReloading.set(e.index,t),this.notifyChange(`elevationRange`))}})),this.clearMemCache(),this._controller.restartNodeLoading(),this._showModifications()}_showModifications(){if(this._modificationGraphics!=null&&(this.view.graphics.removeMany(this._modificationGraphics),this._modificationGraphics=null),!K.I3S_SHOW_MODIFICATIONS||this._modifications.length===0)return;let e={clip:[227,227,79,.8],mask:[227,139,79,.8],replace:[139,227,79,.8]},t={outline:{color:[255,255,255],width:1}};this._modificationGraphics=[];for(let r of this._modifications){let i=r.geometry;i.spatialReference=this.layer.spatialReference;let a=new Ee({...t,color:e[r.type]});this._modificationGraphics.push(new n({geometry:i,symbol:a}))}this.view.graphics.addMany(this._modificationGraphics)}_addMetaToLabeler(e,t){e.addNodeMeta(t,(e,t)=>this._createAttributes(e,t))}_contentVisibleChanged(e){e?(this.view.elevationProvider.register(this._elevationContext,this._elevationProvider),this._stage.view.sceneIntersectionHelper.addIntersectionHandler(this._intersectionHandler)):(this._removeAllNodeDataFromStage(),this.view.elevationProvider&&this.view.elevationProvider.unregister(this._elevationProvider),this._stage.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler))}getLoadedAttributes(e){let t=this._nodeId2Meta.get(e);if(t?.attributeInfo!=null)return t.attributeInfo.loadedAttributes}getAttributeData(e){let t=this._nodeId2Meta.get(e);if(t?.attributeInfo!=null)return t.attributeInfo.attributeData}setAttributeData(e,t){let n=this._nodeId2Meta.get(e);n?.attributeInfo!=null&&(n.attributeInfo.attributeData=t,this._attributeValuesChanged(n))}async updateAttributes(e,t,n){let r=this._nodeId2Meta.get(e);r!=null&&(await this.i3sOverrides.applyAttributeOverrides(r.featureIds,t,n,this._controller.requiredAttributes),r.attributeInfo=t,this._controller.reschedule(()=>{this._nodeId2Meta.get(e)===r&&this._attributeValuesChanged(r)},n).catch(e=>{u(e)||a.getLogger(this).warn(`Error while updating attribute values. Layer might not display correctly.`,e)}))}_attributeValuesChanged(e){e.cachedRendererVersion=this._getInvalidRendererVersion(),e.appliedFilters=null,this._labeler!=null&&this._labeler.setNodeMetaAttributes(e,(e,t)=>this._createAttributes(e,t)),this._updateEngineObject(e)}clearMemCache(){this._memCache!=null&&this._memCache.clear(),this._addTasks.forEach(e=>e.allowMemCache=!1)}getVisibleNodes(){let e=[];return this._nodeId2Meta.forEach(t=>t!=null&&e.push(t.node)),e}getVisibleObbs(){let e=[];return this._nodeId2Meta.forEach(t=>t&&e.push(this._collection.getComponentObb(t.objectHandle))),e}getLoadedNodeIndices(e){this._nodeId2Meta.forEach((t,n)=>e.push(n)),this._nodeId2MetaReloading.forEach((t,n)=>e.push(n))}_getVertexBufferLayout(e,t){return _t(yt(this._getGeometryParameters({hasTexture:It(e.params.material),hasNormals:t.normal,hasRegions:t.uvRegion})))}_getObjectIdField(){return this.layer.objectIdField||L}_getGlobalIdField(){return this.layer.globalIdField}_findGraphicNodeAndIndex(e){let t=G(this.layer.fieldsIndex,e.attributes,this._getObjectIdField());for(let e of this._nodeId2Meta.values()){let n=e?.featureIds.indexOf(t);if(n!=null&&n>=0)return{node:e.node,index:n}}return null}_getGraphicIndices(e,t){let n=this._nodeId2Meta.get(e.index);if(n==null)return[];let r=[],i=this._getObjectIdField(),a=this.layer.fieldsIndex;for(let e of t){let t=G(a,e.attributes,i),o=n.featureIds.indexOf(t);o!==-1&&r.push(o)}return r}whenGraphicBounds(e){let t=this._findGraphicNodeAndIndex(e);if(!t)return Promise.reject();let n=this.getAABB(t.node.index,t.index);return n==null?Promise.reject():Promise.resolve({boundingBox:n,screenSpaceObjects:[]})}getAABBFromIntersectorTarget(e){return e.nodeIndex==null||e.componentIndex==null?null:this.getAABB(e.nodeIndex,e.componentIndex)}getAABB(e,t){let n=this._nodeId2Meta.get(e);if(n?.featureIds==null||t>=n.featureIds.length)return null;let r=n.objectHandle,i=He(t,this._collection,r,P(24),0),a=this.view.renderSpatialReference,o=this.view.spatialReference;return he(i,a,0,i,o,0)?ge(i):null}whenGraphicAttributes(e,t){return tt(this.layer,e,this._getObjectIdField(),t,()=>this._nodeId2Meta.values().filter(i).toArray())}getGraphicFromIntersectorTarget(e,t){if(e.nodeIndex==null||e.componentIndex==null)return null;let n=this._nodeId2Meta.get(e.nodeIndex);if(n?.featureIds==null||e.componentIndex>=n.featureIds.length)return null;let r=this._createLayerGraphic(this._createAttributes(e.componentIndex,n));return r?this._meshUtilsImporterModule?(r.geometry=this._meshUtilsImporterModule.createMesh({layerView:this,nodeIndex:e.nodeIndex,featureIndex:e.componentIndex}),r):t.defer?(t.defer(async()=>(r.geometry=(await this._meshUtilsImporter).createMesh({layerView:this,nodeIndex:e.nodeIndex,featureIndex:e.componentIndex}),r)),null):r:null}_getCacheKey(e){return`${this._layerUrl}/v30/${e}${this._cacheKeySuffix}`}get _meshUtilsImporter(){return this._meshUtilsImporterPromise||(this._meshUtilsImporterPromise=import(`./i3s/meshUtils.js`),this._meshUtilsImporterPromise.then(e=>this._meshUtilsImporterModule=e,()=>{})),this._meshUtilsImporterPromise}_getCacheKeySuffix(){let e=this.view.renderSpatialReference;return e==null?Kt:e===D(e)?qt:this.layer.spatialReference.equals(e)?Gt:e.wkid==null?null:`@${e.wkid}`}_getMemCacheKey(e,t=this.elevationOffset){return e+`#`+t}get _idbCacheEnabled(){return!this._controller.disableIDBCache&&!this.hasModifications&&this.elevationOffset===0&&this._cacheKeySuffix!=null}loadCachedGPUData(e){return this._memCache==null?null:this._memCache.pop(this._getMemCacheKey(e))}deleteCachedGPUData(e){e!=null&&this._deleteComponentObject(e)}_cacheGPUData(e,t=this.elevationOffset){if(this._memCache==null){this._deleteComponentObject(e);return}let n=this._controller.indexDepth-e.node.level;this._memCache.put(this._getMemCacheKey(e.node.index,t),e,n)}loadMissingTextures(e,t,n,r){let i=e?.filter((e,n)=>{if((e.usage&this.rendererTextureUsage)===0)return!1;if(t==null)return!0;let r=Ke(e.encodings,this.supportedTextureEncodings),i=t[n];return!!(i?.data==null||r&&i.encoding!==r.encoding)})??[];return i.length===0?Promise.resolve(!1):n(i,r).then(n=>{let r=0;for(let i=0;i<e.length;i++)r<n.length&&n[r].id===e[i].id&&(t[i]=n[r],r++);return!0})}loadCachedNodeData(e,t,n){return this._idbCacheEnabled?this._idbCache.get(this._getCacheKey(e.id),t).then(r=>r==null?null:(r.globalTrafo=_e(r.globalTrafo),r.nodeVersion===e.version?(this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=J.fromData(r.geometryObbData)),this.loadMissingTextures(r.requiredTextures,r.textureData,n,t).then(n=>(n&&this._idbCache.initialized&&r.textureData!=null&&(r.byteSize=zt(r.transformedGeometry,r.textureData),r.textureData.every(Rt)&&this._indexedDbSizeCheck(e,r)&&this._idbCache.put(this._getCacheKey(e.id),r).catch(t=>a.getLogger(this).warn(`Failed to update node with textures in IndexedDB cache: ${e.id}: ${t}`))),d(t),r))):(this._idbCache.remove(this._getCacheKey(e.id)),null))):Promise.resolve(null)}addNode(e,t,n){return Lt(t)?t.geometryBuffer==null?(this._addNodeMeta(e.index,null),Promise.resolve()):this._addData(e,t.attributeDataInfo,()=>this._transformNode(e,t,n).then(r=>this._safeReschedule(()=>{if(r==null)return e.hasModifications=!1,this._addCachedNodeData(e,null,n);let{obb:i,componentOffsets:o,featureIds:s,anchorIds:c,anchors:l,transformedGeometry:u,geometryMinElevation:d,geometryMaxElevation:f}=r;e.hasModifications=u.hasModifications;let p=_e(r.globalTrafo),m=b(Ht,i.center.x,i.center.y,i.center.z);x(m,m,p);let h=new J(m,[i.extents.x,i.extents.y,i.extents.z],ce(i.orientation.x,i.orientation.y,i.orientation.z,i.orientation.w));this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=h),t.geometryData.componentOffsets=o,s&&(t.geometryData.featureIds=Array.from(s)),t.geometryData.anchorIds=c,t.geometryData.anchors=l;let g={nodeVersion:e.version,geometryData:t.geometryData,requiredTextures:t.requiredTextures,textureData:t.textureData,transformedGeometry:u,globalTrafo:p,geometryObbData:h.data,geometryMinElevation:d,geometryMaxElevation:f,byteSize:zt(u,t.textureData)};if(this._idbCacheEnabled&&this._idbCache.initialized&&this._indexedDbSizeCheck(e,g)){let t=g.textureData==null?null:g.textureData.map(e=>Rt(e)?e:null);this._idbCache.put(this._getCacheKey(e.id),{...g,textureData:t}).catch(t=>a.getLogger(this).warn(`Failed to store node in IndexedDB cache: ${e.id}: ${t}`))}return this._addCachedNodeData(e,g,n)},n))):Promise.reject()}getElevationRange(e){let t=new q,n=this._controller,{index:r}=n;if(!r)return t;let{rootNode:i}=r;if(!i)return t;let a=this._nodeId2Meta,o=n.viewportQueries;return r.traverse(i,n=>{let{childrenLoaded:r}=n;if(r===0)return!1;let i=o.getAndUpdateVisibilityObbInRenderSR(n),s=null;if(i){if(!i.intersectSphereWithMBS(e,i.radius))return!1}else if(s=o.calculateServiceMbsInRenderSRElevationAdjusted(n),s?.isValid&&!e.intersects(s))return!1;let c=a.get(n.index);if(c){let{geometryObbInRenderSR:r}=n;if(!r||r.intersectSphereWithMBS(e)){let e=c.geometryElevationRange;e.elevationRangeValid&&!e.isEmpty&&t.expandElevationRange(e)}}return r-+!!c>0}),t}computeVisibilityObb(e){return nt(e,this.view.renderSpatialReference,this._controller.crsIndex,this.layer.spatialReference,this.elevationOffset,this._modifications,this.view.renderCoordsHelper.sphericalPCPF)}_transformNode(e,t,n){let r=t.geometryData.geometries??[],i=Array(r.length);for(let e=0;e<r.length;++e)i[e]=this._getVertexBufferLayout(r[e],t.geometryDescriptor);let a=this.layer.normalReferenceFrame,o=t.normalReferenceFrame??a??`none`,s=e.serviceMbsInIndexSR,c=this.elevationOffset,l=this._controller.crsIndex,u=this._controller.crsVertex,d=this.view.renderSpatialReference,f=Ze(s,c,o,l,d),p=O(l,u),m=O(u,d);if(p==null||m==null)return Promise.resolve(null);let h={context:this.uid,geometryBuffer:t.geometryBuffer,geometryData:t.geometryData,geometryDescriptor:t.geometryDescriptor,layouts:i,globalTrafo:f,geometryElevationOffset:c,mbs:s.toJSON(),obbData:e.serviceObbInIndexSR?.data,elevationOffset:c,planetRadiusInGlobalMode:this._planetRadiusInGlobalMode,needNormals:this._controller.isMeshPyramid||this._imVertexNormals,computeNormals:this._isIntegratedMesh&&this._imVertexNormals,normalReferenceFrame:o,indexToVertexProjector:p,vertexToRenderProjector:m};return this._workerHandle.invoke(h,n)}get _supportsNodeCrossFading(){return!this.view?.stage?.renderer.shadowsEnabled}get nodeCrossfadingEnabled(){return this._supportsNodeCrossFading&&(this.lodCrossfadeinDuration>0||this.lodCrossfadeoutDuration>0||this.lodCrossfadeUncoveredDuration>0)}get nodeFadeoutEnabled(){return this._supportsNodeCrossFading&&this.lodCrossfadeoutDuration>0}_setNewNodeOpacity(e){let t=this.nodeCrossfadingEnabled?0:this.fullOpacity;this._setNodeOpacity(e,t)}addCachedGPUData(e,t,n){if(this.elevationInfo.mode===0&&(e.geometryObbInRenderSR=this._collection.getComponentObb(t.objectHandle).clone()),!this._controller.isGeometryVisible(e)){this._cacheGPUData(t);return}let r=e.index;this._addNodeMeta(r,t),this.updateNodeState(r,n),this._collection.setObjectVisibility(t.objectHandle,!0),this._updateElevationOffsets(t),this._labeler!=null&&this._addMetaToLabeler(this._labeler,t),this._updateMaterial(t),this._setNewNodeOpacity(t),this.elevationInfo.mode!==0&&this._ensureElevationTask().schedule(r),this._updateEngineObject(t),this._highlights?.objectCreated(t),this._treeDebugger!=null&&this._treeDebugger.update()}addCachedNodeData(e,t,n,r){return this._addData(e,n,()=>this._addCachedNodeData(e,t,r))}async deleteCachedNodeData(e){if(this._idbCacheEnabled)return this._idbCache.remove(this._getCacheKey(e))}async _addCachedNodeData(e,t,n){if(!this.contentVisible||!this._controller.isGeometryVisible(e)){this._removeNodeStageData(e.index,this.elevationOffset,this._nodeId2MetaReloading);return}if(t==null){this._addNodeMeta(e.index,null);return}let r=this._addTasks.get(e.index),{geometryData:i,transformedGeometry:o}=t;await this.i3sOverrides.applyAttributeOverrides(i.featureIds,r.attributeInfo,n,this._controller.requiredAttributes);let s=t.textureData==null?[]:t.textureData.filter(e=>e!=null&&(e.usage&this.rendererTextureUsage)!==0);e.memory=0;let{componentOffsets:c,geometries:l,featureIds:u,anchorIds:d,anchors:f}=i,p=this._collection,m=l[0],{layout:h,indices:g,interleavedVertexData:_,positionData:v,hasColors:ce}=o,{material:b,geometryParameters:x}=this._materialParameters(m,h),S=_.byteLength/h[0].stride,de=c||new Uint32Array([0,g?g.length:S]),C=m.transformation?oe(m.transformation):se(),T=_e(t.globalTrafo);ie(C,T,C);let E=ae(w(),C),D=y(ne(),C),me=this._isIntegratedMesh?this._imShading?2:0:1,he=x.textureCoordinateType,O=!ee(D,re),A=new bt(h,me,he,+!!O),ge=new xt({interleavedVertexData:_,vertexCount:S,indexData:g},{positions:ve(v.data),indices:ye(v.indices)},de,A),j=this.view.renderSpatialReference,M=this.view.groundView.spatialReference,N=J.fromData(ht(t.geometryObbData)).getCenter(Xt),P=[1,1,1];pe(N,j,P,M)||a.getLogger(this).errorOnce(`Unsupported coordinate system for IM overlay`);let F=w();k(N,j,F,M);let I=ne();te(I,D);let L=w();le(L,ue(L,N,E),I);let be=F[0]-L[0]*P[0],xe=F[1]-L[1]*P[1],Se=x.textureCoordinateType===2,{textures:R,texturePromise:Ce,materialParameters:we}=this._initMaterialAndTextures(b,s,Se,e),z=p.createObject(new vt(fe(be,xe,P[0],P[1]),new Ct(E,D),J.fromData(ht(t.geometryObbData)),ge,has(`enable-feature:im-as-ground`)?!this.layer.isUsedAsGroundLayer:!this._isIntegratedMesh),we);e.memory+=this._memEstimateGeometryAdded(z),e.memory+=R.reduce((e,t)=>e+(t==null?0:this._memEstimateTextureAdded(t)),0);let B=!!b.hasParametersFromSource,Te=b.alphaMode!==`blend`&&b.metallicRoughness.baseColorFactor[3]>=1,V=new Ot(e,u,z,this._getInvalidRendererVersion(),r.attributeInfo,{hasParametersFromSource:B,isOpaque:Te},R,d,f,t.geometryMinElevation,t.geometryMaxElevation);r.meta=V,this._hasTextures||=t.requiredTextures?.some(({usage:e})=>!!(e&19))||!!e.resources.texture,this._hasData=!0,this._hasColors||=ce,this.notifyChange(`hasTexturesOrVertexColors`);let Ee=this.slicePlaneEnabled;return Promise.all([this._addOrUpdateEdgeRendering(V),Ce]).then(([t,r])=>(this._addTasks.has(e.index)&&t?.updateObjectVisibility(V.objectHandle,!1).catch(e=>this._logEdgeViewError(e,this.layer.title)),this._safeReschedule(()=>{let n=this._addTasks.get(e.index);if(!n)return;if(this._addNodeMeta(e.index,V),n.meta=null,!this.contentVisible){this._removeNodeStageData(e.index,this.elevationOffset);return}p.setObjectVisibility(z,!0),t?.updateObjectVisibility(V.objectHandle,!0).catch(e=>this._logEdgeViewError(e,this.layer.title)),V.attributeInfo=n.attributeInfo;let r=V.cachedRendererVersion!==this._rendererVersion,i=Ee!==this.slicePlaneEnabled;this._updateElevationOffsets(V);let a=V.elevationOffsets;this._updateComponentData(V);let o=this._applyFiltersToNode(V);(r||t!=null&&(i||o||a))&&this._addOrUpdateEdgeRendering(V).catch(()=>{}),this._labeler!=null&&this._addMetaToLabeler(this._labeler,V),this._visibleGeometryChanged(V,0),this._highlights?.objectCreated(V),this._updateMaterial(V),this._setNewNodeOpacity(V),this._treeDebugger!=null&&this._treeDebugger.update()},n))).catch(e=>{let{meta:t,allowMemCache:n}=r;throw r.meta=null,t&&n?this._cacheGPUData(t):t&&this._deleteComponentObject(t),e})}_addNodeMeta(e,t){if(this._removeNodeStageData(e,this.elevationOffset,this._nodeId2MetaReloading),this._nodeId2Meta.has(e)){a.getLogger(this).error(`Removing duplicated node`);let t=this._nodeId2Meta.get(e);t&&(this._deleteComponentObject(t),this._updateFeatureIdCounts(t,-1))}else this._controller.updateLoadStatus(e,!0);t&&(t.lodCrossfadeProgress=null,this.nodeCrossfadingEnabled&&X(t.cachedEdgeMaterials,0),this._updateFeatureIdCounts(t,1)),this._nodeId2Meta.set(e,t),this.notifyChange(`elevationRange`)}_updateElevationOffsets(e){if(!e.node.serviceMbsInIndexSR)return;let{view:t,elevationInfo:n}=this,r=this._controller.crsIndex,{groundView:i,groundSpatialReference:a,renderSpatialReference:o}=t,s=n.mode;if(s===0){e.elevationAlignmentOffset=n.offset,e.elevationOffsets=null,e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`);return}if(e.elevationAlignmentOffset=0,o==null||a==null){e.elevationOffsets=null,e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`);return}let c=this._collection.getObjectTransform(e.objectHandle);e.elevationOffsets=e.elevationOffsets??[];let l=Ht,u=Ut,d=s===2,f=this.view.renderCoordsHelper,p=e.featureIds.length,m=(()=>{if(e.cachedElevationAnchors)return e.cachedElevationAnchors;let t=P(p*3);e.cachedElevationAnchors=t;let{center:n}=e.node.serviceMbsInIndexSR;for(let i=0;i<p;i++){let s=i*3,d=e.anchorIds?.indexOf(i)??-1;e.anchors&&d>=0?(b(l,e.anchors[d*3],e.anchors[d*3+1],e.anchors[d*3+2]),S(l,l,n),k(l,r,l,o),t[s+2]=f.getAltitude(l),k(l,o,l,a),t[s]=l[0],t[s+1]=l[1]):(this._collection.getComponentAabb(e.objectHandle,i,u,!0),b(l,(u[0]+u[3])/2,(u[1]+u[4])/2,u[2]),le(l,l,c.rotationScale),S(l,l,c.position),t[s+2]=f.getAltitude(l),k(l,o,l,a),t[s]=l[0],t[s+1]=l[1])}return t})(),h=n.offset,g=e.elevationOffsets;i.getElevations(m,p,(e,t)=>{let n=d?m[e*3+2]:0;g[e]=h+(t??0)-n}),e.updateGeometryElevationRange(),this.notifyChange(`elevationRange`)}_ensureElevationTask(){return this._elevationTask??=new ze(this.view.resourceController.scheduler,e=>this._controller.updateElevationChanged(e,this.view.groundView.spatialReference)?.filterInPlace(e=>this._nodeId2Meta.get(e)!=null),e=>this._nodeElevationAlignmentChanged(this._nodeId2Meta.get(e)),()=>this.elevationInfo?.mode),this._elevationTask}_elevationInfoChanged(e,t){let n=e.mode!==0,r=!!t&&t!==e&&t.mode!==0;this._intersectionHandler.updateElevationAlignState(n,this.view.state.viewingMode),n&&!r&&this._controller.removeAllGeometryObbs(),this._nodeId2Meta.forEach(e=>this._nodeElevationAlignmentChanged(e))}_nodeElevationAlignmentChanged(e){e!=null&&(this._updateElevationOffsets(e),this._updateComponentData(e),this._updateEdgeRendering(e),this._labeler!=null&&this._labeler.updateLabelPositions(e),this._updateSnappingSources(e,2),this._elevationProvider.notifyObjectChanged(this._collection.getComponentObb(e.objectHandle)))}_safeReschedule(e,t){return d(t),this._controller.reschedule(e,t)}_materialParameters(e,t){let n=e.params.material==null?qe():e.params.material,r=t.some(({name:e})=>e===`uvRegion`),i=t.some(({name:e})=>e===`normalCompressed`),a=It(n);return{geometryParameters:this._getGeometryParameters({hasTexture:a,hasNormals:i,hasRegions:r}),material:n}}_initMaterialAndTextures(e,t,n,r){let i=this._stage.renderView,a=e=>{this._gpuMemoryEstimate-=e,this._texMemoryEstimate-=e,r.memory-=e},o=t.map(t=>Je(t,e,n,i,this._compressionTracker,a));this._stage.addTextures(o);let{materialParameters:s,texturePromise:c}=Ye(e,o,t,this.view.stage.renderView.textures,{rendererTextureUsage:this.rendererTextureUsage,usePBR:this._usePBR,isIntegratedMesh:this._isIntegratedMesh,isGround:this.layer.isUsedAsGroundLayer,slicePlaneEnabled:this.slicePlaneEnabled,viewSpatialReference:this.view.spatialReference,applySSAO:this._applySSAO});return{textures:o,texturePromise:c,materialParameters:s}}_getGeometryParameters(e){return new St(this._hasVertexColors,e.hasNormals,e.hasTexture?e.hasRegions?2:1:0)}_addData(e,t,n){let r=this._addTasks.get(e.index);if(r)r.attributeInfo=t;else{let i=Promise.withResolvers();r=new Vt(t,null,i.promise),this._addTasks.set(e.index,r),n().then(i.resolve,i.reject).then(()=>this._addTasks.delete(e.index)).catch(t=>{throw this._addTasks.delete(e.index),t})}return r.promise}_clearAddTasks(){this._addTasks.forEach(e=>{e.meta!=null&&(this._cacheGPUData(e.meta),e.meta=null)}),this._addTasks.clear()}_clippingAreaChanged(){let e=this.view.renderSpatialReference,t=this.layer.spatialReference,n=M();this._renderClippingArea=mt(this.view.clippingArea,n,e)?n:null;let r=M();this._layerClippingArea=mt(this.view.clippingArea,r,t)?r:null,this._filterChange(),this._controller&&this._controller.updateClippingArea(this.view.clippingArea),this._isIntegratedMesh&&this._modificationsChanged()}get hasGeometryFilter(){return!1}_geometryFilterChange(){let e=this.hasGeometryFilter;this._controller.geometryFilterChanged(e),this._applyFilters(e),this._assertFeatureIdNodeCounts(e)}_assertFeatureIdNodeCounts(e){e&&!this._featureIdCounts?(this._featureIdCounts=$(this._nodeId2Meta.values()),this._filteredIdCounts=$(this._nodeId2Meta.values(),1),this._weaklyRemovedIdCounts=$(this._nodeId2Meta.values(),2),this.addHandles(p(()=>this._controller.updating,e=>{!e&&this._needFilterResolve&&(this.multiGeometryFilterResolve(),this._needFilterResolve=!1,this.notifyUpdate())},{sync:!0}),`updateFinished`)):!e&&this._featureIdCounts&&(this._featureIdCounts=null,this._filteredIdCounts=null,this._weaklyRemovedIdCounts=null,this._mismatchShow=null,this._mismatchHide=null,this.removeHandles(`updateFinished`),this._needFilterResolve=!1,this.notifyUpdate())}_updateFeatureIdCounts(e,t){this._featureIdCounts&&(this._needFilterResolve=!0,Q(this._featureIdCounts,e.featureIds,t),Q(this._filteredIdCounts,e.filteredIds,t),Q(this._weaklyRemovedIdCounts,e.weaklyRemovedIds,t))}_updateFilteredIdCounts(e,t,n){this._filteredIdCounts&&(this._needFilterResolve=!0,Q(this._filteredIdCounts,t,-1),Q(this._filteredIdCounts,e.filteredIds,1),Q(this._weaklyRemovedIdCounts,n,-1),Q(this._weaklyRemovedIdCounts,e.weaklyRemovedIds,1))}_checkFeatureIdNodeCountInvariant(){let e=this._featureIdCounts!=null;if(this.hasGeometryFilter!==e&&a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`LayerView should have feature id node counts if and only if it has a geometry filter`,{layerView:this,hasNodeCounts:e}),!this._featureIdCounts||!this._filteredIdCounts)return;let t=$(this._nodeId2Meta.values());o(this._featureIdCounts,t)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _featureIdCounts`,{layerView:this,counts:this._featureIdCounts,expected:t});let n=$(this._nodeId2Meta.values(),1);o(this._filteredIdCounts,n)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _filteredIdCounts`,{layerView:this,counts:this._filteredIdCounts,expected:n});let r=$(this._nodeId2Meta.values(),2);o(this._weaklyRemovedIdCounts,r)||a.getLogger(this).error(`checkFeatureIdNodeCountInvariant()`,`Incorrect _weaklyRemovedIdCounts`,{layerView:this,counts:this._weaklyRemovedIdCounts,expected:n})}multiGeometryFilterResolve(){if(!this._featureIdCounts||!this._filteredIdCounts)return;let e=null,t=null;for(let[n,r]of this._filteredIdCounts){let i=this._featureIdCounts.get(n);i!==r&&(r+(this._weaklyRemovedIdCounts?.get(n)??0)===i?(e??=new Set,e.add(n)):(t??=new Set,t.add(n)))}h(e,this._mismatchShow)&&h(t,this._mismatchHide)||(this._mismatchShow=e,this._mismatchHide=t,this._nodeId2Meta.forEach(e=>{if(!e?.filteredIds)return;let t=Yt(e,this._mismatchShow,this._mismatchHide);this._collection.setAllComponentVisibilities(e.objectHandle,t),this._visibleGeometryChanged(e,2)}))}_filterChange(){this._applyFilters(this.hasGeometryFilter)}_applyFilters(e){this._filters=this.getFilters(),e?this._controller&&this._controller.requestUpdate():this._nodeId2Meta.forEach(e=>{e&&this._applyFiltersToNode(e)&&(this._addOrUpdateEdgeRendering(e).catch(()=>{}),this._visibleGeometryChanged(e,2))})}getFilters(){let e=[],t=this._renderClippingArea;return t!=null&&e.push((e,n)=>this._boundingRectFilter(e,n,t)),e}addSqlFilter(e,t,n){if(t!=null){let r=t.fieldNames;e.push((e,i)=>this._sqlFilter(e,i,t,r,n))}}_sqlFilter(e,t,n,r,i){let a={},o=this._createLayerGraphic(a);if(!o)return;let s=this.layer.objectIdField,c=t.featureIds,l=t.attributeInfo?.attributeData;r.every(e=>e===s||l?.[e]!=null)&&rt(e,c,e=>{a[s]=c[e];for(let t of r)t!==s&&(a[t]=l?H(l[t],e):null);try{return n.testFeature(o)}catch(e){return i(e),!1}})}_boundingRectNodeTest(e,t){return me(e.node.serviceMbsInIndexSR,this._controller.crsIndex,Ft,this.view.renderSpatialReference),it(t,Ft)}_boundingRectFeatureTest(e,t,n){return this._collection.getComponentAabb(e.objectHandle,t,At),j(At,jt),N(n,jt)}_boundingRectFilter(e,t,n){let r=this._collection,i=this._boundingRectNodeTest(t,n);if(i===3)return;if(i===0){e.length=0;return}let a=r.getComponentCount(t.objectHandle);if(a.invisible+a.visible!==t.featureIds.length)return;let o=this._transformClippingArea(Mt,n,t.objectHandle);rt(e,t.featureIds,e=>this._boundingRectFeatureTest(t,e,o))}_transformClippingArea(e,t,n){let r=this._collection.getObjectTransform(n),i=r.position,a=r.rotationScale;return e[0]=(t[0]-i[0])/a[0],e[1]=(t[1]-i[1])/a[4],e[2]=(t[2]-i[0])/a[0],e[3]=(t[3]-i[1])/a[4],e}async _addOrUpdateEdgeRendering(e,t=!0){let n=e.objectHandle,{hasEdges:r,perFeatureEdgeMaterials:i}=this._getFilteredEdgeMaterials(e);if(r&&!this._edgeView)try{this._edgeView=await this._stage.renderer.loadEdgeView()}catch(e){if(!u(e))throw e}let a=this._edgeView;if(!a)return null;let o=a.hasObject(n);if(r){if(o)return this.nodeCrossfadingEnabled&&X(i,this.getNodeOpacity(e)),a.updateAllComponentMaterials(n,i,this.slicePlaneEnabled,t).catch(e=>this._logEdgeViewError(e,this.layer.title)),a.updateObjectVisibility(n,!0).catch(e=>this._logEdgeViewError(e,this.layer.title)),a.updateAllVerticalOffsets(n,e.elevationOffsets).catch(e=>this._logEdgeViewError(e,this.layer.title)),a;let r=await this._collection.addEdges(n,a,i,this.slicePlaneEnabled,e.elevationOffsets);return e.edgeMemoryUsage=r,e.node.memory+=r,a}return o&&(e.node.memory-=e.edgeMemoryUsage,e.edgeMemoryUsage=0,a.removeObject(n)),null}_applyFiltersToNode(e){let{filteredIds:t,weaklyRemovedIds:n}=e,r=this._applyFiltersToNodeComponents(e);return this._updateFilteredIdCounts(e,t,n),r&&this._labeler?.applyFilterChange(e),r}_applyFiltersToNodeComponents(e){let t=this._collection,n=t.getComponentCount(e.objectHandle),r=e.filteredIds!=null,i=n.invisible===0;if(t.setAllComponentVisibilities(e.objectHandle,`all`),this._filters.length===0)return e.filteredIds=null,!i;if((e.filteredIds==null||e.appliedFilters!==this._filters)&&(e.weaklyRemovedIds=null,e.filteredIds=Jt(e,this._filters),e.appliedFilters=this._filters),r&&e.filteredIds===e.featureIds&&(!this._mismatchHide||e.filteredIds.every(e=>!this._mismatchHide?.has(e))))return!i;let a=Yt(e,this._mismatchShow,this._mismatchHide);return t.setAllComponentVisibilities(e.objectHandle,a),!0}_removeAllNodeDataFromStage(e=this.elevationOffset){this._nodeId2Meta.forEach((t,n)=>this._removeNodeStageData(n,e)),this._nodeId2MetaReloading.forEach((t,n)=>this._removeNodeStageData(n,e,this._nodeId2MetaReloading)),this._elevationTask=s(this._elevationTask)}removeNode(e){let t=this.elevationOffset;this._removeNodeStageData(e,t),this._removeNodeStageData(e,t,this._nodeId2MetaReloading),this._elevationTask!=null&&this._elevationTask.remove(e)}_removeNodeStageData(e,t,n=this._nodeId2Meta){n.has(e)&&this._controller.updateLoadStatus(e,!1);let r=n.get(e);r==null?n.delete(e):(this._collection.setObjectVisibility(r.objectHandle,!1),this._edgeView!=null&&this._edgeView.hasObject(r.objectHandle)&&this._edgeView.updateObjectVisibility(r.objectHandle,!1).catch(e=>this._logEdgeViewError(e,this.layer.title)),this._visibleGeometryChanged(r,1),this._labeler!=null&&this._labeler.removeNodeMeta(r),n.delete(e),this._highlights?.objectDeleted(r),n===this._nodeId2Meta?(this._updateFeatureIdCounts(r,-1),this._cacheGPUData(r,t),this.nodeCrossfadingEnabled&&this._crossfadeHelper.stopNodeFading(r)):this._deleteComponentObject(r),this._treeDebugger!=null&&this._treeDebugger.update())}_deleteComponentObject(e){if(this._edgeView!=null&&this._edgeView.removeObject(e.objectHandle),this._memEstimateGeometryRemoved(e.objectHandle),this._collection.destroyObject(e.objectHandle),e.textures)for(let t of e.textures)this._memEstimateTextureRemoved(t),this._stage.removeTexture(t)}updateNodeState(e,t){this._nodeId2Meta.get(e)?.objectHandle.updatePolygonOffset(+(t===0))}updateNodeIndex(e,t){if(this._nodeId2Meta.has(e)){let n=this._nodeId2Meta.get(e);this._nodeId2Meta.delete(e),this._nodeId2Meta.set(t,n),this.notifyChange(`elevationRange`)}let n=this._nodeId2MetaReloading.get(e);n&&(this._nodeId2MetaReloading.delete(e),this._nodeId2MetaReloading.set(t,n))}_invalidateAllSymbols(){this._rendererVersion=U(this._rendererVersion,1),this._controller?.requestUpdate()}_getInvalidRendererVersion(){return U(this._rendererVersion,-1)}async _rendererChange(e){if(this._currentRenderer=e,this.notifyChange(`rendererTextureUsage`),this._rendererVersion=U(this._rendererVersion,1),this._rendererFields=null,this._colorVariable=null,this._opacityVariable=null,this._invalidateAllSymbols(),e&&(this._rendererFields=await e.getRequiredFields(this.layer.fieldsIndex)),this._updateSymbologyFields(),!this._arcade&&e&&`arcadeRequired`in e&&e.arcadeRequired&&(this._arcade=await Te()),e&&`visualVariables`in e&&e.visualVariables)for(let t of e.visualVariables)t.type===`color`?this._colorVariable=t:t.type===`opacity`?this._opacityVariable=t:a.getLogger(this).warn(`Unsupported visual variable type for 3D Object Scene Services: ${t.type}`);if(e)for(let t of e.symbols)t.type!==`mesh-3d`&&a.getLogger(this).error(`Symbols of type '${t.type}' are not supported for 3D Object Scene Services.`);this._controller&&this._controller.requestUpdate()}_getCachedEdgeMaterials(e){return this._hasComponentData&&e.cachedRendererVersion!==this._rendererVersion&&this._updateCachedRendererData(e),e.cachedEdgeMaterials}_getComponentParameters(e){this._hasComponentData&&e.cachedRendererVersion!==this._rendererVersion&&this._updateCachedRendererData(e);let t=e.cachedSymbology;return(n,r)=>{let i=n*e.cachedSymbologyStride;T(r.externalColor,t[i]/255,t[i+1]/255,t[i+2]/255,t[i+3]/255);let a=this._stage.renderView.olidRenderHelper;if(a){let t=e.featureIds[n],i=this.sublayerId?`${this.layerViewUid}_${this.sublayerId}`:this.layerViewUid,o=z(this.view,this.uid);a.setUidToObjectAndLayerId(t,t,this.layerId,i,this.layerPopupEnabledAndHasTemplate&&!o,e.node.resources.attributes,n,this.sublayerId),r.olidColor=a.getObjectAndLayerIdColor({graphicUid:t,layerViewUid:i})}r.externalColorMixMode=t[i+4]&15,r.castShadows=!!(t[i+4]&16),r.pickable=!!(t[i+4]&32),r.elevationOffset=e.elevationOffsets?.[n]??0,r.emissiveStrength=e.emissiveStrengths?.[n]??1,r.emissiveSource=e.emissiveSources?.[n]??0}}_getSymbolInfo(e,t){let n=e?.getSymbol(t,{arcade:this._arcade});if(!(n instanceof V))return null;let r=n.id;if(this._symbolInfos.has(r))return this._symbolInfos.get(r);let i=at(n);return this._symbolInfos.set(r,i),i}_setSymbologyOverride(e,t){this._symbologyOverride!==e&&(this._symbologyOverride=e,this._symbologyOverrideFields=t,this._invalidateAllSymbols(),this._updateSymbologyFields())}_updateSymbologyFields(){this._symbologyFields=this._symbologyOverrideFields!=null&&this._symbologyOverrideFields.length>0?this._rendererFields!=null&&this._rendererFields.length>0?xe(this.layer.fieldsIndex,[...this._rendererFields,...this._symbologyOverrideFields]):this._symbologyOverrideFields:this._rendererFields}_updateCachedRendererData(e){if(e.cachedRendererVersion=this._rendererVersion,!this._hasComponentData)return;let t=this._tmpAttributeOnlyGraphic,n={};t.attributes=n;let r=this._currentRenderer,i=e.attributeInfo?.attributeData,a=e.featureIds?this.layer.objectIdField:null,o=i!=null&&this._symbologyFields!=null&&this._symbologyFields.length>0,s=null,c=null;if(o&&this._symbologyFields!=null){s=[],c=[];for(let e of this._symbologyFields){let t=i[e];t&&(s.push(e),c.push(t))}}e.cachedSymbology||=I(e.featureIds.length*e.cachedSymbologyStride);let l=new ut,u=this.fullOpacity,d=this.nodeCrossfadingEnabled?this.getNodeOpacity(e):u,f=null,p=1,m=W,h=0;for(let i=0;i<e.featureIds.length;i++){if(a!=null&&(n[a]=e.featureIds[i]),o&&s)for(let e=0;e<s.length;e++)n[s[e]]=H(c[e],i);let u=r?this._getSymbolInfo(r,t):null,g,_;if(l.pickable=!0,r&&`visualVariables`in r){if(this._colorVariable){let e=Ce(this._colorVariable,t,{color:Pt,arcade:this._arcade});e&&(g=l.color,g[0]=e.r/255,g[1]=e.g/255,g[2]=e.b/255,g[3]=e.a??1,!this._opacityVariable&&e.a!==null&&(_=e.a))}this._opacityVariable&&(_=we(this._opacityVariable,t,{arcade:this._arcade}))}if(u?.material){let e=u.material;g=g==null||_==null?Ie(g,_,e.color,e.alpha,Dt,l.color):Ie(g,_,null,null,Dt,l.color)}g??=T(l.color,1,1,1,1);let v=u?.material;if(l.colorMixMode=v?.colorMixMode??1,l.edgeMaterial=u?.edgeMaterial,this._symbologyOverride?.(t,l),this._nodeColorOverride!=null&&(this._nodeColorOverride(e.node,g),l.colorMixMode=3),l.pickable&&=g[3]>=Et,l.castShadows=u?u.castShadows:l.pickable,l.edgeMaterial!=null){let t=g[3]>=1&&(e.material.isOpaque||l.colorMixMode===3)?1:0;(l.edgeMaterial!==f||t!==p)&&(m={...l.edgeMaterial,opacity:d,objectTransparency:t},f=l.edgeMaterial,p=t),e.cachedEdgeMaterials[i]=m}else e.cachedEdgeMaterials[i]=W;e.cachedSymbology[h++]=Math.round(g[0]*255),e.cachedSymbology[h++]=Math.round(g[1]*255),e.cachedSymbology[h++]=Math.round(g[2]*255),e.cachedSymbology[h++]=Math.round(g[3]*255),e.cachedSymbology[h++]=l.colorMixMode|l.castShadows<<4|l.pickable<<5;let y=v?.emissive?.strength==null?Y:v?.emissive?.strength;y!==Y&&!e.emissiveStrengths&&(e.emissiveStrengths=Array(e.featureIds.length).fill(Y)),e.emissiveStrengths&&(e.emissiveStrengths[i]=y);let ee=v?.emissive?.source||0;ee!==0&&!e.emissiveSources&&(e.emissiveSources=Array(e.featureIds.length).fill(0)),e.emissiveSources&&(e.emissiveSources[i]=ee)}}_getFilteredEdgeMaterials(e){let t=this._getCachedEdgeMaterials(e);this.nodeCrossfadingEnabled||X(t,this.fullOpacity);let n=e.filteredIds;if(n==null)return{hasEdges:t.some(e=>e!==W),perFeatureEdgeMaterials:t};let r=0,i=!1,a=t.map((t,a)=>e.featureIds[a]===n[r]?(i||=t!==W,r++,t):W);return{hasEdges:i,perFeatureEdgeMaterials:a}}_updateComponentData(e){if(!this._hasComponentData)return;let{objectHandle:t}=e,n=this._getComponentParameters(e);this._collection.setComponentData(t,n),this._stage.renderView.requestRender()}_reloadAll(e=this.elevationOffset){this._removeAllNodeDataFromStage(e),this._controller!=null&&this._controller.restartNodeLoading()}_refreshGroundUsage(){this._intersectionHandler.isGround=has(`enable-feature:im-as-ground`)?this.layer.isUsedAsGroundLayer:this._isIntegratedMesh,this.contentVisible&&(this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(this._elevationContext,this._elevationProvider)),this._reloadAll(),this.clearMemCache()}_opacityChange(e){this.nodeCrossfadingEnabled&&this._crossfadeHelper.stopAllNodeFading(),this._nodeId2Meta.forEach(t=>{t!=null&&(this._collection.updateObjectOpacity(t.objectHandle,e),X(t.cachedEdgeMaterials,e),this._updateEdgeRendering(t))})}_updateMaterial(e){e.objectHandle.updateMaterial({slicePlaneEnabled:this.slicePlaneEnabled,usePBR:this._usePBR})}_updateEngineObject(e){this._updateComponentData(e),this._applyFiltersToNode(e),this._addOrUpdateEdgeRendering(e).catch(()=>{}),this._visibleGeometryChanged(e,2)}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e),this._labeler!=null&&(this._labeler.slicePlaneEnabled=e),this._foreachMeta(t=>{t.objectHandle.updateMaterial({slicePlaneEnabled:e}),this._updateEdgeRendering(t,!1)})}_updatePBR(e){this._foreachMeta(t=>t.objectHandle.updateMaterial({usePBR:e})),this._hasLoadedPBRTextures=!0}_foreachMeta(e){this._nodeId2Meta.forEach(t=>{t!=null&&e(t)})}get _usePBR(){return this._imShading&&this.view.qualitySettings.physicallyBasedRenderingEnabled}_updateEdgeRendering(e,t=!0){this._edgeView!=null&&this._edgeView.hasObject(e.objectHandle)&&this._addOrUpdateEdgeRendering(e,t).catch(()=>{})}_forAllNodes(e){this._nodeId2Meta.forEach(e)}_ignoreClientNodeOverriddenFeatures(e){return this.i3sOverrides.hasGeometryChanges?(t,n,r)=>r.node.index>=0&&this.i3sOverrides.featureHasGeometryChanges(t)?0:e(t,n,r):e}_forAllFeatures(e,t,n){for(let r of this._nodeId2Meta.values())if(r!=null&&!(t&&r.node.serviceMbsInIndexSR&&t(r.node.serviceMbsInIndexSR)===1))switch(n){case 1:this._forAllFeaturesOfNode(r,e);break;case 0:this._forAllVisibleFeaturesOfNode(r,e);break;case 2:this._forAllQueryableFeaturesOfNode(r,e)}}_forAllFeaturesOfNode(e,t){e.featureIds.forEach((n,r)=>t(n,r,e))}_forAllVisibleFeaturesOfNode(e,t){let n=e.featureIds;this._collection.forEachVisibleComponent(e.objectHandle,r=>t(n[r],r,e)===0)}_forAllQueryableFeaturesOfNode(e,t){let n=this._ignoreClientNodeOverriddenFeatures(t);if(this._renderClippingArea==null)return this._forAllFeaturesOfNode(e,n);let r=this._boundingRectNodeTest(e,this._renderClippingArea);if(r===0)return;if(r===3)return this._forAllFeaturesOfNode(e,n);let i=e.featureIds,a=e.objectHandle,o=ot(this._renderClippingArea,this._collection.getObjectTransform(a));for(let t=0;t<i.length;t++)this._boundingRectFeatureTest(e,t,o)&&n(i[t],t,e)}_createAttributes(e,t){let n={};t.featureIds!=null&&(n[this._getObjectIdField()]=t.featureIds[e]);let r=t.attributeInfo?.attributeData;if(r!=null)for(let t of Object.keys(r))n[t]=H(r[t],e);return n}_createGraphic(e,t){return this._createLayerGraphic(this._createAttributes(e,t))}highlight(e,t){let r=dt(e);if(r.length===0)return ft;let i=wt(t),a=r[0]instanceof n?this._featureIdsFromGraphics(r):typeof r[0]==`number`?r:null;if(!a)return ft;let o=this._ensureHighlights(),{set:s,handle:c}=o.acquireSet(i);return o.setFeatureIds(s,a),c}_featureIdsFromGraphics(e){let t=this.layer.fieldsIndex,n=this._getObjectIdField();return e.map(e=>G(t,e.attributes,n))}_ensureHighlights(){return this._highlights??=new Re({collection:this._collection,forAllFeatures:e=>this._forAllFeatures(e,null,1),forAllFeaturesOfNode:(e,t)=>this._forAllFeaturesOfNode(e,t)}),this._highlights}resetHighlights(){this._highlights=s(this._highlights)}_visibleGeometryChanged(e,t){this._elevationProvider&&(this._visibleGeometryChangedSchedulerHandle??=m(()=>{let{node:t}=e,n=t.visibilityObbInRenderSR??t.geometryObbInRenderSR??t.serviceObbInRenderSR;if(n!=null){let e=A();n.toAaBoundingBox(e),this.emit(`visible-geometry-changed`,new De(e))}else this.emit(`visible-geometry-changed`);this._visibleGeometryChangedSchedulerHandle=null}),this._updateSnappingSources(e,t),this._elevationProvider.notifyObjectChanged(this._collection.getComponentObb(e.objectHandle)))}get performanceInfo(){return new ke(this.usedMemory,this._nodeId2Meta.size,Math.round(this._gpuMemoryEstimate/1048576),Math.round(this._geoMemoryEstimate/1048576),Math.round(this._texMemoryEstimate/1048576),Math.round(this.unloadedMemory/1048576),this._idbCacheEnabled?Math.round(this._idbCache.getHitRate()*100):0)}checkInvariants(){}get test(){}getNodeOpacityByIndex(e){let t=this._nodeId2Meta.get(e);return this.getNodeOpacity(t)}getNodeOpacity(e){return e==null?0:this._collection.getObjectOpacity(e.objectHandle)}isNodeFullyFadedIn(e){return this._crossfadeHelper.isNodeFullyFadedIn(e)}getNodeCrossfadeMetaData(e){return this._nodeId2Meta.get(e)}getNodeComponentHandle(e){return this._nodeId2Meta.get(e)?.objectHandle}markNodeToRemove(e){this._controller&&this._controller.markNodeToRemove(e)}removeMarkedNodes(){this._controller&&this._controller.removeMarkedNodes()}foreachCrossfadeNode(e){this._nodeId2Meta.forEach(e)}fadeNode(e,t,n){if(!this.nodeCrossfadingEnabled)return;let r=this._nodeId2Meta.get(e);r!=null&&this._crossfadeHelper.fadeNode(e,r,t,n)}setNodeOpacityByIndex(e,t){let n=this._nodeId2Meta.get(e);n!=null&&this._setNodeOpacity(n,t)}_setNodeOpacity(e,t){this._collection.updateObjectOpacity(e.objectHandle,t),this._setNodeEdgeOpacity(e,t)}_setNodeEdgeOpacity(e,t){if(this._edgeView==null||!e.cachedEdgeMaterials)return;X(e.cachedEdgeMaterials,t);let n=e.objectHandle;this._edgeView.hasObject(n)&&this._edgeView.updateAllComponentOpacities(n,t).catch(e=>this._logEdgeViewError(e,this.layer.title))}get hasModifications(){return this._isIntegratedMesh&&this._layerClippingArea!=null||this._modifications&&this._modifications.length>0}updateNodeModificationStatus(e){let t=e.length;if(!this.hasModifications||t<=0||this._i3sWasmLoaded!==!0)return;let n=this.uid,r=Bt(e);if(r){let t={context:n,buffer:r.buffer};Me(t);let i=new Float64Array(r.buffer);e.forAll((e,t)=>{let n=i[t],r=Ne(n);e.imModificationImpact=r,r!==0&&this._controller.invalidateGeometryVisibility(e.index)})}}notifyUpdate(){this.notifyChange(`updating`)}notifyLODUpdate(){this._controller.notifyLODUpdate()}isUpdating(){return!!(this._controller&&this._controller.updating)||!!this._visibleGeometryChangedSchedulerHandle||this._labeler!=null&&this._labeler.updating||this._crossfadeHelper?.updating||this._i3sWasmLoaded instanceof Promise||this._asyncModuleLoading>0||this._elevationTask!=null&&this._elevationTask.readyToRun||this._needFilterResolve||this._compressionTracker.compressing}trackSnappingSources(e){let t={events:e,fetchEdgeLocations:async(e,t,n)=>{let r=this._nodeId2Meta.get(e);if(r==null)throw Error(`invalid-node`);let{origin:i,buffer:a}=await this._collection.extractEdgeInformation(r.objectHandle,t,n);return this._snappingLocationsApplyElevation(r,a,i),{type:`components`,objectIds:r.featureIds,locations:a,origin:i}},remove:()=>r(this._snappingSourcesTrackers,t)};return this._snappingSourcesTrackers.push(t),this._nodeId2Meta.forEach((t,n)=>{if(t==null)return;let r=this._controller.getRenderMbs(t.node);r&&e.add(n,r)}),t}_snappingLocationsApplyElevation(e,t,n){if(!e.elevationOffsets||this.elevationInfo.mode===0)return;let r=t.position0,i=t.position1,a=t.componentIndex,o=w(),s=w(),c=(e,t)=>{S(e,e,n),this.view.renderCoordsHelper.worldUpAtPosition(e,s),S(e,e,de(s,s,t)),C(e,e,n)};for(let t=0;t<r.count;t++){let n=e.elevationOffsets[a.get(t)];r.getVec(t,o),c(o,n),r.setVec(t,o),i.getVec(t,o),c(o,n),i.setVec(t,o)}}_updateSnappingSources(e,t){let{index:n}=e.node,r=this._controller.getRenderMbs(e.node);if(r!=null)for(let e of this._snappingSourcesTrackers)(t===1||t===2)&&e.events.remove(n),(t===0||t===2)&&e.events.add(n,r)}_logEdgeViewError(e,t){u(e)||a.getLogger(this).warn(`Error while processing edges. Edges on this layer might not display correctly`,t,e)}_indexedDbSizeCheck(e,t){return t.byteSize>104857600?(a.getLogger(this).warn(`Node is too big to store in IndexedDB cache: ${e.id} (${t.byteSize} bytes)`),!1):t.byteSize>0}get elevationProvider(){return this._elevationProvider}};return e([_()],F.prototype,`extractChanges`,null),e([_()],F.prototype,`_hasLoadedPBRTextures`,void 0),e([_()],F.prototype,`_asyncModuleLoading`,void 0),e([_()],F.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([_()],F.prototype,`view`,void 0),e([_()],F.prototype,`layer`,void 0),e([_()],F.prototype,`_controller`,void 0),e([_()],F.prototype,`_labeler`,void 0),e([_()],F.prototype,`updating`,void 0),e([_()],F.prototype,`suspended`,void 0),e([_()],F.prototype,`contentVisible`,null),e([_({readOnly:!0})],F.prototype,`legendEnabled`,null),e([_(gt)],F.prototype,`updatingProgress`,void 0),e([_()],F.prototype,`updatingProgressValue`,null),e([_()],F.prototype,`hasTexturesOrVertexColors`,null),e([_()],F.prototype,`rendererTextureUsage`,null),e([_()],F.prototype,`elevationOffset`,null),e([_()],F.prototype,`elevationInfo`,null),e([_({type:Boolean})],F.prototype,`slicePlaneEnabled`,void 0),e([_()],F.prototype,`supportedTextureEncodings`,null),e([_({type:[R]})],F.prototype,`_modifications`,void 0),e([_({readOnly:!0})],F.prototype,`clientGeometry`,null),e([_()],F.prototype,`elevationRange`,null),e([_()],F.prototype,`fullExtent`,null),e([_()],F.prototype,`_elevationTask`,void 0),e([_({readOnly:!0})],F.prototype,`_usePBR`,null),F=e([v(`esri.views.3d.layers.I3SMeshView3D`)],F),F},At=A(),jt=M(),Mt=M(),Nt=new J,Pt=new t([0,0,0,0]),Ft=new F(0,0,0,0);function It(e){if(e==null)return!1;let t=e.metallicRoughness;return t&&t.baseColorTextureId>=0||t&&t.metallicRoughnessTextureId>=0||e.normalTextureId>=0||e.emissiveTextureId>=0||e.occlusionTextureId>=0}function Lt(e){return`geometryData`in e}function Rt(e){return e!=null&&g(e.data)}function zt(e,t){let n=1024+e.interleavedVertexData.byteLength+(e.indices?e.indices.byteLength:0)+e.positionData.data.byteLength+e.positionData.indices.byteLength;if(t!=null)for(let e of t)e!=null&&g(e.data)&&(n+=e.data.byteLength);return n}function Bt(e){if(e.length===0)return;let t=e.length*10,n=new Float64Array(t),r=0;return e.forAll(e=>{let t=e.serviceObbInIndexSR;t??(t=Nt,e.serviceMbsInIndexSR?(t.setCenter(e.serviceMbsInIndexSR.center),t.setHalfSizeFromValues(e.serviceMbsInIndexSR.radius,e.serviceMbsInIndexSR.radius,e.serviceMbsInIndexSR.radius)):t.invalidate());let i=t.data;n[r++]=i[0],n[r++]=i[1],n[r++]=i[2],n[r++]=i[3],n[r++]=i[4],n[r++]=i[5],n[r++]=i[6],n[r++]=i[7],n[r++]=i[8],n[r++]=i[9]}),n}class Vt{constructor(e,t,n){this.attributeInfo=e,this.meta=t,this.promise=n,this.allowMemCache=!0}}function X(e,t){e.forEach(e=>e.opacity=t)}class Z{constructor(e,t){this.mode=e,this.offset=t}}const Ht=w(),Ut=A(),Wt=`elevation-change`,Gt=``,Kt=`@null`,qt=`@ECEF`;function Jt(e,t){let n=e.featureIds.slice();for(let r of t)if(r(n,e),n.length===0)break;return n.length===e.featureIds.length?e.featureIds:n}function Yt(e,t,n){let r=[],i=e.filteredIds;if(i!=null&&!t?.size&&!n?.size)e.featureIds.forEach((e,t)=>{i[r.length]===e&&r.push(t)});else if(i!=null){let a=0;e.featureIds.forEach((e,o)=>{if(i[a]===e)++a;else if(!t?.has(e))return;n?.has(e)||r.push(o)})}return r}function Q(e,t,n){if(e&&t)for(let r of t){let t=(e.get(r)??0)+n;t>0?e.set(r,t):e.delete(r)}}function $(e,t=0){let n=new Map;for(let r of e)Q(n,t===0?r?.featureIds:t===1?r?.filteredIds:r?.weaklyRemovedIds,1);return n}const Xt=w();export{kt as I3SMeshView3D};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{__decorate as e}from"tslib";import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,destroyMaybe as r,removeMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a,createAbortError as o}from"../../../core/promiseUtils.js";import{initial as s,whenOnce as c,watch as l,when as u}from"../../../core/reactiveUtils.js";import{schedule as d}from"../../../core/scheduling.js";import{isUint8Array as f,isFloat32Array as p,isUint32Array as m,isUint16Array as h}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as g,convertUnit as _}from"../../../core/units.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as b,invert as x}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as S,IDENTITY as C}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{normalize as E,sub as D,dot as O,set as k}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as A,freeze as j,clone as ee,ZEROS as te,fromValues as ne}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as re,clone as ie,ONES as ae}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isMoon as oe,isMars as se,getReferenceEllipsoid as M,SphericalECEFSpatialReferenceLike as ce}from"../../../geometry/ellipsoidUtils.js";import le from"../../../geometry/HeightModelInfo.js";import{computeTranslationToOriginAndRotation as ue}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{localLinearScaleFactors as de}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as pe}from"../../../geometry/support/aaBoundingRect.js";import{isCompatible as me}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as he,validateScaleRange as N}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as P,isWebMercator as F,equals as I,isGeographic as L,isCGCS2000 as R}from"../../../geometry/support/spatialReferenceUtils.js";import z from"../../../geometry/support/WKIDUnitConversion.js";import{BufferViewVec4u8 as ge,BufferViewVec3u8 as _e,BufferViewVec2f as ve,BufferViewVec3f as B,BufferViewUint32 as V,BufferViewUint16 as H}from"../../../geometry/support/buffer/BufferView.js";import{nullId as U}from"../../../layers/ILyr3DWasmPerSceneView.js";import ye from"../../../layers/support/SceneModification.js";import{getHeightModelInfoFromVCS as be,validateEntity3D as xe,makeCacheKey as W}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as G}from"../../../support/elevationInfoUtils.js";import{IntegratedMesh3DTilesLayerWorkerHandle as Se}from"./IntegratedMesh3DTilesLayerWorkerHandle.js";import{LayerView3D as Ce}from"./LayerView3D.js";import{Lyr3DViewPerformanceInfo as we}from"./Lyr3DViewPerformanceInfo.js";import{addLayerViewToWasm as Te,removeLayerViewFromWasm as Ee,getLyr3DWasm as De}from"./Lyr3DWasm.js";import{toWasmModification as Oe}from"./SceneLayerWorkerHandle.js";import{LayerElevationProvider as ke}from"./i3s/LayerElevationProvider.js";import{IntegratedMesh3DTilesLayerView3DSymbol as Ae}from"./support/integratedMesh3DTilesLayerViewInstanceUtils.js";import{primTypeConversion as je,alphaModeConversion as Me,faceCullingConversion as Ne,wrapModeConversion as Pe}from"./support/lyr3dTypeConversions.js";import{makeScheduleFunction as Fe}from"./support/makeScheduleFunction.js";import{Tiles3DMeshIntersectionHandler as Ie}from"./support/Tiles3DMeshIntersectionHandler.js";import{Frustum as Le}from"../state/Frustum.js";import{ElevationRange as K}from"../support/ElevationRange.js";import{toBoundingRect as Re}from"../support/extentUtils.js";import{Obb as ze}from"../support/orientedBoundingBox.js";import{glLayout as Be}from"../support/buffer/glUtil.js";import{getGroundTransparencyModeFromOpacity as Ve}from"../terrain/TransparencyMode.js";import{ComponentGeometryParameters as He,SourceGeometry as Ue}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as We}from"../webgl-engine/collections/Component/Transform.js";import{RenderTexture as Ge}from"../webgl-engine/core/material/RenderTexture.js";import{ManagedTexture as Ke}from"../webgl-engine/lib/ManagedTexture.js";import{compressNormals as qe}from"../webgl-engine/lib/Normals.js";import{advancedMRRFactors as q}from"../webgl-engine/materials/pbrUtils.js";import Je from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as Ye}from"../../support/layerViewUtils.js";import{TaskPriority as Xe}from"../../support/Scheduler.js";import{CompressedTextureFormat as J,SizedPixelFormat as Y}from"../../webgl/enums.js";import{alphaCutoff as X}from"../../../webscene/support/AlphaCutoff.js";var Z;function Ze(e,t,n){if(t===`image/vnd-ms.dds`)switch(n){case`Dxt1`:return J.COMPRESSED_RGB_S3TC_DXT1_EXT;case`Dxt5`:return J.COMPRESSED_RGBA_S3TC_DXT5_EXT;default:return null}if(t===`image/ktx`)return n===`Etc1`?J.COMPRESSED_RGB8_ETC2:null;switch(e){case 33319:return Y.RG8;case 6407:return Y.RGB8;case 6408:return Y.RGBA8;case 6403:return Y.R8;default:return null}}let Q=class extends Ce(Je){static{Z=Ae}constructor(e){super(e),this[Z]=!0,this.type=`integrated-mesh-3dtiles`,this.skipHeightModelInfoValidation=!0,this.freeze=!1,this._modifications=[],this._visibleGeometryChangedSchedulerHandle=null,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this.ignoresMemoryFactor=!1,this._usedMemory=0,this._cacheMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._applySSAO=!has(`disable-feature:im-ssao`),this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._lyrHandleToObjects=new Map,this._visibleObjects=new Set,this._loadedObjects=new Set,this._dbgFlags=new Set;let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`IM3DTiles-${this.uid}`,e=>this._deletePerObjectData(e)),this._replacesTerrain=e.layer.replacesTerrain,this._frameTask=t.scheduler.registerTask(Xe.TILES3D,this),this._frustum=new Le(e.view.renderCoordsHelper)}tryRecycleWith(e,t){return this.canRecycleWith(e)?e.load(t).then(()=>{a(t);let n=this.layer.queryElevationCallback;this.layer=e,this.layer.queryElevationCallback=n}):null}canRecycleWith(e){return e.url===this.layer.url&&e.type===`integrated-mesh-3dtiles`&&e.replacesTerrain===this._replacesTerrain}initialize(){this._dbg(2,`Tiles3DLayerView3D initialize() called`);let{view:e}=this;this._workerHandle=new Se(Fe(e.resourceController)),this._updatingHandles.add(()=>this.layer.modifications,()=>this._loadModifications(),s),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await c(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw Ye(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await Te(this,t),a(t);let n=new Ie(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new ke({view:e,layerElevationSource:this,intersectionHandler:n});let r=this._getElevationContext();e.elevationProvider.register(r,this._elevationProvider),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged()),this._updatingHandles.add(()=>this.fullOpacity,()=>this._opacityChange()),this._updatingHandles.add(()=>e.overlayManager.renderer.isEmpty,()=>this._opacityChange()),this._updatingHandles.add(()=>e.clippingArea,()=>this._clippingAreaChanged(),s),this._updatingHandles.add(()=>e.state.contentCamera,()=>this._cameraChanged(),s),this._updatingHandles.add(()=>this.layer.isUsedAsGroundLayer,()=>this._groundUsageChanged()),e.overlayManager.registerDrapeTarget(this),this.addHandles([l(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),u(()=>this.fullOpacity,()=>this._opacityChange()),l(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),s),l(()=>this.freeze,e=>{e?this._wasm?.incrementFrozenLayerViewCount(this):(this._wasm?.decrementFrozenLayerViewCount(this),this._cameraChanged())})]),this._initializationController=null,this.addHandles(l(()=>this._replacesTerrain&&!!this._wasm?.isTerrainReady||!this._replacesTerrain&&!!has(`enable-feature:im-as-ground`)&&this.layer.isUsedAsGroundLayer,e=>{this.layer.queryElevationCallback=e?(e,t)=>this._queryElevation(e,t):null},s))}destroy(){if(this.freeze=!1,this._initializationController=n(this._initializationController),this._dbg(2,`Tiles3DLayerView3D destroy() called`),this._workerHandle?.destroyContextAndSelf(this.uid),Ee(this),this.layer.queryElevationCallback=null,this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),this._intersectionHandler.destroy(),null),this._elevationProvider){let e=Array.from(this._lyrHandleToObjects.values()),t=e.reduce((e,{componentObjects:t})=>e+t.length,0);this._elevationProvider.notifyObjectsChangedFunctional(t,t=>{for(let{componentObjects:n}of e)for(let{obb:e}of n)if(!t(e))return}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null}this.view.overlayManager.unregisterDrapeTarget(this),this._lyrHandleToObjects.forEach(e=>this.freeObject(e)),this._lyrHandleToObjects.clear(),this._visibleObjects.clear(),this._loadedObjects.clear(),this._usedMemory=0,this._cacheMemory=0,this._memCache.destroy(),this._frameTask.remove(),this._updatingHandles=r(this._updatingHandles),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=i(this._visibleGeometryChangedSchedulerHandle)}get usedAsGround(){return this.layer.isUsedAsGroundLayer}get replacesTerrain(){return this._replacesTerrain}get fullOpacity(){return has(`enable-feature:im-as-ground`)?this.usedAsGround?this.view.map.ground.opacity:this.layer.opacity:this.replacesTerrain?this.view.map.ground.opacity:1}get opaque(){return this._groundTransparencyMode===0}get invisible(){return this._groundTransparencyMode===3}get _groundTransparencyMode(){return(has(`enable-feature:im-as-ground`)?!this.usedAsGround:!this._replacesTerrain)?0:Ve(this.fullOpacity,this.view.overlayManager.renderer.isEmpty)}get _renderOpacity(){switch(this._groundTransparencyMode){case 3:return 0;case 2:return X;default:return this.fullOpacity}}get hasModifications(){return this._modifications&&this._modifications.length>0}_opacityChange(){let e=this._renderOpacity,t=this._groundTransparencyMode;this.forEachComponentObject(n=>this._collection.updateObjectOpacity(n,e,t))}_getElevationContext(){return this.replacesTerrain?0:has(`enable-feature:im-as-ground`)?this.usedAsGround?1:2:1}_groundUsageChanged(){let e=this._getElevationContext();this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(e,this._elevationProvider),this._intersectionHandler.isGround=!has(`enable-feature:im-as-ground`)||this.usedAsGround,this._intersectionHandler.slicePlaneEnabled=this.slicePlaneEnabled&&!this.replacesTerrain,this.view.overlayManager.unregisterDrapeTarget(this),this.view.overlayManager.registerDrapeTarget(this),this._loadModifications();let t=has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,n=this._renderOpacity,r=this._groundTransparencyMode;this.forEachComponentObject(e=>e.updateMaterial({isGround:t,opacity:n,groundTransparencyMode:r}))}_cameraChanged(){if(this.freeze)return;let e=this._frustum;e.update(this.view.state.contentCamera);let t=this._visibleObjects,n=!1;this._loadedObjects.forEach(r=>{let i=r.obb?.intersectsFrustum(e)??!1;i!==r.isVisible&&(r.isVisible=i,i?t.add(r):t.delete(r),r.componentObjects.forEach(e=>this._collection.setObjectVisibility(e,i)),n||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(i,r.elevationRange))}),n&&this._setVisibleElevationRangeDirty()}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}get ready(){return!this.replacesTerrain||!!this._wasm?.isTerrainReady}_modificationsChanged(){let e=this.useEsriCrs?this.layer.supportedSpatialReferences[1]:this.layer.supportedSpatialReferences[0],t=Oe(this._layerClippingArea,this._modifications,e,this.view.state.isGlobal);this._wasm?.setMeshModifications(this,t)}_clippingAreaChanged(){let e=this.layer.spatialReference,t=pe();this._layerClippingArea=Re(this.view.clippingArea,t,e)?t:null,this._modificationsChanged()}_visibleGeometryChanged(){this._visibleGeometryChangedSchedulerHandle??=d(()=>{this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=null})}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e&&!this.replacesTerrain),this.forEachComponentObject(t=>t.updateMaterial({slicePlaneEnabled:e}))}_elevationInfoChanged(e){this._wasm?.setLayerOffset(this,G(e))}get _wasm(){return De(this.view)}_queryElevation(e,t){return this.destroying||this.destroyed?Promise.reject(o()):this._wasm?.queryElevation(this,e,t)??Promise.reject(o())}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get usedMemory(){return this._usedMemory}get unloadedMemory(){return 0}get cachedMemory(){return this._cacheMemory}get useEsriCrs(){return this._useEsriCrs}get visibleAtCurrentScale(){return this.replacesTerrain||he(this.layer.effectiveScaleRange,this.view.scale)}canResume(){let e=this.layer&&`effectiveScaleRange`in this.layer?this.layer.effectiveScaleRange:null;return this.visible&&this.layer?.loaded&&this.parent&&!this.parent.suspended&&this.view?.ready&&(this.replacesTerrain||N(e)&&this.visibleAtCurrentScale)&&this.visibleAtCurrentTimeExtent||!1}get performanceInfo(){let e=0,t=0,n=0,r=0,i=0,a=0;return this._lyrHandleToObjects.forEach(o=>{o.isLoaded?(e+=o.textureMemoryUsage,t+=o.vboMemoryUsage,i++):(n+=o.textureMemoryUsage,r+=o.vboMemoryUsage,a++)}),new we(this.usedMemory,i,a,$(t),$(e),$(r),$(n))}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||P(this.view.renderSpatialReference)||F(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&I(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=be(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=L(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=g(z.units[z[t.wkid]])),r&&(e=new le({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=me(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=_(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}get _stage(){return this.view.stage}get _collection(){return this._stage.renderView.componentObjectCollection}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return G(this.layer.elevationInfo)}get elevationRange(){let e=this.fullExtent;return e?.zmin&&e?.zmax?new K(e.zmin,e.zmax):null}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get visibleElevationRange(){let e=new K;this._visibleObjects.size===0?e.setElevationRangeValues(0,0):(e.setElevationRangeValues(1/0,-1/0),this._forEachRelevantVisibleTile(t=>e.expandElevationRange(t.elevationRange)),e.minElevation===1/0&&e.setElevationRangeValues(0,0));let t=this._get(`visibleElevationRange`);return t&&t.minElevation===e.minElevation&&t.maxElevation===e.maxElevation?t:e}_setVisibleElevationRangeDirty(){this.notifyChange(`visibleElevationRange`)}_forEachRelevantVisibleTile(e){let{view:t}=this,{spatialReference:n}=t,r=n.isWGS84||n.isWebMercator||R(n)||oe(n)||se(n);if(this.view.state.isGlobal||!r)return this.forEachVisibleTile(e);let i=M(n).radius,{eye:a,viewForward:o,near:s}=t.state.contentCamera,c=E(A(),o),l=Math.max(a[2],500),u=l+i,d=Math.sqrt(u**2-i**2),f=Math.abs(Math.atan2(d,i))*i,p=l>.5*i?.5*Math.PI*i:f,m=A();this.forEachVisibleTile(t=>{let{mbsRadius:n,mbsCenter:r}=t;if(n<0)return;D(m,r,a);let i=O(m,c);Math.abs(i)<p&&i+n>s&&i-n<p&&e(t)})}get fullExtent(){return this.layer.fullExtent}forEachComponentObject(e){this._forEachObject(this._lyrHandleToObjects.values(),e)}forEachVisibleTile(e){for(let t of this._visibleObjects)e(t)}forEachTile(e){for(let t of this._loadedObjects)e(t)}forEachVisibleComponentObject(e){this._forEachObject(this._visibleObjects,e)}_forEachObject(e,t){for(let{componentObjects:n}of e)for(let e of n)t(e)}get drapeTargetType(){return has(`enable-feature:im-as-ground`)?+!this.usedAsGround:+!this.replacesTerrain}isUpdating(){let e=this._wasm;return!this.freeze&&this._wasmLayerId>=0&&e!=null&&e.isUpdating(this._wasmLayerId)}get readyToRun(){return!!this._frameTask?.readyToRun}runTask(e){this._frameTask.processQueue(e)}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!xe(t))throw Error(`entity3D not valid`);let n=new Map,r;try{r=this._createPrimitiveTextureBundles(t,n)}catch(e){throw n.forEach(e=>this._stage?.removeTexture(e)),e}let i=null;try{if(i=await this._createRenderableMain(t,r),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable aborted due to destroyed instance`);let{tileObb:a,componentObjects:o,elevationRange:s}=i,c=0,l=0,u=0;for(let e of o){let{texture:t,textureMetallicRoughness:n,textureEmissive:r,textureOcclusion:i,textureNormal:a}=e.renderable.drawParameters;c+=(t?.usedMemory??0)+(n?.usedMemory??0)+(r?.usedMemory??0)+(i?.usedMemory??0)+(a?.usedMemory??0),l+=this._collection.getObjectGPUMemoryUsage(e),u+=e.intersectionGeometry.usedMemory}let d=Array.from(n.values()),f=new $e(e.handle,o,d,u,l,c,a,e.stableNodeId,e.nodeDepth,s);return this._lyrHandleToObjects.set(e.handle,f),()=>{this._memCache.put(W(f.handle),f);let{usedMemory:e}=f;return this._cacheMemory+=e,{memUsageBytes:e}}}catch(e){throw r.forEach(e=>e.cleanup()),i?.componentObjects.forEach(e=>this._collection.destroyObject(e)),n.forEach(e=>this._stage?.removeTexture(e)),e}}_createPrimitiveTextureBundles(e,t){let n=[];try{let r=e.desc.geometry;for(let i of e.validPrimitiveIndices){let a=r.prims[i].materialId,o=e.desc.materials?.materials&&a!=null&&a!==U?e.desc.materials.materials[a]:null,s=Promise.resolve(tt),c=null,l=null,u=null,d=null,f=null;if(o){let n=o.lightingModel===`Pbr`;c=this._getTexture(o.baseColorTex,e,t),l=n?this._getTexture(o.metalTex,e,t):null,u=n?this._getTexture(o.emissiveTex,e,t):null,d=n?this._getTexture(o.occlusionTex,e,t):null,f=n?this._getTexture(o.normalTex,e,t):null;let r=[c,l,u,d,f].map(e=>e?.loadPromise??null);s=Promise.all(r)}n.push(new nt(s,c,l,u,d,f))}}catch(e){throw n.forEach(e=>e.cleanup()),e}return n}async _createRenderableMain(e,t){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain called after destroy`);let n=[],r=e.desc,i=j(...e.origin),a=this.view.groundView.spatialReference,o=this.view.state.isGlobal,s=C;if(o){let e=w();ue(ce,i,e,a),s=b(S(),e)}let c=et(r.obb),l=o?M(this.view.spatialReference).radius:0,u=[];try{let d=-1;for(let n of e.validPrimitiveIndices){d+=1;let i=r.geometry.prims[n],a=t[d];if(this._dbgFlags.has(2)&&this._dbg(2,JSON.stringify(i)),je[i.ptype]==null){this._dbg(2,`[Unsupported Feature] Unsupported primitive mode (`+i.ptype+`). Skipping primitive.`),a.cleanup();continue}let{positionView:o,normalsData:s,colorView:c,texCoord0Data:l,indicesView:f}=this._getBufferViews(i,e);if(o==null||f==null){a.cleanup();continue}let p=o.count,m=(e,t)=>e!=null&&e!==p?(this._dbg(3,`${t} !== numPos. Skipping primitive.`),!1):!0;!m(l==null?void 0:l.length/2,`numTexcoord`)||!m(c?.count,`numColors`)||!m(s?.length,`normals`)?a.cleanup():u.push({componentIndex:d,positionView:o,indicesView:f,texCoord0Data:l,colorView:c,normalsData:s})}let f=s!==C,p=f?x(S(),s)??C:C,{vertexProcessingOutputs:m,obbHalfSizeAccumulator:h,elevationRange:g}=await this._workerHandle.processTiles3DVertices(u,i,l,o,s,c,this._imVertexNormals&&!this.usedAsGround);if(this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);let _=r.materials;if(await Promise.all(t.map(e=>e.materialPromise)),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);m.length>0&&c.setHalfSize(h);for(let o of m){let{componentIndex:s,positionView:l,indicesView:u,layout:d,textureCoordinateType:m,interleavedVertexData:h,indices:g}=o,v=e.validPrimitiveIndices[s],y=r.geometry.prims[v],b=t[s],x=c.clone(),S=Be(d),C=new Uint32Array([0,u.typedBuffer.length]),w=new He(S,this._imShading?2:0,m,f?2:0),T=new Ue({interleavedVertexData:h,vertexCount:h.byteLength/S[0].stride,indexData:g},{positions:l.typedBuffer,indices:u.typedBuffer},C,w),E=this.view.renderSpatialReference,D=A(),O=[1,1,1];de(i,E,O,a)||this._dbg(3,`Unsupported coordinate system for IM overlay`),fe(i,E,D,a);let k=this._createComponentMaterialInitParameters(_,y.materialId,b);k.baseColorTexture||this._dbg(3,`No colour texture 1`);let j=this._collection.createObject({toMapSpace:re(D[0],D[1],O[0],O[1]),transform:new We(i,p),obb:x,geometry:T,elevationAlignable:!1},k);n.push(j)}let{fullExtent:v}=this.layer;return v?.hasZ&&v.zmax&&v.zmin&&(g.minElevation=Math.max(g.minElevation,v.zmin),g.maxElevation=Math.min(g.maxElevation,v.zmax)),{tileObb:c,componentObjects:n,elevationRange:g}}catch(e){throw n.forEach(e=>this._collection.destroyObject(e)),e}}_createComponentMaterialInitParameters(e,t,n){let r=e?.materials!=null&&t!=null&&t!==U?e.materials[t]:null,i=1,a=r?.baseColorTex?.imageId;if(a!=null&&e&&Array.isArray(e.images)&&a>=0&&a<e.images.length){let t=e.images[a];t.alpha&&(i=Me[t.alpha])}let o=(r==null?`Unlit`:r.lightingModel)===`Pbr`,s=ae,c=X,l=!1,u=2,d=ne(0,0,0),f=ee(q),p=n.baseColorTexture,m=n.metallicRoughnessTexture,h=n.emissionTexture,g=n.occlusionTexture,_=n.normalTexture;return r&&(s=ie(r.baseColorFactor),c=r.alphaCutoff??X,o&&(k(f,r.metallicFactor,r.roughnessFactor,0),r.emissiveFactor&&(d=r.emissiveFactor)),l=r.isDoubleSided,u=Ne[r.faceCulling??`NotSet`]),{isIntegratedMesh:!0,baseColor:s,textureAlphaCutoff:c,mrrFactors:f,baseColorTexture:p,metallicRoughnessTexture:m,normalTexture:_,occlusionTexture:g,emissionTexture:h,hasParametersFromSource:!1,sphereDepthInterpolate:this.layer.hasGoogleUrl,alphaDiscardMode:i,doubleSided:l,cullFace:u,isGround:has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,groundTransparencyMode:this._groundTransparencyMode,emissiveBaseColor:d,usePBR:o,slicePlaneEnabled:this.slicePlaneEnabled,opacity:this._renderOpacity,polygonOffset:0,ellipsoidMode:1,applySSAO:this._applySSAO}}freeRenderable(e){let t=this._lyrHandleToObjects.get(e);t?(t.isLoaded?(this._loadedObjects.delete(t),this._visibleObjects.delete(t),this._intersectionHandler.removeTile(t),this._usedMemory-=t.usedMemory):this._cacheMemory-=t.usedMemory,this.freeObject(t),this._lyrHandleToObjects.delete(e)):this._dbg(3,`freeRendedrable on non-existent renderable ${e}`)}freeObject(e){let t=W(e.handle);this._memCache.pop(t),e.textures.forEach(e=>this._stage.removeTexture(e)),e.componentObjects.forEach(e=>this._collection.destroyObject(e))}setRenderableVisibility(e,t,n){if(this.destroyed||this.destroying)return;let r=this._frustum,i=[],a=!1,o=!1;for(let s=0;s<n;++s){if(!t[s])continue;let n=e[s],c=this._lyrHandleToObjects.get(n);if(c){if(c.isLoaded){this._dbg(3,`Already loaded object marked loaded again ${c.stableNodeId}`);continue}a=!0,c.isLoaded=!0,this._loadedObjects.add(c),this._intersectionHandler.addTile(c),this._usedMemory+=c.usedMemory,this._cacheMemory-=c.usedMemory;let e=c.obb?.intersectsFrustum(r)??!0;c.isVisible=e,e&&(this._visibleObjects.add(c),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(e,c.elevationRange)),i.push(c.obb),c.componentObjects.forEach(t=>{this._collection.setObjectVisibility(t,e)}),this._memCache.pop(W(n))}else this._dbg(3,`Tried to mark Non existent object ${n} as loaded`)}for(let r=0;r<n;++r){let n=e[r];if(t[r])continue;let a=this._lyrHandleToObjects.get(n);if(a){if(!a.isLoaded){this._dbg(3,`Tried to unload not-loaded object ${a.stableNodeId}`);continue}let e=a.isVisible;this._visibleObjects.delete(a),a.isVisible=!1,a.isLoaded=!1,this._loadedObjects.delete(a),this._intersectionHandler.removeTile(a),e&&(this._visibleGeometryChanged(),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(!1,a.elevationRange)),this._usedMemory-=a.usedMemory,this._cacheMemory+=a.usedMemory,i.push(a.obb),a.componentObjects.forEach(e=>{this._collection.setObjectVisibility(e,!1)}),this._memCache.put(W(n),a)}else this._dbg(3,`Tried to mark Non existent object ${n} as not loaded`)}a&&this._visibleGeometryChanged(),i.length>0&&this._elevationProvider.notifyObjectsChanged(i),o&&this._setVisibleElevationRangeDirty()}setLodPixelThreshold(e){this._wasm?.setLodPixelThreshold(this,e)}_isVisibileElevationRangeModifiedByChangedTileVisbility(e,t){let{visibleElevationRange:n}=this,{minElevation:r,maxElevation:i}=t;return e?r<n.minElevation||i>n.maxElevation:r===n.minElevation||i===n.maxElevation}_getTexture(e,t,n){let r=e&&t.desc.materials?.images?.[e.imageId];if(!r||r.data==null||r.data===U)return null;let i=t.assets[r.data];if(!i||i.byteCount<1||i.dataType!==`U8`)return null;let a=n.get(r)??this._createTexture(e,r,i,n);return a?new Ge(this._stage.renderView.textures,a.id):null}_createTexture(e,n,r,i){let a=this._stage.renderView.renderingContext.parameters.maxMaxAnisotropy,o=n.mipCount?!0:a>1,s=Pe[e.wrapMode??`None`],c=n.alpha?6408:6407,l=new Uint8Array(r.data.buffer,0,r.byteCount),u=null,d=null;switch(n.format){case`Raw`:if(n.pixelFormat===`R8`)u=l,c=6403,d=``;else if(n.pixelFormat===`Rg8`||n.pixelFormat===`Ga8`)u=l,c=33319,d=``;else if(n.pixelFormat===`Rgb8`)u=l,c=6407,d=``;else if(n.pixelFormat===`Rgba8`)u=l,c=6408,d=``;else return t.getLogger(this).error(`Raw texture pixel format ${n.pixelFormat} not supported`),null;break;case`Dxt1`:u=l,c=6407,d=`image/vnd-ms.dds`;break;case`Dxt5`:u=l,c=6408,d=`image/vnd-ms.dds`;break;case`Basis`:u=l,c=6407,d=`image/ktx2`;break;case`Etc1`:u=l,c=6407,d=`image/ktx`;break;default:return t.getLogger(this).error(`${n.format} texture not supported`),null}if(u&&d!=null){let e=Ze(c,d,n.format),t=new Ke(u,{mipmap:o,maxAnisotropy:a,encoding:d,wrap:s,pixelFormat:c,internalFormat:e??void 0,immutable:e!=null,noUnpackFlip:!0,width:n.mip0Width,height:n.mip0Height});return this._stage.addTexture(t),i.set(n,t),t}return null}_getBufferViews(e,t){let n,r,i,a;for(let o=0;o<e.atrbs.length;o++){let s=e.atrbs[o],c=t.assets[s.assetId];if(!c)continue;let l=c.data.buffer,u=c.byteCount;try{switch(s.sem){case`Position`:c.ncomp!==3||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Position (`+c+`)`):n=new B(l,0,void 0,u);break;case`Normal`:if(c.ncomp!==3||c.dataType!==`F32`||!p(c.data))this._dbg(3,`[Unsupported Feature] Unsupported view for Normal (`+c+`)`);else{let e=new B(l,0,void 0,u);a=new Uint32Array(e.count),qe(e.typedBuffer,new Int16Array(a.buffer,a.byteOffset,a.length*2))}break;case`TexCoord`:c.ncomp!==2||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Texcoord (`+c+`)`):i===void 0&&(i=new ve(l,0,void 0,u).typedBuffer);break;case`Color`:c.dataType===`U8`&&f(c.data)&&(c.ncomp===4?r=new ge(l,0,void 0,u):c.ncomp===3&&(r=new _e(l,0,void 0,u))),r??this._dbg(3,`[Unsupported Feature] Unsupported view for Color (`+c+`)`);break;case`FeatureIndex`:break;default:this._dbg(2,`[Unsupported Feature] Unsupported semantic (`+s.sem+`). Skipping vertex attribute.`)}}catch(e){this._dbg(2,`Error Creating buffer (`+e+`). Skipping vertex attribute.`)}}let o,s=!1;if(e.index!=null&&e.index!==U){let n=t.assets[e.index];if(!n)s=!0;else{let e=n.byteCount;switch(n.dataType){case`U16`:n.ncomp===1&&h(n.data)&&(o=new H(n.data.buffer,0,void 0,e));break;case`U32`:n.ncomp===1&&m(n.data)&&(o=new V(n.data.buffer,0,void 0,e))}s=!o}}if(!s&&o==null&&n!=null){let e=n.count;o=o=e<65535?new H(new Uint16Array(e).buffer):new V(new Uint32Array(e).buffer);for(let t=0;t<e;t++)o.set(t,t)}return{positionView:n,colorView:r,texCoord0Data:i,indicesView:o,normalsData:a}}_loadModifications(){if(this.removeHandles(`modifications`),this.layer.modifications==null){this._modifications=[];return}let e=this.layer.modifications;this.addHandles(this._updatingHandles.addOnCollectionChange(()=>e,()=>{this._modifications=e.filter(e=>!(this.usedAsGround&&e.type!==`replace`)).toArray(),this._modifications.length<e.length&&t.getLogger(this).info(`Ground layers only support replace modifications. Other modification types have been ignored.`)},s),`modifications`)}_deletePerObjectData(e){this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}_dbg(e,n){this._dbgFlags.has(e)&&(e===3?t.getLogger(this).error(n):t.getLogger(this).warn(n))}};e([v()],Q.prototype,`freeze`,void 0),e([v()],Q.prototype,`fullOpacity`,null),e([v()],Q.prototype,`opaque`,null),e([v()],Q.prototype,`invisible`,null),e([v({readOnly:!0})],Q.prototype,`ready`,null),e([v({type:[ye]})],Q.prototype,`_modifications`,void 0),e([v()],Q.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([v()],Q.prototype,`layer`,void 0),e([v({readOnly:!0})],Q.prototype,`visibleAtCurrentScale`,null),e([v({readOnly:!0})],Q.prototype,`_collection`,null),e([v()],Q.prototype,`elevationOffset`,null),e([v({readOnly:!0})],Q.prototype,`visibleElevationRange`,null),e([v()],Q.prototype,`fullExtentInLocalViewSpatialReference`,void 0),Q=e([y(`esri.views.3d.layers.IntegratedMesh3DTilesLayerView3D`)],Q);const Qe=Q;class $e{constructor(e,t,n,r,i,a,o,s,c,l){this.handle=e,this.componentObjects=t,this.textures=n,this.cpuMemoryUsage=r,this.vboMemoryUsage=i,this.textureMemoryUsage=a,this.obb=o,this.stableNodeId=s,this.nodeDepth=c,this.elevationRange=l,this.bvhIntersectionGeneration=0,this.isLoaded=!1,this.isVisible=!1;let u=A();o?.getCenter(u),this._obbCenterX=u[0],this._obbCenterY=u[1],this._obbCenterZ=u[2];let d=o?.radius??-1;this._obbRadius=d,this._obbRadiusSquared=d*d,this._obbShortestHalfsize=o?Math.min(o.halfSizeX,o.halfSizeY,o.halfSizeZ):0,this._mbsCenter=o?o.getCenter(A()):te}get usedMemory(){return this.textureMemoryUsage+this.vboMemoryUsage+this.cpuMemoryUsage}get mbsRadius(){return this._obbRadius}get mbsCenter(){return this._mbsCenter}boundingVolumeIntersectsRay(e,t){if(!this.obb)return!0;let{_obbCenterX:n,_obbCenterY:r,_obbCenterZ:i}=this,a=n-e[0],o=r-e[1],s=i-e[2],c=a*t[0]+o*t[1]+s*t[2];return a*a+o*o+s*s-c*c<=this._obbRadiusSquared&&this.obb.intersectRay(e,t)}boundingVolumeIntersectsSphere(e){let t=this._obbRadius;if(t<0)return!0;let n=e.center,r=e.radius,i=t+r,a=this._obbCenterX-n[0];if(a>i)return!1;let o=this._obbCenterY-n[1];if(o>i)return!1;let s=this._obbCenterZ-n[2];if(s>i)return!1;let c=a*a+o*o+s*s;if(c>i*i)return!1;if(c<=(this._obbShortestHalfsize+r)**2)return!0;let l=r-t;return l>0&&c<=l*l?!0:this.obb?.intersectSphere(e)??!0}}function $(e){return Math.round(e/1048.576)/1e3}function et(e){return new ze(e.center,e.halfSize,T(...e.quaternion))}const tt=[];class nt{constructor(e,t,n,r,i,a){this.materialPromise=e,this.baseColorTexture=t,this.metallicRoughnessTexture=n,this.emissionTexture=r,this.occlusionTexture=i,this.normalTexture=a}cleanup(){this.baseColorTexture?.dispose(),this.metallicRoughnessTexture?.dispose(),this.emissionTexture?.dispose(),this.occlusionTexture?.dispose(),this.normalTexture?.dispose()}}export{Qe as default};
|
|
2
|
+
import{__decorate as e}from"tslib";import has from"../../../core/has.js";import t from"../../../core/Logger.js";import{abortMaybe as n,destroyMaybe as r,removeMaybe as i}from"../../../core/maybe.js";import{throwIfAborted as a,createAbortError as o}from"../../../core/promiseUtils.js";import{initial as s,whenOnce as c,watch as l,when as u}from"../../../core/reactiveUtils.js";import{schedule as d}from"../../../core/scheduling.js";import{isUint8Array as f,isFloat32Array as p,isUint32Array as m,isUint16Array as h}from"../../../core/typedArrayUtil.js";import{unitFromRESTJSON as g,convertUnit as _}from"../../../core/units.js";import{property as v,subclass as y}from"../../../core/accessorSupport/decorators.js";import{fromMat4 as b,invert as x}from"../../../core/libs/gl-matrix-2/math/mat3.js";import{create as S,IDENTITY as C}from"../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as w}from"../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{fromValues as T}from"../../../core/libs/gl-matrix-2/factories/quatf64.js";import{normalize as E,sub as D,dot as O,set as k}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{create as A,freeze as j,clone as ee,ZEROS as te,fromValues as ne}from"../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as re,clone as ie,ONES as ae}from"../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{isMoon as oe,isMars as se,getReferenceEllipsoid as M,SphericalECEFSpatialReferenceLike as ce}from"../../../geometry/ellipsoidUtils.js";import le from"../../../geometry/HeightModelInfo.js";import{computeTranslationToOriginAndRotation as ue}from"../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{localLinearScaleFactors as de}from"../../../geometry/projection/localLinearScaleFactors.js";import{projectVectorToVector as fe}from"../../../geometry/projection/projectVectorToVector.js";import{create as pe}from"../../../geometry/support/aaBoundingRect.js";import{isCompatible as me}from"../../../geometry/support/heightModelInfoUtils.js";import{isInEffectiveScaleRange as he,validateScaleRange as N}from"../../../geometry/support/scaleUtils.js";import{isPlateCarree as P,isWebMercator as F,equals as I,isGeographic as L,isCGCS2000 as R}from"../../../geometry/support/spatialReferenceUtils.js";import z from"../../../geometry/support/WKIDUnitConversion.js";import{BufferViewVec4u8 as ge,BufferViewVec3u8 as _e,BufferViewVec2f as ve,BufferViewVec3f as B,BufferViewUint32 as V,BufferViewUint16 as H}from"../../../geometry/support/buffer/BufferView.js";import{nullId as U}from"../../../layers/ILyr3DWasmPerSceneView.js";import ye from"../../../layers/support/SceneModification.js";import{getHeightModelInfoFromVCS as be,validateEntity3D as xe,makeCacheKey as W,isValidHandle as G}from"../../../layers/support/tiles3DUtils.js";import{getElevationOffsetInMeters as K}from"../../../support/elevationInfoUtils.js";import{IntegratedMesh3DTilesLayerWorkerHandle as Se}from"./IntegratedMesh3DTilesLayerWorkerHandle.js";import{LayerView3D as Ce}from"./LayerView3D.js";import{Lyr3DViewPerformanceInfo as we}from"./Lyr3DViewPerformanceInfo.js";import{addLayerViewToWasm as Te,removeLayerViewFromWasm as Ee,getLyr3DWasm as De}from"./Lyr3DWasm.js";import{toWasmModification as q}from"./SceneLayerWorkerHandle.js";import{LayerElevationProvider as Oe}from"./i3s/LayerElevationProvider.js";import{IntegratedMesh3DTilesLayerView3DSymbol as ke}from"./support/integratedMesh3DTilesLayerViewInstanceUtils.js";import{primTypeConversion as Ae,alphaModeConversion as je,faceCullingConversion as Me,wrapModeConversion as Ne}from"./support/lyr3dTypeConversions.js";import{makeScheduleFunction as Pe}from"./support/makeScheduleFunction.js";import{Tiles3DMeshIntersectionHandler as Fe}from"./support/Tiles3DMeshIntersectionHandler.js";import{Frustum as Ie}from"../state/Frustum.js";import{ElevationRange as Le}from"../support/ElevationRange.js";import{toBoundingRect as Re}from"../support/extentUtils.js";import{Obb as ze}from"../support/orientedBoundingBox.js";import{glLayout as Be}from"../support/buffer/glUtil.js";import{getGroundTransparencyModeFromOpacity as Ve}from"../terrain/TransparencyMode.js";import{ComponentGeometryParameters as He,SourceGeometry as Ue}from"../webgl-engine/collections/Component/SourceGeometry.js";import{Transform as We}from"../webgl-engine/collections/Component/Transform.js";import{RenderTexture as Ge}from"../webgl-engine/core/material/RenderTexture.js";import{ManagedTexture as Ke}from"../webgl-engine/lib/ManagedTexture.js";import{compressNormals as qe}from"../webgl-engine/lib/Normals.js";import{advancedMRRFactors as Je}from"../webgl-engine/materials/pbrUtils.js";import Ye from"../../layers/LayerView.js";import{spatialReferenceIncompatibleError as Xe}from"../../support/layerViewUtils.js";import{TaskPriority as Ze}from"../../support/Scheduler.js";import{CompressedTextureFormat as J,SizedPixelFormat as Y}from"../../webgl/enums.js";import{alphaCutoff as X}from"../../../webscene/support/AlphaCutoff.js";var Z;function Qe(e,t,n){if(t===`image/vnd-ms.dds`)switch(n){case`Dxt1`:return J.COMPRESSED_RGB_S3TC_DXT1_EXT;case`Dxt5`:return J.COMPRESSED_RGBA_S3TC_DXT5_EXT;default:return null}if(t===`image/ktx`)return n===`Etc1`?J.COMPRESSED_RGB8_ETC2:null;switch(e){case 33319:return Y.RG8;case 6407:return Y.RGB8;case 6408:return Y.RGBA8;case 6403:return Y.R8;default:return null}}let Q=class extends Ce(Ye){static{Z=ke}constructor(e){super(e),this[Z]=!0,this.type=`integrated-mesh-3dtiles`,this.skipHeightModelInfoValidation=!0,this.freeze=!1,this._modifications=[],this._visibleGeometryChangedSchedulerHandle=null,this._initializationController=null,this._wasmLayerId=-1,this._metersPerVCSUnit=1,this.ignoresMemoryFactor=!1,this._usedMemory=0,this._cacheMemory=0,this._useEsriCrs=!1,this.fullExtentInLocalViewSpatialReference=null,this._applySSAO=!has(`disable-feature:im-ssao`),this._imShading=!!has(`enable-feature:im-shading`),this._imVertexNormals=!!has(`enable-feature:im-vertex-normals`),this._lyrHandleToObjects=new Map,this._visibleObjects=new Set,this._loadedObjects=new Set,this._dbgFlags=new Set;let t=e.view.resourceController;this._memCache=t.memoryController.newCache(`IM3DTiles-${this.uid}`,e=>this._deletePerObjectData(e)),this._replacesTerrain=e.layer.replacesTerrain,this._frameTask=t.scheduler.registerTask(Ze.TILES3D,this),this._frustum=new Ie(e.view.renderCoordsHelper)}tryRecycleWith(e,t){return this.canRecycleWith(e)?e.load(t).then(()=>{a(t);let n=this.layer.queryElevationCallback;this.layer=e,this.layer.queryElevationCallback=n}):null}canRecycleWith(e){return e.url===this.layer.url&&e.type===`integrated-mesh-3dtiles`&&e.replacesTerrain===this._replacesTerrain}initialize(){this._dbg(2,`Tiles3DLayerView3D initialize() called`);let{view:e}=this;this._workerHandle=new Se(Pe(e.resourceController)),this._updatingHandles.add(()=>this.layer.modifications,()=>this._loadModifications(),s),this.addResolvingPromise(this._initializeAsync(e))}async _initializeAsync(e){this._initializationController=new AbortController;let{signal:t}=this._initializationController;if(await c(()=>e?.defaultsFromMap.heightModelInfoReady,t),a(t),!this._canProjectWithoutEngine())throw Xe(`layer`,this.layer.spatialReference.wkid,e.renderSpatialReference?.wkid);this._wasmLayerId=await Te(this,t),a(t);let n=new Fe(this);this._intersectionHandler=n,e.sceneIntersectionHelper.addIntersectionHandler(n),this._elevationProvider=new Oe({view:e,layerElevationSource:this,intersectionHandler:n});let r=this._getElevationContext();e.elevationProvider.register(r,this._elevationProvider),this._updatingHandles.add(()=>this.slicePlaneEnabled,e=>this._slicePlaneEnabledChange(e)),this._updatingHandles.add(()=>this._modifications,()=>this._modificationsChanged()),this._updatingHandles.add(()=>this.fullOpacity,()=>this._opacityChange()),this._updatingHandles.add(()=>e.overlayManager.renderer.isEmpty,()=>this._opacityChange()),this._updatingHandles.add(()=>e.clippingArea,()=>this._clippingAreaChanged(),s),this._updatingHandles.add(()=>e.state.contentCamera,()=>this._cameraChanged(),s),this._updatingHandles.add(()=>this.layer.isUsedAsGroundLayer,()=>this._groundUsageChanged()),e.overlayManager.registerDrapeTarget(this),this.addHandles([l(()=>this.layer.elevationInfo,e=>this._elevationInfoChanged(e)),u(()=>this.fullOpacity,()=>this._opacityChange()),l(()=>this.suspended,e=>this._wasm?.setEnabled(this,!e),s),l(()=>this.freeze,e=>{e?this._wasm?.incrementFrozenLayerViewCount(this):(this._wasm?.decrementFrozenLayerViewCount(this),this._cameraChanged())})]),this._initializationController=null,this.addHandles(l(()=>this._replacesTerrain&&!!this._wasm?.isTerrainReady||!this._replacesTerrain&&!!has(`enable-feature:im-as-ground`)&&this.layer.isUsedAsGroundLayer,e=>{this.layer.queryElevationCallback=e?(e,t)=>this._queryElevation(e,t):null},s))}destroy(){if(this.freeze=!1,this._initializationController=n(this._initializationController),this._dbg(2,`Tiles3DLayerView3D destroy() called`),this._workerHandle?.destroyContextAndSelf(this.uid),Ee(this),this.layer.queryElevationCallback=null,this._intersectionHandler&&=(this.view.sceneIntersectionHelper.removeIntersectionHandler(this._intersectionHandler),this._intersectionHandler.destroy(),null),this._elevationProvider){let e=Array.from(this._lyrHandleToObjects.values()),t=e.reduce((e,{componentObjects:t})=>e+t.length,0);this._elevationProvider.notifyObjectsChangedFunctional(t,t=>{for(let{componentObjects:n}of e)for(let{obb:e}of n)if(!t(e))return}),this.view.elevationProvider.unregister(this._elevationProvider),this._elevationProvider=null}this.view.overlayManager.unregisterDrapeTarget(this),this._lyrHandleToObjects.forEach(e=>this.freeObject(e)),this._lyrHandleToObjects.clear(),this._visibleObjects.clear(),this._loadedObjects.clear(),this._usedMemory=0,this._cacheMemory=0,this._memCache.destroy(),this._frameTask.remove(),this._updatingHandles=r(this._updatingHandles),this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=i(this._visibleGeometryChangedSchedulerHandle)}get usedAsGround(){return this.layer.isUsedAsGroundLayer}get replacesTerrain(){return this._replacesTerrain}get fullOpacity(){return has(`enable-feature:im-as-ground`)?this.usedAsGround?this.view.map.ground.opacity:this.layer.opacity:this.replacesTerrain?this.view.map.ground.opacity:1}get opaque(){return this._groundTransparencyMode===0}get invisible(){return this._groundTransparencyMode===3}get _groundTransparencyMode(){return(has(`enable-feature:im-as-ground`)?!this.usedAsGround:!this._replacesTerrain)?0:Ve(this.fullOpacity,this.view.overlayManager.renderer.isEmpty)}get _renderOpacity(){switch(this._groundTransparencyMode){case 3:return 0;case 2:return X;default:return this.fullOpacity}}get hasModifications(){return this._modifications&&this._modifications.length>0}_opacityChange(){let e=this._renderOpacity,t=this._groundTransparencyMode;this.forEachComponentObject(n=>this._collection.updateObjectOpacity(n,e,t))}_getElevationContext(){return this.replacesTerrain?0:has(`enable-feature:im-as-ground`)?this.usedAsGround?1:2:1}_groundUsageChanged(){let e=this._getElevationContext();this.view.elevationProvider.unregister(this._elevationProvider),this.view.elevationProvider.register(e,this._elevationProvider),this._intersectionHandler.isGround=!has(`enable-feature:im-as-ground`)||this.usedAsGround,this._intersectionHandler.slicePlaneEnabled=this.slicePlaneEnabled&&!this.replacesTerrain,this.view.overlayManager.unregisterDrapeTarget(this),this.view.overlayManager.registerDrapeTarget(this),this._loadModifications();let t=has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,n=this._renderOpacity,r=this._groundTransparencyMode;this.forEachComponentObject(e=>e.updateMaterial({isGround:t,opacity:n,groundTransparencyMode:r}))}_cameraChanged(){if(this.freeze)return;let e=this._frustum;e.update(this.view.state.contentCamera);let t=this._visibleObjects,n=!1;this._loadedObjects.forEach(r=>{let i=r.obb?.intersectsFrustum(e)??!1;i!==r.isVisible&&(r.isVisible=i,i?t.add(r):t.delete(r),r.componentObjects.forEach(e=>this._collection.setObjectVisibility(e,i)),n||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(i,r.elevationRange))}),n&&this._setVisibleElevationRangeDirty()}intersect(e,t,n,r){this._intersectionHandler.intersectRay(e,t,n,r,null,!1)}get ready(){return!this.replacesTerrain||!!this._wasm?.isTerrainReady}_modificationsChanged(){let e=this.useEsriCrs?this.layer.supportedSpatialReferences[1]:this.layer.supportedSpatialReferences[0],t=q(this._layerClippingArea,this._modifications,e,this.view.state.isGlobal);this._wasm?.setMeshModifications(this,t)}_clippingAreaChanged(){let e=this.layer.spatialReference,t=pe();this._layerClippingArea=Re(this.view.clippingArea,t,e)?t:null,this._modificationsChanged()}_visibleGeometryChanged(){this._visibleGeometryChangedSchedulerHandle??=d(()=>{this.emit(`visible-geometry-changed`),this._visibleGeometryChangedSchedulerHandle=null})}_slicePlaneEnabledChange(e){this._intersectionHandler&&(this._intersectionHandler.slicePlaneEnabled=e&&!this.replacesTerrain),this.forEachComponentObject(t=>t.updateMaterial({slicePlaneEnabled:e}))}_elevationInfoChanged(e){this._wasm?.setLayerOffset(this,K(e))}get _wasm(){return De(this.view)}_queryElevation(e,t){return this.destroying||this.destroyed?Promise.reject(o()):this._wasm?.queryElevation(this,e,t)??Promise.reject(o())}get wasmLayerId(){return this._wasmLayerId}get metersPerVCSUnit(){return this._metersPerVCSUnit}get usedMemory(){return this._usedMemory}get unloadedMemory(){return 0}get cachedMemory(){return this._cacheMemory}get useEsriCrs(){return this._useEsriCrs}get visibleAtCurrentScale(){return this.replacesTerrain||he(this.layer.effectiveScaleRange,this.view.scale)}canResume(){let e=this.layer&&`effectiveScaleRange`in this.layer?this.layer.effectiveScaleRange:null;return this.visible&&this.layer?.loaded&&this.parent&&!this.parent.suspended&&this.view?.ready&&(this.replacesTerrain||N(e)&&this.visibleAtCurrentScale)&&this.visibleAtCurrentTimeExtent||!1}get performanceInfo(){let e=0,t=0,n=0,r=0,i=0,a=0;return this._lyrHandleToObjects.forEach(o=>{o.isLoaded?(e+=o.textureMemoryUsage,t+=o.vboMemoryUsage,i++):(n+=o.textureMemoryUsage,r+=o.vboMemoryUsage,a++)}),new we(this.usedMemory,i,a,$(t),$(e),$(r),$(n))}_canProjectWithoutEngine(){if(this.view.state.viewingMode===1||P(this.view.renderSpatialReference)||F(this.view.renderSpatialReference))return!0;if(this.layer.esriCrsSpatialReference&&I(this.layer.esriCrsSpatialReference,this.view.renderSpatialReference)){if(this.layer.esriCrsSpatialReference.vcsWkid===115700)return!1;let e=be(this.layer.esriCrsSpatialReference);if(!e){let t=this.layer.esriCrsSpatialReference,n=L(t),r=`meters`;!n&&t.wkid&&t.wkid!==-1&&(r=g(z.units[z[t.wkid]])),r&&(e=new le({heightModel:`gravity-related-height`,heightUnit:r}))}let t=this.view.heightModelInfo;return this._useEsriCrs=me(e,t,!1)===0,this._useEsriCrs&&(e&&(this._metersPerVCSUnit=_(1,e.heightUnit,`meters`)),this.fullExtentInLocalViewSpatialReference=this.layer.esriCrsFullExtent),this._useEsriCrs}return!1}get _stage(){return this.view.stage}get _collection(){return this._stage.renderView.componentObjectCollection}get elevationProvider(){return this._elevationProvider}get elevationOffset(){return K(this.layer.elevationInfo)}get elevationRange(){return this._intersectionHandler?.elevationRange}getElevationRange(e){return this._intersectionHandler.getElevationRange(e)}get visibleElevationRange(){let e=new Le;this._visibleObjects.size===0?e.setElevationRangeValues(0,0):(e.setElevationRangeValues(1/0,-1/0),this._forEachRelevantVisibleTile(t=>e.expandElevationRange(t.elevationRange)),e.minElevation===1/0&&e.setElevationRangeValues(0,0));let t=this._get(`visibleElevationRange`);return t&&t.minElevation===e.minElevation&&t.maxElevation===e.maxElevation?t:e}_setVisibleElevationRangeDirty(){this.notifyChange(`visibleElevationRange`)}_forEachRelevantVisibleTile(e){let{view:t}=this,{spatialReference:n}=t,r=n.isWGS84||n.isWebMercator||R(n)||oe(n)||se(n);if(this.view.state.isGlobal||!r)return this.forEachVisibleTile(e);let i=M(n).radius,{eye:a,viewForward:o,near:s}=t.state.contentCamera,c=E(A(),o),l=Math.max(a[2],500),u=l+i,d=Math.sqrt(u**2-i**2),f=Math.abs(Math.atan2(d,i))*i,p=l>.5*i?.5*Math.PI*i:f,m=A();this.forEachVisibleTile(t=>{let{mbsRadius:n,mbsCenter:r}=t;if(n<0)return;D(m,r,a);let i=O(m,c);Math.abs(i)<p&&i+n>s&&i-n<p&&e(t)})}get fullExtent(){return this.layer.fullExtent}forEachComponentObject(e){this._forEachObject(this._lyrHandleToObjects.values(),e)}forEachVisibleTile(e){for(let t of this._visibleObjects)e(t)}forEachTile(e){for(let t of this._loadedObjects)e(t)}forEachVisibleComponentObject(e){this._forEachObject(this._visibleObjects,e)}_forEachObject(e,t){for(let{componentObjects:n}of e)for(let e of n)t(e)}get drapeTargetType(){return has(`enable-feature:im-as-ground`)?+!this.usedAsGround:+!this.replacesTerrain}isUpdating(){let e=this._wasm;return!this.freeze&&this._wasmLayerId>=0&&e!=null&&e.isUpdating(this._wasmLayerId)}get readyToRun(){return!!this._frameTask?.readyToRun}runTask(e){this._frameTask.processQueue(e)}updatingFlagChanged(){this.notifyChange(`updating`)}async createRenderable(e){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable called after destroy`);let{entity3d:t}=e;if(!xe(t))throw Error(`entity3D not valid`);let n=new Map,r;try{r=this._createPrimitiveTextureBundles(t,n)}catch(e){throw n.forEach(e=>this._stage?.removeTexture(e)),e}let i=null;try{if(i=await this._createRenderableMain(t,r),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderable aborted due to destroyed instance`);let{tileObb:a,componentObjects:o,elevationRange:s}=i,c=0,l=0,u=0;for(let e of o){let{texture:t,textureMetallicRoughness:n,textureEmissive:r,textureOcclusion:i,textureNormal:a}=e.renderable.drawParameters;c+=(t?.usedMemory??0)+(n?.usedMemory??0)+(r?.usedMemory??0)+(i?.usedMemory??0)+(a?.usedMemory??0),l+=this._collection.getObjectGPUMemoryUsage(e),u+=e.intersectionGeometry.usedMemory}let d=Array.from(n.values()),f=new et(e.handle,o,d,u,l,c,a,e.stableNodeId,e.nodeDepth,s);return this._lyrHandleToObjects.set(e.handle,f),()=>{this._memCache.put(W(f.handle),f);let{usedMemory:e}=f;return this._cacheMemory+=e,{memUsageBytes:e}}}catch(e){throw r.forEach(e=>e.cleanup()),i?.componentObjects.forEach(e=>this._collection.destroyObject(e)),n.forEach(e=>this._stage?.removeTexture(e)),e}}_createPrimitiveTextureBundles(e,t){let n=[];try{let r=e.desc.geometry;for(let i of e.validPrimitiveIndices){let a=r.prims[i].materialId,o=e.desc.materials?.materials&&a!=null&&a!==U?e.desc.materials.materials[a]:null,s=Promise.resolve(nt),c=null,l=null,u=null,d=null,f=null;if(o){let n=o.lightingModel===`Pbr`;c=this._getTexture(o.baseColorTex,e,t),l=n?this._getTexture(o.metalTex,e,t):null,u=n?this._getTexture(o.emissiveTex,e,t):null,d=n?this._getTexture(o.occlusionTex,e,t):null,f=n?this._getTexture(o.normalTex,e,t):null;let r=[c,l,u,d,f].map(e=>e?.loadPromise??null);s=Promise.all(r)}n.push(new rt(s,c,l,u,d,f))}}catch(e){throw n.forEach(e=>e.cleanup()),e}return n}async _createRenderableMain(e,t){if(this.destroyed||this.destroying)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain called after destroy`);let n=[],r=e.desc,i=j(...e.origin),a=this.view.groundView.spatialReference,o=this.view.state.isGlobal,s=C;if(o){let e=w();ue(ce,i,e,a),s=b(S(),e)}let c=tt(r.obb),l=o?M(this.view.spatialReference).radius:0,u=o?Math.hypot(c.centerX,c.centerY,c.centerZ)-l:c.centerZ,d=o?Math.max(-l,u-c.radius):u-c.radius,f=u+c.radius,p=[];try{let u=-1;for(let n of e.validPrimitiveIndices){u+=1;let i=r.geometry.prims[n],a=t[u];if(this._dbgFlags.has(2)&&this._dbg(2,JSON.stringify(i)),Ae[i.ptype]==null){this._dbg(2,`[Unsupported Feature] Unsupported primitive mode (`+i.ptype+`). Skipping primitive.`),a.cleanup();continue}let{positionView:o,normalsData:s,colorView:c,texCoord0Data:l,indicesView:d}=this._getBufferViews(i,e);if(o==null||d==null){a.cleanup();continue}let f=o.count,m=(e,t)=>e!=null&&e!==f?(this._dbg(3,`${t} !== numPos. Skipping primitive.`),!1):!0;!m(l==null?void 0:l.length/2,`numTexcoord`)||!m(c?.count,`numColors`)||!m(s?.length,`normals`)?a.cleanup():p.push({componentIndex:u,positionView:o,indicesView:d,texCoord0Data:l,colorView:c,normalsData:s})}let m=s!==C,h=m?x(S(),s)??C:C,{vertexProcessingOutputs:g,obbHalfSizeAccumulator:_,elevationRange:v}=await this._workerHandle.processTiles3DVertices(p,i,l,o,s,c,this._imVertexNormals&&!this.usedAsGround);if(this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);let y=r.materials;if(await Promise.all(t.map(e=>e.materialPromise)),this.destroyed)throw Error(`IntegratedMesh3DTilesLayerView3D: createRenderableMain aborted due to destroyed instance`);g.length>0&&c.setHalfSize(_);for(let o of g){let{componentIndex:s,positionView:l,indicesView:u,layout:d,textureCoordinateType:f,interleavedVertexData:p,indices:g}=o,_=e.validPrimitiveIndices[s],v=r.geometry.prims[_],b=t[s],x=c.clone(),S=Be(d),C=new Uint32Array([0,u.typedBuffer.length]),w=new He(S,this._imShading?2:0,f,m?2:0),T=new Ue({interleavedVertexData:p,vertexCount:p.byteLength/S[0].stride,indexData:g},{positions:l.typedBuffer,indices:u.typedBuffer},C,w),E=this.view.renderSpatialReference,D=A(),O=[1,1,1];de(i,E,O,a)||this._dbg(3,`Unsupported coordinate system for IM overlay`),fe(i,E,D,a);let k=this._createComponentMaterialInitParameters(y,v.materialId,b);k.baseColorTexture||this._dbg(3,`No colour texture 1`);let j=this._collection.createObject({toMapSpace:re(D[0],D[1],O[0],O[1]),transform:new We(i,h),obb:x,geometry:T,elevationAlignable:!1},k);n.push(j)}return v.minElevation=Math.max(v.minElevation,d),v.maxElevation=Math.min(v.maxElevation,f),{tileObb:c,componentObjects:n,elevationRange:v}}catch(e){throw n.forEach(e=>this._collection.destroyObject(e)),e}}_createComponentMaterialInitParameters(e,t,n){let r=e?.materials!=null&&t!=null&&t!==U?e.materials[t]:null,i=1,a=r?.baseColorTex?.imageId;if(a!=null&&e&&Array.isArray(e.images)&&a>=0&&a<e.images.length){let t=e.images[a];t.alpha&&(i=je[t.alpha])}let o=(r==null?`Unlit`:r.lightingModel)===`Pbr`,s=ae,c=X,l=!1,u=2,d=ne(0,0,0),f=ee(Je),p=n.baseColorTexture,m=n.metallicRoughnessTexture,h=n.emissionTexture,g=n.occlusionTexture,_=n.normalTexture;return r&&(s=ie(r.baseColorFactor),c=r.alphaCutoff??X,o&&(k(f,r.metallicFactor,r.roughnessFactor,0),r.emissiveFactor&&(d=r.emissiveFactor)),l=r.isDoubleSided,u=Me[r.faceCulling??`NotSet`]),{isIntegratedMesh:!0,baseColor:s,textureAlphaCutoff:c,mrrFactors:f,baseColorTexture:p,metallicRoughnessTexture:m,normalTexture:_,occlusionTexture:g,emissionTexture:h,hasParametersFromSource:!1,sphereDepthInterpolate:this.layer.hasGoogleUrl,alphaDiscardMode:i,doubleSided:l,cullFace:u,isGround:has(`enable-feature:im-as-ground`)?this.usedAsGround:this.replacesTerrain,groundTransparencyMode:this._groundTransparencyMode,emissiveBaseColor:d,usePBR:o,slicePlaneEnabled:this.slicePlaneEnabled,opacity:this._renderOpacity,polygonOffset:0,ellipsoidMode:1,applySSAO:this._applySSAO}}freeRenderable(e){let t=this._lyrHandleToObjects.get(e);t?(t.isLoaded?(this._loadedObjects.delete(t),this._visibleObjects.delete(t),this._intersectionHandler.removeTile(t),this._usedMemory-=t.usedMemory):this._cacheMemory-=t.usedMemory,this.freeObject(t),this._lyrHandleToObjects.delete(e)):this._dbg(3,`freeRendedrable on non-existent renderable ${e}`)}freeObject(e){let t=W(e.handle);this._memCache.pop(t),e.textures.forEach(e=>this._stage.removeTexture(e)),e.componentObjects.forEach(e=>this._collection.destroyObject(e))}setRenderableVisibility(e,t,n){if(this.destroyed||this.destroying)return;let r=this._frustum,i=[],a=!1,o=!1;for(let s=0;s<n;++s){if(!t[s])continue;let n=e[s],c=this._lyrHandleToObjects.get(n);if(c){if(c.isLoaded){this._dbg(3,`Already loaded object marked loaded again ${c.stableNodeId}`);continue}a=!0,c.isLoaded=!0,this._loadedObjects.add(c),this._intersectionHandler.addTile(c),this._usedMemory+=c.usedMemory,this._cacheMemory-=c.usedMemory;let e=c.obb?.intersectsFrustum(r)??!0;c.isVisible=e,e&&(this._visibleObjects.add(c),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(e,c.elevationRange)),i.push(c.obb),c.componentObjects.forEach(t=>{this._collection.setObjectVisibility(t,e)}),this._memCache.pop(W(n))}else this._dbg(3,`Tried to mark Non existent object ${n} as loaded`)}for(let r=0;r<n;++r){let n=e[r];if(t[r])continue;let a=this._lyrHandleToObjects.get(n);if(a){if(!a.isLoaded){this._dbg(3,`Tried to unload not-loaded object ${a.stableNodeId}`);continue}let e=a.isVisible;this._visibleObjects.delete(a),a.isVisible=!1,a.isLoaded=!1,this._loadedObjects.delete(a),this._intersectionHandler.removeTile(a),e&&(this._visibleGeometryChanged(),o||=this._isVisibileElevationRangeModifiedByChangedTileVisbility(!1,a.elevationRange)),this._usedMemory-=a.usedMemory,this._cacheMemory+=a.usedMemory,i.push(a.obb),a.componentObjects.forEach(e=>{this._collection.setObjectVisibility(e,!1)}),this._memCache.put(W(n),a)}else this._dbg(3,`Tried to mark Non existent object ${n} as not loaded`)}a&&this._visibleGeometryChanged(),i.length>0&&this._elevationProvider.notifyObjectsChanged(i),o&&this._setVisibleElevationRangeDirty()}setLodPixelThreshold(e){this._wasm?.setLodPixelThreshold(this,e)}_isVisibileElevationRangeModifiedByChangedTileVisbility(e,t){let{visibleElevationRange:n}=this,{minElevation:r,maxElevation:i}=t;return e?r<n.minElevation||i>n.maxElevation:r===n.minElevation||i===n.maxElevation}_getTexture(e,t,n){let r=e&&t.desc.materials?.images?.[e.imageId];if(!r||!G(r.data))return null;let i=t.assets[r.data];if(!i||i.byteCount<1||i.dataType!==`U8`)return null;let a=n.get(r)??this._createTexture(e,r,i,n);return a?new Ge(this._stage.renderView.textures,a.id):null}_createTexture(e,n,r,i){let a=this._stage.renderView.renderingContext.parameters.maxMaxAnisotropy,o=n.mipCount?!0:a>1,s=Ne[e.wrapMode??`None`],c=n.alpha?6408:6407,l=new Uint8Array(r.data.buffer,0,r.byteCount),u=null,d=null;switch(n.format){case`Raw`:if(n.pixelFormat===`R8`)u=l,c=6403,d=``;else if(n.pixelFormat===`Rg8`||n.pixelFormat===`Ga8`)u=l,c=33319,d=``;else if(n.pixelFormat===`Rgb8`)u=l,c=6407,d=``;else if(n.pixelFormat===`Rgba8`)u=l,c=6408,d=``;else return t.getLogger(this).error(`Raw texture pixel format ${n.pixelFormat} not supported`),null;break;case`Dxt1`:u=l,c=6407,d=`image/vnd-ms.dds`;break;case`Dxt5`:u=l,c=6408,d=`image/vnd-ms.dds`;break;case`Basis`:u=l,c=6407,d=`image/ktx2`;break;case`Etc1`:u=l,c=6407,d=`image/ktx`;break;default:return t.getLogger(this).error(`${n.format} texture not supported`),null}if(u&&d!=null){let e=Qe(c,d,n.format),t=new Ke(u,{mipmap:o,maxAnisotropy:a,encoding:d,wrap:s,pixelFormat:c,internalFormat:e??void 0,immutable:e!=null,noUnpackFlip:!0,width:n.mip0Width,height:n.mip0Height});return this._stage.addTexture(t),i.set(n,t),t}return null}_getBufferViews(e,t){let n,r,i,a;for(let o=0;o<e.atrbs.length;o++){let s=e.atrbs[o],c=t.assets[s.assetId];if(!c)continue;let l=c.data.buffer,u=c.byteCount;try{switch(s.sem){case`Position`:c.ncomp!==3||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Position (`+c+`)`):n=new B(l,0,void 0,u);break;case`Normal`:if(c.ncomp!==3||c.dataType!==`F32`||!p(c.data))this._dbg(3,`[Unsupported Feature] Unsupported view for Normal (`+c+`)`);else{let e=new B(l,0,void 0,u);a=new Uint32Array(e.count),qe(e.typedBuffer,new Int16Array(a.buffer,a.byteOffset,a.length*2))}break;case`TexCoord`:c.ncomp!==2||c.dataType!==`F32`||!p(c.data)?this._dbg(3,`[Unsupported Feature] Unsupported view for Texcoord (`+c+`)`):i===void 0&&(i=new ve(l,0,void 0,u).typedBuffer);break;case`Color`:c.dataType===`U8`&&f(c.data)&&(c.ncomp===4?r=new ge(l,0,void 0,u):c.ncomp===3&&(r=new _e(l,0,void 0,u))),r??this._dbg(3,`[Unsupported Feature] Unsupported view for Color (`+c+`)`);break;case`FeatureIndex`:break;default:this._dbg(2,`[Unsupported Feature] Unsupported semantic (`+s.sem+`). Skipping vertex attribute.`)}}catch(e){this._dbg(2,`Error Creating buffer (`+e+`). Skipping vertex attribute.`)}}let o,s=!1;if(G(e.index)){let n=t.assets[e.index];if(!n)s=!0;else{let e=n.byteCount;switch(n.dataType){case`U16`:n.ncomp===1&&h(n.data)&&(o=new H(n.data.buffer,0,void 0,e));break;case`U32`:n.ncomp===1&&m(n.data)&&(o=new V(n.data.buffer,0,void 0,e))}s=!o}}if(!s&&o==null&&n!=null){let e=n.count;o=o=e<65535?new H(new Uint16Array(e).buffer):new V(new Uint32Array(e).buffer);for(let t=0;t<e;t++)o.set(t,t)}return{positionView:n,colorView:r,texCoord0Data:i,indicesView:o,normalsData:a}}_loadModifications(){if(this.removeHandles(`modifications`),this.layer.modifications==null){this._modifications=[];return}let e=this.layer.modifications;this.addHandles(this._updatingHandles.addOnCollectionChange(()=>e,()=>{this._modifications=e.filter(e=>!(this.usedAsGround&&e.type!==`replace`)).toArray(),this._modifications.length<e.length&&t.getLogger(this).info(`Ground layers only support replace modifications. Other modification types have been ignored.`)},s),`modifications`)}_deletePerObjectData(e){this._wasm?.onRenderableEvicted(this,e.handle,e.usedMemory),this.freeRenderable(e.handle)}_dbg(e,n){this._dbgFlags.has(e)&&(e===3?t.getLogger(this).error(n):t.getLogger(this).warn(n))}};e([v()],Q.prototype,`freeze`,void 0),e([v()],Q.prototype,`fullOpacity`,null),e([v()],Q.prototype,`opaque`,null),e([v()],Q.prototype,`invisible`,null),e([v({readOnly:!0})],Q.prototype,`ready`,null),e([v({type:[ye]})],Q.prototype,`_modifications`,void 0),e([v()],Q.prototype,`_visibleGeometryChangedSchedulerHandle`,void 0),e([v()],Q.prototype,`layer`,void 0),e([v({readOnly:!0})],Q.prototype,`visibleAtCurrentScale`,null),e([v({readOnly:!0})],Q.prototype,`_collection`,null),e([v()],Q.prototype,`elevationOffset`,null),e([v({readOnly:!0})],Q.prototype,`visibleElevationRange`,null),e([v()],Q.prototype,`fullExtentInLocalViewSpatialReference`,void 0),Q=e([y(`esri.views.3d.layers.IntegratedMesh3DTilesLayerView3D`)],Q);const $e=Q;class et{constructor(e,t,n,r,i,a,o,s,c,l){this.handle=e,this.componentObjects=t,this.textures=n,this.cpuMemoryUsage=r,this.vboMemoryUsage=i,this.textureMemoryUsage=a,this.obb=o,this.stableNodeId=s,this.nodeDepth=c,this.elevationRange=l,this.bvhIntersectionGeneration=0,this.isLoaded=!1,this.isVisible=!1;let u=A();o?.getCenter(u),this._obbCenterX=u[0],this._obbCenterY=u[1],this._obbCenterZ=u[2];let d=o?.radius??-1;this._obbRadius=d,this._obbRadiusSquared=d*d,this._obbShortestHalfsize=o?Math.min(o.halfSizeX,o.halfSizeY,o.halfSizeZ):0,this._mbsCenter=o?o.getCenter(A()):te}get usedMemory(){return this.textureMemoryUsage+this.vboMemoryUsage+this.cpuMemoryUsage}get mbsRadius(){return this._obbRadius}get mbsCenter(){return this._mbsCenter}boundingVolumeIntersectsRay(e,t){if(!this.obb)return!0;let{_obbCenterX:n,_obbCenterY:r,_obbCenterZ:i}=this,a=n-e[0],o=r-e[1],s=i-e[2],c=a*t[0]+o*t[1]+s*t[2];return a*a+o*o+s*s-c*c<=this._obbRadiusSquared&&this.obb.intersectRay(e,t)}boundingVolumeIntersectsSphere(e){let t=this._obbRadius;if(t<0)return!0;let n=e.center,r=e.radius,i=t+r,a=this._obbCenterX-n[0];if(a>i)return!1;let o=this._obbCenterY-n[1];if(o>i)return!1;let s=this._obbCenterZ-n[2];if(s>i)return!1;let c=a*a+o*o+s*s;if(c>i*i)return!1;if(c<=(this._obbShortestHalfsize+r)**2)return!0;let l=r-t;return l>0&&c<=l*l?!0:this.obb?.intersectSphere(e)??!0}}function $(e){return Math.round(e/1048.576)/1e3}function tt(e){return new ze(e.center,e.halfSize,T(...e.quaternion))}const nt=[];class rt{constructor(e,t,n,r,i,a){this.materialPromise=e,this.baseColorTexture=t,this.metallicRoughnessTexture=n,this.emissionTexture=r,this.occlusionTexture=i,this.normalTexture=a}cleanup(){this.baseColorTexture?.dispose(),this.metallicRoughnessTexture?.dispose(),this.emissionTexture?.dispose(),this.occlusionTexture?.dispose(),this.normalTexture?.dispose()}}export{$e as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/6.0/LICENSE.txt */
|
|
2
|
-
import{loadLyr3DWorkerWASM as e}from"../../../libs/lyr3d/Lyr3DModule.js";let t,n=null;async function r(e){await s();let t={status:1,error:``,jobDescJson:``,data:new Uint8Array,
|
|
2
|
+
import{loadLyr3DWorkerWASM as e}from"../../../libs/lyr3d/Lyr3DModule.js";let t,n=null;async function r(e){await s();let t={status:1,error:``,jobDescJson:``,data:new Uint8Array,missingInputs:[]};if(e.inputs.length<1)return{result:t,transferList:[]};let r={ptrs:[],sizes:[]};for(let t of e.inputs){let e=n._malloc(t.byteLength);new Uint8Array(n.HEAPU8.buffer,e,t.byteLength).set(new Uint8Array(t)),r.ptrs.push(e),r.sizes.push(t.byteLength)}let i=n.process(e.jobDescJson,e.id,r,e.isMissingResourceCase);t.status=i.status,t.missingInputs=i.missingInputs.slice();let a=i.status===0&&i.data,o=t.status===2&&t.missingInputs.length>0;t.jobDescJson=i.jobDescJson.slice(),t.error=i.error.slice(),a?t.data=i.data.slice():o&&(t.originalInputs=e.inputs.slice());for(let e=0;e<r.ptrs.length;++e)n._free(r.ptrs[e]);let c=[];if(a)c.push(t.data.buffer);else if(o)for(let t of e.inputs)c.push(t);return{result:t,transferList:c}}async function i(e){await s(),n.add_spatial_reference_info(e.sr,e.isGCS,e.toMetersXY,e.toMetersZ)}function a(e){if(!n)return{success:!1,modifications:null};let t=n._malloc(e.modifications.length*8),r=new Float64Array(n.HEAPF64.buffer,t,e.modifications.length);r.set(e.modifications);let i=n.switch_mesh_modification_polygon_vcs(t,e.modifications.length,e.inVCS),a=null;return i&&(a=r.slice()),n._free(t),{success:i,modifications:a}}function o(){n&&=(n.uninitialize_lyr3d_worker_wasm(),null)}function s(){return c()?Promise.resolve():(t||=e().then(e=>{n=e,n.initialize_lyr3d_worker_wasm(),t=null}),t)}function c(){return n!==null}export{i as addSpatialReferenceInfo,o as destroyWasm,s as initialize,c as isInitialized,r as process,a as switchMeshModificationPolygonVCSSync};
|