@arcgis/core 5.0.0-next.15 → 5.0.0-next.16
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/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/71d9e9b0a7f8c0edd32d.js +1 -0
- package/config.js +1 -1
- package/core/accessorSupport/ensureType.js +1 -1
- package/core/accessorSupport/extensions/serializableProperty/reader.js +1 -1
- package/interfaces.d.ts +2 -2
- package/kernel.js +1 -1
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/webgl-engine/collections/Component/ComponentObjectCollection.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentMaterial.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/collections/Component/Material/shader/ComponentData.glsl.js +14 -32
- package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBuffer.glsl.js +17 -0
- package/views/3d/webgl-engine/core/shaderLibrary/TextureBackedBufferFields.glsl.js +10 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/BufferManager.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/ManagedTextureBackedBuffer.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBuffer.js +1 -1
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferFields.js +5 -0
- package/views/3d/webgl-engine/lib/TextureBackedBuffer/TextureBackedBufferLayout.js +5 -0
- package/views/input/gamepad/GamepadInputDevice.js +1 -1
- package/views/input/gamepad/GamepadSource.js +1 -1
- package/views/navigation/gamepad/GamepadSettings.js +1 -1
- package/assets/esri/core/workers/chunks/097e5deb51ee7e25e654.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{j as s,m as n,c as o,z as r}from"../../../../chunks/sphere.js";import{NodeBoundingData as a,Node as d,NodeTraversalState as l}from"./I3SNode.js";import{invalidateMbs as h,addWraparound as u}from"./I3SUtil.js";import{ValidatedNode as c}from"./ValidatedNode.js";import{ElevationRange as g}from"../../support/ElevationRange.js";import{Obb as _}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,i,s,n){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this._boundingData=s,this.node=n,this.parentIndex=-1,this.useAsHole=0,this.filterImpact=2,this.traversalState=null}get nodeBoundingData(){return this._boundingData}destroy(){this._boundingData=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.nodeBoundingData?.invalidateServiceBVsInRenderSR()}}class m{constructor(e=new Array,t=new Array){this._nodeDescriptors=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(const e of this._nodeDescriptors)e.destroy();this._nodeDescriptors.length=0,this._children.length=0}get nodes(){return this._nodeDescriptors}addNode(e){return this._nodeDescriptors.push(e),this._nodeDescriptors.length-1}setNodes(e,t){this._nodeDescriptors=e,this._children=t}get children(){return this._children}}class v{get _useNodePages(){return this._pageSize>0}constructor(t,i,s,n,o,r,d,l,h,u,c,g,_,f,v){if(this.viewingMode=t,this._layer=i,this._requester=n,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=d,this.holeFilling=l,this._isLoaded=h,this._isReloading=u,this._shouldLoadNode=c,this._enable=g,this._needsUpdate=_,this._computeVisibilityObb=f,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this.urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=P(0),this._visibilityCacheVersion=P(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new N(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,"page"===s.type){const e=s.rootPage;switch(this.urlPrefix=s.urlPrefix,this._pageSize=s.pageSize,s.lodMetric){case"maxScreenThreshold":this._lodMetric=1;break;case"maxScreenThresholdSQ":this._lodMetric=1,this._lodConversion=A}if(this._isEditable){this._rootIndex=-1;const t=S(s.rootIndex,s.pageSize),i=e.nodes[t],n={nodes:[{index:this._rootIndex,children:[s.rootIndex],mesh:void 0,obb:i.obb,lodThreshold:i.lodThreshold}]};this._addPage(R(this._rootIndex,this._pageSize),n),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=s.rootIndex;this._addPage(R(s.rootIndex,this._pageSize),e),this._updateParentsAndLevel()}else if("node"===s.type){this.urlPrefix=s.urlPrefix;const e=new m;if(this._nodePages.set(0,e),this._isEditable){this._clientNodePage=new m;const e={id:"-1",version:null,mbs:s.rootNode.mbs,obb:s.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:s.rootNode.mbs,obb:s.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(e.id,null),-1);const t=this._validateNode(e.id,e);t&&this._addNode(t,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(s.rootNode.id,null),-1);const t=this._validateNode(s.rootNode.id,s.rootNode);t&&this._addNode(t,0)}}addClientNodeToIndex(e,t){const i=-1,s=new a(e,t),n=this._makeClientRefNode(s,i);return this._linkChildToParentNode(i,n),this.requestUpdate(),n}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_canRequest(e){return!this._requester.isFull(e)}_loadPage(e){this._loadingPages.add(e);const i=this.urlPrefix+e;this._requester.request(i,"json").then(t=>this._pageQueue.push({pageIndex:e,page:t})).catch(i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach(e=>{let t=e.parentIndex;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this._getParentIndex(t)}})}}_addPage(e,t){const i=[],n=[],o=t.nodes.map((t,o)=>{const r=i.length,a=t.children?t.children.length:0;n.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=_.fromJSON(t.obb),u=s(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,m=t.mesh?.material,v={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=m?.resource?`${m.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:m?m.definition:-1},p=new d(l,C(o,e,this._pageSize),u,a,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return p.serviceObbInIndexSR=h,p.visibilityObbInRenderSR=this._computeVisibilityObb(p),p.vertexCount=g?g.vertexCount:0,new f(r,a,b(this._visibilityCacheVersion),null,p)}),r=new m(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,s)=>{const n=this._getPage(t);if(null!=n){const o=S(t,this._pageSize),r=n.nodes[o];r.parentIndex=null!=i?i:-1;const a=r.node;null!=a&&(a.level=s,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),s=this.getNode(i);if(null!=s)for(let e=0;e<s.childCount;e++){t(this.getChildIndex(s.index,e),i,s.level+1),this._maxLevel=Math.max(this._maxLevel,s.level+1)}}}_getPage(e){const t=R(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeDescriptor(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[S(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),s=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?s+1:s);const{lodMetric:n,maxError:o}=E(e.lodSelection),r=this._getNodeDescriptor(t),a=new d(e.id,t,e.mbs,r.childCount,s,e.resources,e.version,n,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=_.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.nodeBoundingData;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const s=i.nodes.length,n=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(n),n.parentIndex=t,e.invalidateServiceBVsInRenderSR(),s}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const s=-(i.nodes.length+1),n=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(n),n.parentIndex=t,e.invalidateServiceBVsInRenderSR(),s}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const s=S(e,this._pageSize),n=S(t,this._pageSize),o=i.nodes[s],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const d of i.nodes)d.childOffset>r&&(d.childOffset+=a);i.nodes[n].parentIndex=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const s=this._clientNodePage;if(null==s)return;const n=this._getParentIndex(e);if(null==n)return;const o=new Set,r=new Map,a=e=>{const i=S(e,this._pageSize),n=s.nodes[i];if(n.childCount>0)for(let t=n.childOffset;t<n.childOffset+n.childCount;++t)a(s.children[t]);const r=n.node?.id??n.nodeBoundingData?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(n)};a(e);const d=s.nodes,l=s.children,h=s.nodes.map(()=>-1),u=[],c=[];for(let g=0;g<d.length;++g){const e=d[g];if(o.has(e))continue;const t=u.length,s=C(g,-1,this._pageSize),n=C(t,-1,this._pageSize);if(e.node&&(e.node.index=n),h[g]=n,u.push(e),s!==n){const t=e.node?.id??e.nodeBoundingData?.id;if(null==t)throw new Error("Node has no id");i(t,s,n),r.set(s,n)}}for(let g=0;g<u.length;++g){const e=C(g,-1,this._pageSize),t=u[g],i=c.length;for(let s=t.childOffset;s<t.childOffset+t.childCount;++s){const t=l[s];if(t>=0)c.push(t);else{const i=S(t,this._pageSize),s=d[i];if(o.has(s))continue;const n=h[i];c.push(n),s.parentIndex=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}s.setNodes(u,c),this._updateParentBoundingInformation(h[S(n,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const s=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,d=this._getNodeDescriptor(t);if(null==d)return;for(let o=0;o<d.childCount;o++){const d=this.getChildIndex(t,o),l=this._getNodeDescriptor(d),h=null!=l?l.nodeBoundingData||l.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=n(h.serviceMbsInIndexSR,V);else{const t=O,n=L,o=B;i(h.serviceMbsInIndexSR,s,t,a),i(e,s,n,a),r(t,n,o),i(o,a,e,s)}}const l=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),n(e,t.serviceMbsInIndexSR)):h(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};l(d.nodeBoundingData),l(d.node),this.invalidateNodeVisibilityCacheInternal(d),t=this._getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeDescriptor(e),s=this._getPage(e);i.childOffset=s.children.length,i.childCount=t.length;for(let n=0;n<t.length;n++){const i=this._makeRefNode(t[n],e);s.children.push(i)}}getNode(e){const t=this._getNodeDescriptor(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes((i,s)=>{(null!=i.node&&i.node.id===e||null!=i.nodeBoundingData&&i.nodeBoundingData.id===e)&&(t=s)}),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const s=i.nodes[S(e,this._pageSize)];return i.children[s.childOffset+t]}_getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[S(e,this._pageSize)]?.parentIndex:null}getParent(e){const t=this._getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeDescriptor(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=P(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeDescriptor(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=b(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeDescriptor(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeDescriptor(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.nodeBoundingData;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeDescriptor(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.nodeBoundingData;return!t||t.elevationRangeValid}_updateElevationRange(e,t){const i=this._getNodeDescriptor(e);if(!i)return!1;const s=i?.node??i?.nodeBoundingData;if(!s)return!1;if(s.elevationRangeValid)return t?.expandElevationRange(s),!0;const n=new g;let o=!1;for(let d=0;d<i.childCount;d++){const t=this.getChildIndex(e,d),i=this._updateElevationRange(t,n);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(s,e,n)}n.elevationRangeMin!==1/0&&n.elevationRangeMax!==-1/0||n.expandElevationRangeValues(0,0);const{elevationRangeMin:r,elevationRangeMax:a}=s;return r===n.elevationRangeMin&&a===n.elevationRangeMax?(t?.expandElevationRange(s),!0):(i.node?.setElevationRange(n),i.nodeBoundingData?.setElevationRange(n),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(s),!0)}isNodeVisible(e){const t=this._getNodeDescriptor(e);if(null==t)return!0;const i=t.nodeBoundingData;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&I(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);const s=t.node,n=this._viewportQueries;if(s){const e=n.ensureElevationAgnosticBoundingVolume(s),i=n.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=n.getNodeObbInRenderSRIndependentOfElevationOffset(s);null!=t&&(o=n.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=s||null!=i)&&2===t.filterImpact){const e=null!=s?s.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):0}const o=null!=s&&1===t.filterImpact;let r=!(null!=s&&2===s.imModificationImpact)&&!o;if(r){const t=!s||i&&!s.visibilityObbInRenderSR?i??null:s;if(null!=t){this.needNodeElevationRange&&this._updateElevationRange(e);r=n.isNodeVisible(t)}}return t.visibilityCache=y(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeDescriptor(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&4===t.node.imModificationImpact)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,s,n){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let d=t.childOffset;d<r;++d){const e=o.children[d],t=this._getNodeDescriptor(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}s/=a.length;for(const d of a){const e=d.node.index;this._isLoaded(e)||this._isReloading(e)?(n.delta=Math.max(n.delta,i),n.coverage+=s):this._traverseCoverage(e,d,i+1,s,n)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeDescriptor(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(I(t.useAsHole,this._version))return x(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const s=i.delta*i.coverage<=.5;return t.useAsHole=y(s,this._version),s}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.prune(),this._prefetchNodes.prune(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=P(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{null!=e&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(null!=e){e.filterImpact=2;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this.resetUpdateState(e);let s=!0;const n=new M,o=new D,r=this._imModificationUncategorized;r.clear();const a=new Set;let d=0;const l=(a,l,h)=>{const u=e=>{this._shouldLoadNode(e)&&e.childCount&&(s=!1)};if(!l){const e=R(a,this._pageSize);let t=this._getNodeLoadPriority(a);return t===1/0&&(t=this._getNodeLoadPriority(h)),p.set(e,Math.max(t,p.get(e)||0)),this._loadingPages.has(e)||this._failedPages.has(e)||(this._missingPagesAndNodes.push(e),++d),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,t))}const{node:c,childCount:g}=l;if(this._updateNodeFeatureEstimate(c,o),!c){const e=this._getNodeLoadPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),p.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(!this._useNodePages&&0===this._missingPagesAndNodes.length)for(let e=0;e<g;e++){const t=_.children[l.childOffset+e],i=this._getNodeDescriptor(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(p.set(t,this._getNodeLoadPriority(t)),this._prefetchNodes.push(t))}if(c.failed||c.resources.isEmpty)return void u(c);if(this._isLoaded(a)){if(n.known+=c.memory,++n.knownNodes,u(c),this._shouldLoadNode(c)||(n.unremoved+=c.memory),this._needsUpdate(c)){const e=this._getNodeLoadPriority(a);p.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(c.memory&&(n.known+=c.memory,++n.knownNodes),!this._shouldLoadNode(c))return void(this._isReloading(a)&&this._updates.remove.push(a));if(u(c),c.memory?(n.missing+=c.memory,n.known+=c.memory,++n.knownNodes):++n.missingNodes,e.includes(c.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._getNodeLoadPriority(a)),void(this._updates.cancel=this._updates.cancel.filter(e=>e!==c.index));if(!t.done&&this._enable(c))return void t.madeProgress();const f=this._getNodeLoadPriority(a);p.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=c&&4===c.imModificationImpact&&r.push(a)};this.traverseVisible(l,a),this._frameNumber++,this._finalizeMissingNodesAndPages(),this._removeUnusedNodePages(a,d),this._handleModifications(i,r),this._updateUnloadedMemoryEstimate(n),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=s,this._updates.add.filterInPlace(e=>p.get(e)>=this._maxUnloadedPrio).sort((e,t)=>p.get(e)-p.get(t)),this._updates.update.sort((e,t)=>p.get(e)-p.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,p.clear()}_updateUnloadedMemoryEstimate(e){this._unloadedMemoryEstimate=e.missing-e.unremoved,e.knownNodes>3&&e.missingNodes>0&&(this._unloadedMemoryEstimate+=e.known/e.knownNodes*e.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate)}resetUpdateState(e){this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),p.clear()}_finalizeMissingNodesAndPages(){this._missingPagesAndNodes.sort((e,t)=>e-t),this._missingPagesAndNodes.filterInPlace((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e),this._missingPagesAndNodes.sort((e,t)=>p.get(e)-p.get(t)),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=p.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear())}_handleModifications(e,t){this.layerHasModifications&&0!==this._updates.add.length&&(t.length>0&&e?.(t),this._updates.add.filterInPlace(e=>{const t=this._getNodeDescriptor(e),i=null==t?.node||2!==t.node.imModificationImpact;return i||this.invalidateNodeVisibilityCache(e),i}))}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let s=t,n=t,o=i,r=10;for(;r--;){const i=new D;this._updateFeatureEstimate(s,i);if(this._computeFeatureEstimate(i)<=e){if(s>=t||i.missingNodes>0||0===r)break;o=s,s=.5*(s+n)}else n=s,s=.5*(s+o)}return this._version=P(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,s)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,s=this._nodePages,n=s.size+this._loadingPages.size+t;if(n>z&&n>i){const t=new Array;for(const[i,n]of s)0!==n.numNodesWithLoadedChildren||e.has(i)||t.push([n.lastTraversed,i]);t.sort((e,t)=>e[0]-t[0]).some(e=>{const t=e[1];return this._deleteNodePage(t),s.size<=z})}}_updateFeatureEstimate(e,t){this._version=P(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,i)=>this._updateNodeFeatureEstimate(i?.node,t))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._shouldLoadNode(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort((e,t)=>p.get(e)-p.get(t)),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest(this.urlPrefix))return!1;for(;e.length>0&&this._canRequest(this.urlPrefix);){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeDescriptor(t);if(!i)return null;let s=i?.traversalState;if(s&&I(s.version,this._version))return s;const n=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this._getParentIndex(t);if(null!=e){const t=this._getNodeDescriptor(e),i=t?.traversalState;r=!!i&&n>i.lodLevel}else r=n>0}else r=0===e.childCount;return s?(s.lodLevel=n,s.isChosen=r,s.version=y(!0,this._version),s):(s=new l(o,r,n,y(!0,this._version)),i.traversalState=s,s)}_loadNode(e){this._loadingNodes.add(e);const i=this._getNodeDescriptor(e).nodeBoundingData;if(null==i)return void this._failedNodes.add(e);const s=i.id,n=this.urlPrefix+s,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};(e>=0?this._requester.request(n,"json"):this._clientNodeLoader.loadNodeJSON(s)).catch(i=>{o(),t(i)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+n),this._failedNodes.add(e))}).then(t=>{o();const i=this._validateNode(s,t);if(null==i)return;i.obb&&this.invalidateNodeVisibilityCache(e);const n=this._addNode(i,e);this.nodeTraversalState(n)})}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const s=t.attributeData,n=this._layer.attributeStorageInfo;null==s||Array.isArray(s)&&!s.some((e,t)=>e.href!==`./attributes/${n?.[t]?.key??`f_${t}`}/0`)||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,d=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const s=new a(`${t.id}`,t.mbs);return s.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?_.fromJSON(t.obb):null,s.visibilityObbInRenderSR=this._computeVisibilityObb(s),s},l=Array.isArray(t.children)?t.children.map(d).filter(e=>null!=e):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new c(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},l,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{null!=e.node&&(e.node.failed=!1)})}_getNodeLoadPriority(e){const t=this._getNodeDescriptor(e),i=this._getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._getNodeLoadPriority(i);let s=0;if(t.node&&null!=i){const e=this._getNodeDescriptor(i);s=e.traversalState?.lodLevel??0}const n=10,o=this._hasLoadedAncestor(e)?0:n*this._viewportQueries.distCameraToPOI();return-(this._viewportQueries.distToPOI(t.nodeBoundingData??t.node)*(1+s)+s*n*this._viewportQueries.distCameraToPOI())+o}_hasLoadedAncestor(e){let t=this._getParentIndex(e);for(;null!=t;){if(this._isLoaded(t))return!0;t=this._getParentIndex(t)}return!1}traverseVisible(e,t){const i=this._getNodeDescriptor(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,s,n){const o=R(e,this._pageSize);if(n&&n.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&s(e,i,t));if(!this.isNodeVisible(e))return;if(s(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let d=0;d<i.childCount;d++){const t=a.children[i.childOffset+d],o=this._getNodeDescriptor(t);if(o)this._traverseVisible(t,e,o,s,n);else{if(n){const e=R(t,this._pageSize);n.add(e)}s(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,s=this._pageSize,n=R(i,s),o=this._getPageFromPageIndex(n);if(null==o)return;const r=this._frameNumber,a=this._nodePages,d=S(i,s),l=o.nodes[d],h=l.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=l,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let s=e;s<e+t;++s){const e=i[s];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let s=0;for(;s<u.length;){const n=u[s];++s;const o=-n-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:d}=r;if(0===d)continue;const{childOffset:l}=r,h=l+d;for(let e=l;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(s>0){let i=n*s,d=o,l=d.nodes;for(;e<g;){const n=c[e];let o;if(++e,i<=n&&n<i+s)o=d;else{const e=n/s|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,d=o,l=d.nodes,i=s*e}const h=l[n-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,p=v+_;for(let e=v;e<p;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const s=c[e++],n=i.nodes[s],o=n.node;if(!o||!t(o))continue;const{childCount:r}=n;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:d}=n,l=d+r;for(let e=d;e<l;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,s=e+t;i.childrenLoaded=s;const n=0===e?1:0===s?-1:0,o=i.index;if(0!==n){this._getPage(o).numNodesWithLoadedChildren+=n}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.nodeBoundingData?.invalidateElevationRange()})}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const s=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],s+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(R(e,this._pageSize)));for(const[i,s]of e)if(0!==s.numNodesWithLoadedChildren||t.has(i))for(const e of s.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){const t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const p=new Map;class N{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function b(e){return u(e,-2)}function P(e){return u(e,2)}function y(e,t){return t+(e?1:0)}function I(e,t){return(-2&e)===t}function x(e){return!(1&~e)}function R(e,t){return e<0?-1:t>0?e/t|0:0}function S(e,t){return e<0?-e-1:0===t?e:e%t}function C(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const w=[["maxScreenThreshold",1],["screenSpaceRelative",2],["removedFeatureDiameter",3],["distanceRangeFromDefaultCamera",4]];function E(e){if(e)for(let t=0;t<e.length;t++)for(const i of w)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:0,maxError:0}}class M{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class D{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function A(e){return Math.sqrt(e*(4/Math.PI))}const V=o(),O=o(),L=o(),B=o(),z=has("esri-mobile")?100:300;export{v as I3SIndex,E as selectErrorMetric};
|
|
5
|
+
import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{j as s,m as n,c as o,z as r}from"../../../../chunks/sphere.js";import{NodeBoundingData as a,Node as d,NodeTraversalState as l}from"./I3SNode.js";import{invalidateMbs as h,addWraparound as u}from"./I3SUtil.js";import{ValidatedNode as c}from"./ValidatedNode.js";import{ElevationRange as g}from"../../support/ElevationRange.js";import{Obb as _}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,i,s,n){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this._boundingData=s,this.node=n,this.parentIndex=-1,this.useAsHole=0,this.filterImpact=2,this.traversalState=null}get nodeBoundingData(){return this._boundingData}destroy(){this._boundingData=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.nodeBoundingData?.invalidateServiceBVsInRenderSR()}}class m{constructor(e=new Array,t=new Array){this._nodeDescriptors=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(const e of this._nodeDescriptors)e.destroy();this._nodeDescriptors.length=0,this._children.length=0}get nodes(){return this._nodeDescriptors}addNode(e){return this._nodeDescriptors.push(e),this._nodeDescriptors.length-1}setNodes(e,t){this._nodeDescriptors=e,this._children=t}get children(){return this._children}}class v{get _useNodePages(){return this._pageSize>0}constructor(t,i,s,n,o,r,d,l,h,u,c,g,_,f,v){if(this.viewingMode=t,this._layer=i,this._requester=n,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=d,this.holeFilling=l,this._isLoaded=h,this._isReloading=u,this._shouldLoadNode=c,this._enable=g,this._needsUpdate=_,this._computeVisibilityObb=f,this._computeNodeFiltering=v,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this.urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=P(0),this._visibilityCacheVersion=P(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._progressiveLoadPenaltyWeight=10,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new N(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,"page"===s.type){const e=s.rootPage;switch(this.urlPrefix=s.urlPrefix,this._pageSize=s.pageSize,s.lodMetric){case"maxScreenThreshold":this._lodMetric=1;break;case"maxScreenThresholdSQ":this._lodMetric=1,this._lodConversion=A}if(this._isEditable){this._rootIndex=-1;const t=S(s.rootIndex,s.pageSize),i=e.nodes[t],n={nodes:[{index:this._rootIndex,children:[s.rootIndex],mesh:void 0,obb:i.obb,lodThreshold:i.lodThreshold}]};this._addPage(R(this._rootIndex,this._pageSize),n),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=s.rootIndex;this._addPage(R(s.rootIndex,this._pageSize),e),this._updateParentsAndLevel()}else if("node"===s.type){this.urlPrefix=s.urlPrefix;const e=new m;if(this._nodePages.set(0,e),this._isEditable){this._clientNodePage=new m;const e={id:"-1",version:null,mbs:s.rootNode.mbs,obb:s.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:s.rootNode.mbs,obb:s.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(e.id,null),-1);const t=this._validateNode(e.id,e);t&&this._addNode(t,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(s.rootNode.id,null),-1);const t=this._validateNode(s.rootNode.id,s.rootNode);t&&this._addNode(t,0)}}addClientNodeToIndex(e,t){const i=-1,s=new a(e,t),n=this._makeClientRefNode(s,i);return this._linkChildToParentNode(i,n),this.requestUpdate(),n}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_canRequest(e){return!this._requester.isFull(e)}_loadPage(e){this._loadingPages.add(e);const i=this.urlPrefix+e;this._requester.request(i,"json").then(t=>this._pageQueue.push({pageIndex:e,page:t})).catch(i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach(e=>{let t=e.parentIndex;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this._getParentIndex(t)}})}}_addPage(e,t){const i=[],n=[],o=t.nodes.map((t,o)=>{const r=i.length,a=t.children?t.children.length:0;n.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const l=`${t.index}`,h=_.fromJSON(t.obb),u=s(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,m=t.mesh?.material,v={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=m?.resource?`${m.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:m?m.definition:-1},p=new d(l,C(o,e,this._pageSize),u,a,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return p.serviceObbInIndexSR=h,p.visibilityObbInRenderSR=this._computeVisibilityObb(p),p.vertexCount=g?g.vertexCount:0,new f(r,a,b(this._visibilityCacheVersion),null,p)}),r=new m(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,s)=>{const n=this._getPage(t);if(null!=n){const o=S(t,this._pageSize),r=n.nodes[o];r.parentIndex=null!=i?i:-1;const a=r.node;null!=a&&(a.level=s,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),s=this.getNode(i);if(null!=s)for(let e=0;e<s.childCount;e++){t(this.getChildIndex(s.index,e),i,s.level+1),this._maxLevel=Math.max(this._maxLevel,s.level+1)}}}_getPage(e){const t=R(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeDescriptor(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[S(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),s=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?s+1:s);const{lodMetric:n,maxError:o}=E(e.lodSelection),r=this._getNodeDescriptor(t),a=new d(e.id,t,e.mbs,r.childCount,s,e.resources,e.version,n,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=_.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const l=r.nodeBoundingData;return null!=l&&(null==l.serviceMbsInIndexSR&&(l.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(l),l.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const s=i.nodes.length,n=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(n),n.parentIndex=t,e.invalidateServiceBVsInRenderSR(),s}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const s=-(i.nodes.length+1),n=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(n),n.parentIndex=t,e.invalidateServiceBVsInRenderSR(),s}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const s=S(e,this._pageSize),n=S(t,this._pageSize),o=i.nodes[s],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const d of i.nodes)d.childOffset>r&&(d.childOffset+=a);i.nodes[n].parentIndex=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const s=this._clientNodePage;if(null==s)return;const n=this._getParentIndex(e);if(null==n)return;const o=new Set,r=new Map,a=e=>{const i=S(e,this._pageSize),n=s.nodes[i];if(n.childCount>0)for(let t=n.childOffset;t<n.childOffset+n.childCount;++t)a(s.children[t]);const r=n.node?.id??n.nodeBoundingData?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(n)};a(e);const d=s.nodes,l=s.children,h=s.nodes.map(()=>-1),u=[],c=[];for(let g=0;g<d.length;++g){const e=d[g];if(o.has(e))continue;const t=u.length,s=C(g,-1,this._pageSize),n=C(t,-1,this._pageSize);if(e.node&&(e.node.index=n),h[g]=n,u.push(e),s!==n){const t=e.node?.id??e.nodeBoundingData?.id;if(null==t)throw new Error("Node has no id");i(t,s,n),r.set(s,n)}}for(let g=0;g<u.length;++g){const e=C(g,-1,this._pageSize),t=u[g],i=c.length;for(let s=t.childOffset;s<t.childOffset+t.childCount;++s){const t=l[s];if(t>=0)c.push(t);else{const i=S(t,this._pageSize),s=d[i];if(o.has(s))continue;const n=h[i];c.push(n),s.parentIndex=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}s.setNodes(u,c),this._updateParentBoundingInformation(h[S(n,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const s=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,d=this._getNodeDescriptor(t);if(null==d)return;for(let o=0;o<d.childCount;o++){const d=this.getChildIndex(t,o),l=this._getNodeDescriptor(d),h=null!=l?l.nodeBoundingData||l.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=n(h.serviceMbsInIndexSR,V);else{const t=L,n=O,o=B;i(h.serviceMbsInIndexSR,s,t,a),i(e,s,n,a),r(t,n,o),i(o,a,e,s)}}const l=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),n(e,t.serviceMbsInIndexSR)):h(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};l(d.nodeBoundingData),l(d.node),this.invalidateNodeVisibilityCacheInternal(d),t=this._getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeDescriptor(e),s=this._getPage(e);i.childOffset=s.children.length,i.childCount=t.length;for(let n=0;n<t.length;n++){const i=this._makeRefNode(t[n],e);s.children.push(i)}}getNode(e){const t=this._getNodeDescriptor(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes((i,s)=>{(null!=i.node&&i.node.id===e||null!=i.nodeBoundingData&&i.nodeBoundingData.id===e)&&(t=s)}),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const s=i.nodes[S(e,this._pageSize)];return i.children[s.childOffset+t]}_getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[S(e,this._pageSize)]?.parentIndex:null}getParent(e){const t=this._getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeDescriptor(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=P(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeDescriptor(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=b(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeDescriptor(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeDescriptor(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.nodeBoundingData;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeDescriptor(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.nodeBoundingData;return!t||t.elevationRangeValid}_updateElevationRange(e,t){const i=this._getNodeDescriptor(e);if(!i)return!1;const s=i?.node??i?.nodeBoundingData;if(!s)return!1;if(s.elevationRangeValid)return t?.expandElevationRange(s),!0;const n=new g;let o=!1;for(let d=0;d<i.childCount;d++){const t=this.getChildIndex(e,d),i=this._updateElevationRange(t,n);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(s,e,n)}n.elevationRangeMin!==1/0&&n.elevationRangeMax!==-1/0||n.expandElevationRangeValues(0,0);const{elevationRangeMin:r,elevationRangeMax:a}=s;return r===n.elevationRangeMin&&a===n.elevationRangeMax?(t?.expandElevationRange(s),!0):(i.node?.setElevationRange(n),i.nodeBoundingData?.setElevationRange(n),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(s),!0)}isNodeVisible(e){const t=this._getNodeDescriptor(e);if(null==t)return!0;const i=t.nodeBoundingData;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&I(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);const s=t.node,n=this._viewportQueries;if(s){const e=n.ensureElevationAgnosticBoundingVolume(s),i=n.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=n.getNodeObbInRenderSRIndependentOfElevationOffset(s);null!=t&&(o=n.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=s||null!=i)&&2===t.filterImpact){const e=null!=s?s.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):0}const o=null!=s&&1===t.filterImpact;let r=!(null!=s&&2===s.imModificationImpact)&&!o;if(r){const t=!s||i&&!s.visibilityObbInRenderSR?i??null:s;if(null!=t){this.needNodeElevationRange&&this._updateElevationRange(e);r=n.isNodeVisible(t)}}return t.visibilityCache=y(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeDescriptor(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&4===t.node.imModificationImpact)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,s,n){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let d=t.childOffset;d<r;++d){const e=o.children[d],t=this._getNodeDescriptor(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}s/=a.length;for(const d of a){const e=d.node.index;this._isLoaded(e)||this._isReloading(e)?(n.delta=Math.max(n.delta,i),n.coverage+=s):this._traverseCoverage(e,d,i+1,s,n)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeDescriptor(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(I(t.useAsHole,this._version))return x(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const s=i.delta*i.coverage<=.5;return t.useAsHole=y(s,this._version),s}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.prune(),this._prefetchNodes.prune(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=P(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{null!=e&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(null!=e){e.filterImpact=2;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this.resetUpdateState(e);let s=!0;const n=new M,o=new D,r=this._imModificationUncategorized;r.clear();const a=new Set;let d=0;const l=(a,l,h)=>{const u=e=>{this._shouldLoadNode(e)&&e.childCount&&(s=!1)};if(!l){const e=R(a,this._pageSize);let t=this._getNodeLoadPriority(a);return t===1/0&&(t=this._getNodeLoadPriority(h)),p.set(e,Math.max(t,p.get(e)||0)),this._loadingPages.has(e)||this._failedPages.has(e)||(this._missingPagesAndNodes.push(e),++d),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,t))}const{node:c,childCount:g}=l;if(this._updateNodeFeatureEstimate(c,o),!c){const e=this._getNodeLoadPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),p.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const _=this._getPage(a);if(!this._useNodePages&&0===this._missingPagesAndNodes.length)for(let e=0;e<g;e++){const t=_.children[l.childOffset+e],i=this._getNodeDescriptor(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(p.set(t,this._getNodeLoadPriority(t)),this._prefetchNodes.push(t))}if(c.failed||c.resources.isEmpty)return void u(c);if(this._isLoaded(a)){if(n.known+=c.memory,++n.knownNodes,u(c),this._shouldLoadNode(c)||(n.unremoved+=c.memory),this._needsUpdate(c)){const e=this._getNodeLoadPriority(a);p.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(c.memory&&(n.known+=c.memory,++n.knownNodes),!this._shouldLoadNode(c))return void(this._isReloading(a)&&this._updates.remove.push(a));if(u(c),c.memory?(n.missing+=c.memory,n.known+=c.memory,++n.knownNodes):++n.missingNodes,e.includes(c.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._getNodeLoadPriority(a)),void(this._updates.cancel=this._updates.cancel.filter(e=>e!==c.index));if(!t.done&&this._enable(c))return void t.madeProgress();const f=this._getNodeLoadPriority(a);p.set(a,f),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,f),this._updates.add.push(a),this.layerHasModifications&&i&&null!=c&&4===c.imModificationImpact&&r.push(a)};this.traverseVisible(l,a),this._frameNumber++,this._finalizeMissingNodesAndPages(),this._removeUnusedNodePages(a,d),this._handleModifications(i,r),this._updateUnloadedMemoryEstimate(n),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=s,this._updates.add.filterInPlace(e=>p.get(e)>=this._maxUnloadedPrio).sort((e,t)=>p.get(e)-p.get(t)),this._updates.update.sort((e,t)=>p.get(e)-p.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,p.clear()}_updateUnloadedMemoryEstimate(e){this._unloadedMemoryEstimate=e.missing-e.unremoved,e.knownNodes>3&&e.missingNodes>0&&(this._unloadedMemoryEstimate+=e.known/e.knownNodes*e.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate)}resetUpdateState(e){this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),p.clear()}_finalizeMissingNodesAndPages(){this._missingPagesAndNodes.sort((e,t)=>e-t),this._missingPagesAndNodes.filterInPlace((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e),this._missingPagesAndNodes.sort((e,t)=>p.get(e)-p.get(t)),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=p.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear())}_handleModifications(e,t){this.layerHasModifications&&0!==this._updates.add.length&&(t.length>0&&e?.(t),this._updates.add.filterInPlace(e=>{const t=this._getNodeDescriptor(e),i=null==t?.node||2!==t.node.imModificationImpact;return i||this.invalidateNodeVisibilityCache(e),i}))}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let s=t,n=t,o=i,r=10;for(;r--;){const i=new D;this._updateFeatureEstimate(s,i);if(this._computeFeatureEstimate(i)<=e){if(s>=t||i.missingNodes>0||0===r)break;o=s,s=.5*(s+n)}else n=s,s=.5*(s+o)}return this._version=P(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,s)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,s=this._nodePages,n=s.size+this._loadingPages.size+t;if(n>z&&n>i){const t=new Array;for(const[i,n]of s)0!==n.numNodesWithLoadedChildren||e.has(i)||t.push([n.lastTraversed,i]);t.sort((e,t)=>e[0]-t[0]).some(e=>{const t=e[1];return this._deleteNodePage(t),s.size<=z})}}_updateFeatureEstimate(e,t){this._version=P(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,i)=>this._updateNodeFeatureEstimate(i?.node,t))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._shouldLoadNode(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort((e,t)=>p.get(e)-p.get(t)),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest(this.urlPrefix))return!1;for(;e.length>0&&this._canRequest(this.urlPrefix);){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeDescriptor(t);if(!i)return null;let s=i?.traversalState;if(s&&I(s.version,this._version))return s;const n=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this._getParentIndex(t);if(null!=e){const t=this._getNodeDescriptor(e),i=t?.traversalState;r=!!i&&n>i.lodLevel}else r=n>0}else r=0===e.childCount;return s?(s.lodLevel=n,s.isChosen=r,s.version=y(!0,this._version),s):(s=new l(o,r,n,y(!0,this._version)),i.traversalState=s,s)}_loadNode(e){this._loadingNodes.add(e);const i=this._getNodeDescriptor(e).nodeBoundingData;if(null==i)return void this._failedNodes.add(e);const s=i.id,n=this.urlPrefix+s,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};(e>=0?this._requester.request(n,"json"):this._clientNodeLoader.loadNodeJSON(s)).catch(i=>{o(),t(i)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+n),this._failedNodes.add(e))}).then(t=>{o();const i=this._validateNode(s,t);if(null==i)return;i.obb&&this.invalidateNodeVisibilityCache(e);const n=this._addNode(i,e);this.nodeTraversalState(n)})}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const s=t.attributeData,n=this._layer.attributeStorageInfo;null==s||Array.isArray(s)&&!s.some((e,t)=>e.href!==`./attributes/${n?.[t]?.key??`f_${t}`}/0`)||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,d=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const s=new a(`${t.id}`,t.mbs);return s.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?_.fromJSON(t.obb):null,s.visibilityObbInRenderSR=this._computeVisibilityObb(s),s},l=Array.isArray(t.children)?t.children.map(d).filter(e=>null!=e):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new c(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},l,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{null!=e.node&&(e.node.failed=!1)})}_getNodeLoadPriority(e){const t=this._getNodeDescriptor(e),i=this._getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._getNodeLoadPriority(i);let s=0;if(t.node&&null!=i){const e=this._getNodeDescriptor(i);s=e.traversalState?.lodLevel??0}const n=this._getHoleBonus(e);return-(this._viewportQueries.distToCameraPOIRay(t.nodeBoundingData??t.node)*(1+s)+s*this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI())+n}_getHoleBonus(e){return this._hasLoadedAncestor(e)?0:this._progressiveLoadPenaltyWeight*this._viewportQueries.distCameraToPOI()}_hasLoadedAncestor(e){let t=this._getParentIndex(e);for(;null!=t;){if(this._isLoaded(t))return!0;t=this._getParentIndex(t)}return!1}traverseVisible(e,t){const i=this._getNodeDescriptor(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,s,n){const o=R(e,this._pageSize);if(n&&n.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&s(e,i,t));if(!this.isNodeVisible(e))return;if(s(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let d=0;d<i.childCount;d++){const t=a.children[i.childOffset+d],o=this._getNodeDescriptor(t);if(o)this._traverseVisible(t,e,o,s,n);else{if(n){const e=R(t,this._pageSize);n.add(e)}s(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,s=this._pageSize,n=R(i,s),o=this._getPageFromPageIndex(n);if(null==o)return;const r=this._frameNumber,a=this._nodePages,d=S(i,s),l=o.nodes[d],h=l.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=l,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let s=e;s<e+t;++s){const e=i[s];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let s=0;for(;s<u.length;){const n=u[s];++s;const o=-n-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:d}=r;if(0===d)continue;const{childOffset:l}=r,h=l+d;for(let e=l;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(s>0){let i=n*s,d=o,l=d.nodes;for(;e<g;){const n=c[e];let o;if(++e,i<=n&&n<i+s)o=d;else{const e=n/s|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,d=o,l=d.nodes,i=s*e}const h=l[n-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,p=v+_;for(let e=v;e<p;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const s=c[e++],n=i.nodes[s],o=n.node;if(!o||!t(o))continue;const{childCount:r}=n;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:d}=n,l=d+r;for(let e=d;e<l;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,s=e+t;i.childrenLoaded=s;const n=0===e?1:0===s?-1:0,o=i.index;if(0!==n){this._getPage(o).numNodesWithLoadedChildren+=n}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.nodeBoundingData?.invalidateElevationRange()})}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const s=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],s+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(R(e,this._pageSize)));for(const[i,s]of e)if(0!==s.numNodesWithLoadedChildren||t.has(i))for(const e of s.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){const t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const p=new Map;class N{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function b(e){return u(e,-2)}function P(e){return u(e,2)}function y(e,t){return t+(e?1:0)}function I(e,t){return(-2&e)===t}function x(e){return!(1&~e)}function R(e,t){return e<0?-1:t>0?e/t|0:0}function S(e,t){return e<0?-e-1:0===t?e:e%t}function C(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const w=[["maxScreenThreshold",1],["screenSpaceRelative",2],["removedFeatureDiameter",3],["distanceRangeFromDefaultCamera",4]];function E(e){if(e)for(let t=0;t<e.length;t++)for(const i of w)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:0,maxError:0}}class M{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class D{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function A(e){return Math.sqrt(e*(4/Math.PI))}const V=o(),L=o(),O=o(),B=o(),z=has("esri-mobile")?100:300;export{v as I3SIndex,E as selectErrorMetric};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{n as e,a as t,f as i,c as s,d as n,H as r,x as o,h as a,F as c,s as u,k as l,b as h,m as d,e as m,g as _}from"../../../../chunks/vec32.js";import{create as p}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as v}from"../../../../geometry/ellipsoidUtils.js";import{getSphericalPCPF as g}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBoundingSphere as b}from"../../../../geometry/projection/projectBoundingSphere.js";import{getProjector as R}from"../../../../geometry/projection/projectors.js";import{create as S,fromMatrix as x,createPoints as M,intersectsSphere as C}from"../../../../geometry/support/frustum.js";import{getNormal as I,signedDistance as P}from"../../../../geometry/support/plane.js";import{isPlateCarree as E}from"../../../../geometry/support/spatialReferenceUtils.js";import{m as F,a as D}from"../../../../chunks/sphere.js";import{makeDehydratedPoint as O}from"../../../../layers/graphics/dehydratedPoint.js";import{evaluateElevationAlignmentAtPoint as A}from"../graphics/elevationAlignmentUtils.js";import{ElevationContext as B}from"../graphics/ElevationContext.js";import{createContextWithoutExpressionSupport as V,extractExpressionInfo as j}from"../graphics/featureExpressionInfoUtils.js";import{isValidMbs as L,intersectBoundingRectWithMbs as y}from"./I3SUtil.js";import{Obb as w,computeOffsetObb as U}from"../../support/orientedBoundingBox.js";const k=1e5;class q{get _frustumMbsCenter(){return this._frustumMbs}get _frustumMbsRadius(){return this._frustumMbs[3]}get _frustumPlanes(){return this._frustum}constructor(e,t,i,s,n,r,o,a,c={}){this._indexSR=e,this._renderCoordsHelper=t,this._clippingArea=n,this._elevationProvider=r,this._viewingMode=o,this._options=c,this._frustum=S(),this._frustumMbs=f(),this._useFrustumCulling=!1,this._poi=p(),this._elevationContext=null,this.minDistance=1/0,this.maxDistance=0,this.maxLodLevel=2,this._tmpObb=new w,this._tmp1=p(),this._tmp2=p(),this._tmp3=p(),this._tmp0=p(),this._screenspaceErrorBias=c.screenspaceErrorBias||1,this._progressiveLoadFactor=c.progressiveLoadFactor||1,this.updateCamera(i,s);const u=this._renderCoordsHelper.spatialReference;this._renderSR=u,this._renderSRSphericalPCPF=g(u),this._isGlobalMode=u===this._renderSRSphericalPCPF,this.updateElevationInfo(a),this._tmpPoint=O(0,0,0,e),this._isECEFOBBInLocalMode=this._indexSR.isWGS84&&(u.isWebMercator||E(u)),this._indexSREllipsoidRadius=v(this._indexSR).radius,this._indexSRSphericalPCPF=g(e),this._projectorIndexSRToIndexSRSphericalPCPF=R(this._indexSR,this._indexSRSphericalPCPF)}updateElevationInfo(e){null!=e?(this._elevationContext=B.fromElevationInfo(e),this._elevationContext.setFeatureExpressionInfoContext(V(j(e,!1)))):this._elevationContext=null}updateCamera(n,r){if(this._useFrustumCulling=r,r){x(n.viewMatrix,n.projectionMatrix,this._frustum,N);{const r=n.eye,o=G;e(o,n.viewForward);const a=T;t(a,N[4],r);const c=.5*i(a,a)/i(o,a),u=this._frustumMbs;s(u,r,o,c);const l=1+c;u[3]=l}}this._screenSizeFactor=1/(n.perScreenPixelRatio/2),this._camPos=n.eye,this.minDistance=1/0,this.maxDistance=0}setPointOfInterest(e){this._poi=e}updateScreenSpaceErrorBias(e){const t=this._screenspaceErrorBias;return this._screenspaceErrorBias=e,t}updateClippingArea(e){this._clippingArea=e}expandElevationRange(e,t,i){if(null==this._elevationContext)return;const s=e.serviceMbsInIndexSR;if(!s)return;const n="relative-to-scene"===this._elevationContext.mode?"scene":"ground";if(this._elevationProvider.getSphereElevationBounds){const e=this._elevationProvider.getSphereElevationBounds(s,this._indexSR,n);if(e)return void i.expandElevationRange(e)}const r=s[0],o=s[1],a=s[2],c=this._elevationProvider.getElevation(r,o,a,this._indexSR,n);c&&i.expandElevationRangeValues(c,c);const u=t?null:this._elevationProvider.getRootElevationBounds?.();u&&i.expandElevationRange(u)}getServiceMbsInRenderSR(e){const t=e.serviceMbsInRenderSR;if(L(t))return t;const{serviceMbsInIndexSR:i}=e;i&&F(i,t);const s=e.elevationRangeMin;if(this._elevationContext&&Number.isFinite(s)){let i=0,n=0;const r=e.elevationRangeMax;switch(this._elevationContext.mode){case"relative-to-ground":case"relative-to-scene":i=this._elevationContext.geometryZWithOffset(t[2],this._renderCoordsHelper)+s-t[2],n=r-s;break;case"on-the-ground":i=s-t[2],n=r-s}t[2]+=i+.5*n,t[3]+=.5*n}else this._elevationContext&&t[3]<k&&(this._tmpPoint.x=t[0],this._tmpPoint.y=t[1],this._tmpPoint.z=t[2],t[2]=A(this._tmpPoint,this._elevationProvider,this._elevationContext,this._renderCoordsHelper));return b(t,this._indexSR,t,this._renderSR),t}getAndUpdateVisibilityObbInRenderSR(e){{const t=e.visibilityObbInRenderSR;if(t)return t}const t=.01*this._indexSREllipsoidRadius,{serviceMbsInIndexSR:i,serviceObbInIndexSR:s}=e;if(null==s||!i||!s.isValid||this._isECEFOBBInLocalMode&&(s.halfSizeX>t||s.halfSizeY>t||s.halfSizeZ>t))return null;{let t=e.serviceObbInRenderSR;if(null==t)t=new w,e.serviceObbInRenderSR=t;else if(t.isValid)return t;const n=i[3];let r=0,o=0;const a=s.centerZ,c=this._renderCoordsHelper,u=this._elevationContext;if(u&&e.elevationRangeValid){const t=e.elevationRangeMin,i=e.elevationRangeMax;switch(u.mode){case"relative-to-ground":case"relative-to-scene":r=u.geometryZWithOffset(a,c)+t-a,o=i-t;break;case"on-the-ground":r=t-a,o=i-t}}else if(u&&n<k){const e=this._tmpPoint;e.x=s.centerX,e.y=s.centerY,e.z=a,r=A(e,this._elevationProvider,u,c)-a}const l=o>0,h=l?this._tmpObb:t;return s.transform(h,this._indexSR,this._renderSR,r,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),l&&U(h,0,o,this._viewingMode,t),t}}getNodeObbInRenderSRIndependentOfElevationOffset(e){{const t=e.visibilityObbInRenderSR??e.serviceObbInRenderSR??null;if(t?.isValid)return t}const t=e.serviceObbInIndexSR;return t?(t.transform(Y,this._indexSR,this._renderSR,void 0,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),Y):null}ensureElevationAgnosticBoundingVolume(e){return!e.elevationAgnosticBoundingVolume.valid&&e.level>0&&(1===this._viewingMode?this._updateElevationAgnosticBoundingVolumeGlobal(e):this._updateElevationAgnosticBoundingVolumeLocal(e)),e.elevationAgnosticBoundingVolume}_updateElevationAgnosticBoundingVolumeGlobal(t){const s=this.getNodeObbInRenderSRIndependentOfElevationOffset(t),o=t.elevationAgnosticBoundingVolume;let a,c=-1;if(s){const t=J;s.getCenter(t),e(t,t),a=t,s.getCorners(K);for(const s of K){e(s,s);const n=i(s,t);if(n<=0)return void o.invalidate();const r=Math.sqrt(1-n*n);c=Math.max(c,r)}}else{const i=t.serviceMbsInRenderSR;if(!L(i))return void o.invalidate();{const t=n(J,D(i)),s=i[3],u=r(t);if(u<s)return void o.invalidate();c=s/u,e(t,t),a=t}}const u=.001;o.set(a,c+u)}_updateElevationAgnosticBoundingVolumeLocal(e){const t=e.elevationAgnosticBoundingVolume,i=this.getNodeObbInRenderSRIndependentOfElevationOffset(e);if(i){const e=i.getCenter(J);e[2]=0;let s=0;const n=Q;i.getCorners(K);for(const t of K){t[2]=0;const e=o(n,t);s=Math.max(s,e)}t.set(e,Math.sqrt(s))}else{const i=e.serviceMbsInRenderSR;if(L(i)){const e=n(J,D(i));e[2]=0,t.set(e,i[3])}}}isNodeVisible(e){const t=this.getServiceMbsInRenderSR(e);if(!this._isMBSinClippingArea(t))return!1;if(!this._useFrustumCulling)return!0;const i=this.getAndUpdateVisibilityObbInRenderSR(e);return i?i.doesIntersectFrustumConservativeApproximation(this._frustum):C(this._frustum,t)}isElevationAgnosticBoundingVolumeVisible(e){return!this._useFrustumCulling||(!e.valid||(1===this._viewingMode?this._isConeVisibleInFrustum(e):this._isCylinderVisibleInFrustum(e)))}_isConeVisibleInFrustum(n){if(!this._isConeVisibleInFrustumMbs(n))return!1;const r=n.radius;if(-1===r||r>.9)return!0;const o=this._frustumPlanes,c=this._frustumMbsCenter,u=n.getAxis(ie),l=i(u,c),h=this._frustumMbsRadius,d=l-h,m=l+h;if(d<=0)return!0;const _=a(W,u,d),p=a(Z,u,m),f=r/Math.sqrt(1-r*r);for(const v of o){const n=I(v),r=e(X,n),o=i(r,u);if(Math.abs(1-o)<.01)continue;const c=$;a(c,u,o),t(c,c,r),e(c,c);const l=ee;s(l,_,c,d*f);if(P(v,l)<=0)continue;s(l,p,c,m*f);if(P(v,l)<=0)continue;return!1}return!0}_isConeVisibleInFrustumMbs(e){const t=e.radius;if(t>.9)return!0;const s=this._frustumMbsRadius,n=this._frustumMbsCenter,o=r(n);if(o<=s)return!0;const u=e.getAxis(ie),l=i(u,n);{const e=a(H,u,l);if(c(e,n)<s)return!0}const h=l/o;if(l<=0){return-h<s}const d=Math.sqrt(1-h*h);if(d<t)return!0;const m=s/o;return d*Math.sqrt(1-m*m)-m*h<t}isObbVisibleIndependentOfElevation(e,t){if(!this._useFrustumCulling)return!0;if(!e.valid)return!0;const s=this._frustumMbsRadius,n=this._frustumMbsCenter,r=this._frustumPlanes,o=K;if(t.getCorners(o),1===this._viewingMode){const t=e.getAxis(ie),c=i(t,n),u=c-s,l=c+s;if(u<=0)return!0;for(const e of r){let s=!0;for(const n of o){const r=i(n,t),o=te;if(a(o,n,u/r),P(e,o)<=0){s=!1;break}const c=te;if(a(c,n,l/r),P(e,c)<=0){s=!1;break}}if(s)return!1}}else{const e=n[2]-s,t=n[2]+s;for(const i of r){let s=!0;const n=I(i),r=n[0],a=n[1],c=n[2],u=i[3];for(const i of o){const n=r*i[0]+a*i[1]+u;if(n+c*e<=0||n+c*t<=0){s=!1;break}}if(s)return!1}}return!0}_isCylinderVisibleInFrustum(e){const t=this._frustumMbsCenter,i=this._frustumMbsRadius,s=n(H,t);s[2]=0;const r=e.radius,o=e.getAxis(ie);return c(s,o)<=r+i}isGeometryVisible(e){if(!this._useFrustumCulling)return!0;const t=e.geometryObbInRenderSR;return t?.doesIntersectFrustumConservativeApproximation(this._frustum)??this.isNodeVisible(e)}_isMBSinClippingArea(e){return null==this._clippingArea||0!==y(this._clippingArea,e)}_screenSpaceDiameterMbs(e,t){const i=this.getServiceMbsInRenderSR(e),s=Math.sqrt(u(D(i),this._camPos)),n=s-i[3];return this._updateMinMaxDistance(s),n<0?.5*Number.MAX_VALUE:t/n*this._screenSizeFactor}calcCameraDistance(e){return this.calcCameraDistanceToCenter(e)-this.getServiceMbsInRenderSR(e)[3]}calcCameraDistanceToCenter(e){const t=this.getServiceMbsInRenderSR(e),i=l(D(t),this._camPos);return this._updateMinMaxDistance(i),i}calcAngleDependentLoD(e){const t=this.getServiceMbsInRenderSR(e),i=t[3],s=(Math.abs(t[0]*(t[0]-this._camPos[0])+t[1]*(t[1]-this._camPos[1])+t[2]*(t[2]-this._camPos[2]))/h(D(t))+i)/l(D(t),this._camPos);return Math.min(1,s)}hasLOD(e){return 0!==e.lodMetric}_getDistanceGlobeMode(e,t){const s=h(D(t)),n=h(e)-s;a(this._tmp0,e,i(e,D(t))/d(e));const r=u(D(t),this._tmp0),o=t[3];if(r<=o*o)return Math.abs(n);{const r=a(this._tmp0,D(t),1/s),c=s,u=o*o/2/c,d=a(this._tmp1,r,c-u),p=e,f=m(this._tmp2,p,d),v=m(this._tmp2,f,a(this._tmp3,r,i(r,f))),g=_(this._tmp2,d,a(this._tmp2,v,o/h(v)));let b=l(p,g);if(n>=2e5){const e=m(this._tmp1,p,g);let t=i(e,r)/h(e);t<.08&&(t=1e-4),b/=t}return b}}_getDistance(e,t){return this._isGlobalMode?this._getDistanceGlobeMode(e,t):z(e,t)}_updateMinMaxDistance(e){e>0?(this.minDistance=Math.min(this.minDistance,e),this.maxDistance=Math.max(this.maxDistance,e)):(this.minDistance=0,this.maxDistance=Math.max(this.maxDistance,-e))}getLodLevel(e){if(0===e.lodMetric)return 0;if(0===e.childCount)return this.maxLodLevel;if(this._useFrustumCulling&&this._progressiveLoadFactor<1){const t=this._progressiveLoadFactor*this._screenspaceErrorBias,i=this._screenspaceErrorBias;return this.evaluateLODmetric(e,t)?this.evaluateLODmetric(e,i)?2:1:0}return this.evaluateLODmetric(e,this._screenspaceErrorBias)?this.maxLodLevel:0}evaluateLODmetric(e,t){switch(e.lodMetric){case 2:{const i=this.getServiceMbsInRenderSR(e),s=this._getDistance(this._camPos,i),n=2*s/this._screenSizeFactor,r=s+i[3];return this._updateMinMaxDistance(r),e.maxError*t<=n}case 1:{let i=this._screenSpaceDiameterMbs(e,e.serviceMbsInIndexSR[3]*t);return this._options.angleDependentLoD&&(i*=this.calcAngleDependentLoD(e)),i<e.maxError}case 3:return this._screenSpaceDiameterMbs(e,e.maxError)*t<10;case 4:return this.calcCameraDistance(e)>e.maxError*t}return!1}distToPOI(e){if(null==e)return 0;const t=this.getServiceMbsInRenderSR(e);return l(D(t),this._poi)-t[3]}distCameraToPOI(){return l(this._camPos,this._poi)}}function z(e,t){const i=e[0]-t[0],s=e[1]-t[1],n=e[2]-t[2],r=i*i+s*s,o=t[3];if(r<=o*o)return Math.abs(n);const a=Math.sqrt(r)-o;return Math.sqrt(n*n+a*a)}const G=p(),N=M(),T=p(),H=p(),W=p(),Z=p(),X=p(),Y=new w,J=p(),K=[p(),p(),p(),p(),p(),p(),p(),p()],Q=p(),$=p(),ee=p(),te=p(),ie=p();export{q as default};
|
|
5
|
+
import{n as e,a as t,f as i,c as s,G as n,e as r,d as o,H as a,x as c,h,F as u,s as l,k as d,b as m,m as _,g as p}from"../../../../chunks/vec32.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as v}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{getReferenceEllipsoid as g}from"../../../../geometry/ellipsoidUtils.js";import{getSphericalPCPF as b}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{projectBoundingSphere as R}from"../../../../geometry/projection/projectBoundingSphere.js";import{getProjector as S}from"../../../../geometry/projection/projectors.js";import{create as x,fromMatrix as M,createPoints as C,intersectsSphere as I}from"../../../../geometry/support/frustum.js";import{getNormal as P,signedDistance as D}from"../../../../geometry/support/plane.js";import{isPlateCarree as E}from"../../../../geometry/support/spatialReferenceUtils.js";import{m as O,a as F}from"../../../../chunks/sphere.js";import{makeDehydratedPoint as A}from"../../../../layers/graphics/dehydratedPoint.js";import{evaluateElevationAlignmentAtPoint as B}from"../graphics/elevationAlignmentUtils.js";import{ElevationContext as V}from"../graphics/ElevationContext.js";import{createContextWithoutExpressionSupport as j,extractExpressionInfo as L}from"../graphics/featureExpressionInfoUtils.js";import{isValidMbs as y,intersectBoundingRectWithMbs as w}from"./I3SUtil.js";import{Obb as q,computeOffsetObb as G}from"../../support/orientedBoundingBox.js";const U=1e5;class k{get _frustumMbsCenter(){return this._frustumMbs}get _frustumMbsRadius(){return this._frustumMbs[3]}get _frustumPlanes(){return this._frustum}constructor(e,t,i,s,n,r,o,a,c={}){this._indexSR=e,this._renderCoordsHelper=t,this._clippingArea=n,this._elevationProvider=r,this._viewingMode=o,this._options=c,this._frustum=x(),this._frustumMbs=v(),this._viewDirection=f(),this._useFrustumCulling=!1,this._poi=f(),this._cameraPOIDirection=f(),this._elevationContext=null,this.minDistance=1/0,this.maxDistance=0,this.maxLodLevel=2,this._tmpObb=new q,this._tmp1=f(),this._tmp2=f(),this._tmp3=f(),this._tmp0=f(),this._screenspaceErrorBias=c.screenspaceErrorBias||1,this._progressiveLoadFactor=c.progressiveLoadFactor||1,this.updateCamera(i,s);const h=this._renderCoordsHelper.spatialReference;this._renderSR=h,this._renderSRSphericalPCPF=b(h),this._isGlobalMode=h===this._renderSRSphericalPCPF,this.updateElevationInfo(a),this._tmpPoint=A(0,0,0,e),this._isECEFOBBInLocalMode=this._indexSR.isWGS84&&(h.isWebMercator||E(h)),this._indexSREllipsoidRadius=g(this._indexSR).radius,this._indexSRSphericalPCPF=b(e),this._projectorIndexSRToIndexSRSphericalPCPF=S(this._indexSR,this._indexSRSphericalPCPF)}updateElevationInfo(e){null!=e?(this._elevationContext=V.fromElevationInfo(e),this._elevationContext.setFeatureExpressionInfoContext(j(L(e,!1)))):this._elevationContext=null}updateCamera(n,r){if(this._useFrustumCulling=r,e(this._viewDirection,n.viewForward),r){M(n.viewMatrix,n.projectionMatrix,this._frustum,N);{const e=n.eye,r=T;t(r,N[4],e);const o=.5*i(r,r)/i(this._viewDirection,r),a=this._frustumMbs;s(a,e,this._viewDirection,o);const c=1+o;a[3]=c}}this._screenSizeFactor=1/(n.perScreenPixelRatio/2),this._camPos=n.eye,this._updateCameraPOIDirection(),this.minDistance=1/0,this.maxDistance=0}setPointOfInterest(e){this._poi=e,this._updateCameraPOIDirection()}updateScreenSpaceErrorBias(e){const t=this._screenspaceErrorBias;return this._screenspaceErrorBias=e,t}updateClippingArea(e){this._clippingArea=e}expandElevationRange(e,t,i){if(null==this._elevationContext)return;const s=e.serviceMbsInIndexSR;if(!s)return;const n="relative-to-scene"===this._elevationContext.mode?"scene":"ground";if(this._elevationProvider.getSphereElevationBounds){const e=this._elevationProvider.getSphereElevationBounds(s,this._indexSR,n);if(e)return void i.expandElevationRange(e)}const r=s[0],o=s[1],a=s[2],c=this._elevationProvider.getElevation(r,o,a,this._indexSR,n);c&&i.expandElevationRangeValues(c,c);const h=t?null:this._elevationProvider.getRootElevationBounds?.();h&&i.expandElevationRange(h)}getServiceMbsInRenderSR(e){const t=e.serviceMbsInRenderSR;if(y(t))return t;const{serviceMbsInIndexSR:i}=e;i&&O(i,t);const s=e.elevationRangeMin;if(this._elevationContext&&Number.isFinite(s)){let i=0,n=0;const r=e.elevationRangeMax;switch(this._elevationContext.mode){case"relative-to-ground":case"relative-to-scene":i=this._elevationContext.geometryZWithOffset(t[2],this._renderCoordsHelper)+s-t[2],n=r-s;break;case"on-the-ground":i=s-t[2],n=r-s}t[2]+=i+.5*n,t[3]+=.5*n}else this._elevationContext&&t[3]<U&&(this._tmpPoint.x=t[0],this._tmpPoint.y=t[1],this._tmpPoint.z=t[2],t[2]=B(this._tmpPoint,this._elevationProvider,this._elevationContext,this._renderCoordsHelper));return R(t,this._indexSR,t,this._renderSR),t}getAndUpdateVisibilityObbInRenderSR(e){{const t=e.visibilityObbInRenderSR;if(t)return t}const t=.01*this._indexSREllipsoidRadius,{serviceMbsInIndexSR:i,serviceObbInIndexSR:s}=e;if(null==s||!i||!s.isValid||this._isECEFOBBInLocalMode&&(s.halfSizeX>t||s.halfSizeY>t||s.halfSizeZ>t))return null;{let t=e.serviceObbInRenderSR;if(null==t)t=new q,e.serviceObbInRenderSR=t;else if(t.isValid)return t;const n=i[3];let r=0,o=0;const a=s.centerZ,c=this._renderCoordsHelper,h=this._elevationContext;if(h&&e.elevationRangeValid){const t=e.elevationRangeMin,i=e.elevationRangeMax;switch(h.mode){case"relative-to-ground":case"relative-to-scene":r=h.geometryZWithOffset(a,c)+t-a,o=i-t;break;case"on-the-ground":r=t-a,o=i-t}}else if(h&&n<U){const e=this._tmpPoint;e.x=s.centerX,e.y=s.centerY,e.z=a,r=B(e,this._elevationProvider,h,c)-a}const u=o>0,l=u?this._tmpObb:t;return s.transform(l,this._indexSR,this._renderSR,r,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),u&&G(l,0,o,this._viewingMode,t),t}}getNodeObbInRenderSRIndependentOfElevationOffset(e){{const t=e.visibilityObbInRenderSR??e.serviceObbInRenderSR??null;if(t?.isValid)return t}const t=e.serviceObbInIndexSR;return t?(t.transform(Y,this._indexSR,this._renderSR,void 0,this._renderSRSphericalPCPF,this._indexSRSphericalPCPF,this._projectorIndexSRToIndexSRSphericalPCPF),Y):null}ensureElevationAgnosticBoundingVolume(e){return!e.elevationAgnosticBoundingVolume.valid&&e.level>0&&(1===this._viewingMode?this._updateElevationAgnosticBoundingVolumeGlobal(e):this._updateElevationAgnosticBoundingVolumeLocal(e)),e.elevationAgnosticBoundingVolume}_updateCameraPOIDirection(){n(this._poi,this._camPos)?this._cameraPOIDirection=this._viewDirection:(r(this._cameraPOIDirection,this._camPos,this._poi),e(this._cameraPOIDirection,this._cameraPOIDirection))}_updateElevationAgnosticBoundingVolumeGlobal(t){const s=this.getNodeObbInRenderSRIndependentOfElevationOffset(t),n=t.elevationAgnosticBoundingVolume;let r,c=-1;if(s){const t=J;s.getCenter(t),e(t,t),r=t,s.getCorners(K);for(const s of K){e(s,s);const r=i(s,t);if(r<=0)return void n.invalidate();const o=Math.sqrt(1-r*r);c=Math.max(c,o)}}else{const i=t.serviceMbsInRenderSR;if(!y(i))return void n.invalidate();{const t=o(J,F(i)),s=i[3],h=a(t);if(h<s)return void n.invalidate();c=s/h,e(t,t),r=t}}const h=.001;n.set(r,c+h)}_updateElevationAgnosticBoundingVolumeLocal(e){const t=e.elevationAgnosticBoundingVolume,i=this.getNodeObbInRenderSRIndependentOfElevationOffset(e);if(i){const e=i.getCenter(J);e[2]=0;let s=0;const n=Q;i.getCorners(K);for(const t of K){t[2]=0;const e=c(n,t);s=Math.max(s,e)}t.set(e,Math.sqrt(s))}else{const i=e.serviceMbsInRenderSR;if(y(i)){const e=o(J,F(i));e[2]=0,t.set(e,i[3])}}}isNodeVisible(e){const t=this.getServiceMbsInRenderSR(e);if(!this._isMBSinClippingArea(t))return!1;if(!this._useFrustumCulling)return!0;const i=this.getAndUpdateVisibilityObbInRenderSR(e);return i?i.doesIntersectFrustumConservativeApproximation(this._frustum):I(this._frustum,t)}isElevationAgnosticBoundingVolumeVisible(e){return!this._useFrustumCulling||(!e.valid||(1===this._viewingMode?this._isConeVisibleInFrustum(e):this._isCylinderVisibleInFrustum(e)))}_isConeVisibleInFrustum(n){if(!this._isConeVisibleInFrustumMbs(n))return!1;const r=n.radius;if(-1===r||r>.9)return!0;const o=this._frustumPlanes,a=this._frustumMbsCenter,c=n.getAxis(ie),u=i(c,a),l=this._frustumMbsRadius,d=u-l,m=u+l;if(d<=0)return!0;const _=h(W,c,d),p=h(Z,c,m),f=r/Math.sqrt(1-r*r);for(const v of o){const n=P(v),r=e(X,n),o=i(r,c);if(Math.abs(1-o)<.01)continue;const a=$;h(a,c,o),t(a,a,r),e(a,a);const u=ee;s(u,_,a,d*f);if(D(v,u)<=0)continue;s(u,p,a,m*f);if(D(v,u)<=0)continue;return!1}return!0}_isConeVisibleInFrustumMbs(e){const t=e.radius;if(t>.9)return!0;const s=this._frustumMbsRadius,n=this._frustumMbsCenter,r=a(n);if(r<=s)return!0;const o=e.getAxis(ie),c=i(o,n);{const e=h(H,o,c);if(u(e,n)<s)return!0}const l=c/r;if(c<=0){return-l<s}const d=Math.sqrt(1-l*l);if(d<t)return!0;const m=s/r;return d*Math.sqrt(1-m*m)-m*l<t}isObbVisibleIndependentOfElevation(e,t){if(!this._useFrustumCulling)return!0;if(!e.valid)return!0;const s=this._frustumMbsRadius,n=this._frustumMbsCenter,r=this._frustumPlanes,o=K;if(t.getCorners(o),1===this._viewingMode){const t=e.getAxis(ie),a=i(t,n),c=a-s,u=a+s;if(c<=0)return!0;for(const e of r){let s=!0;for(const n of o){const r=i(n,t),o=te;if(h(o,n,c/r),D(e,o)<=0){s=!1;break}const a=te;if(h(a,n,u/r),D(e,a)<=0){s=!1;break}}if(s)return!1}}else{const e=n[2]-s,t=n[2]+s;for(const i of r){let s=!0;const n=P(i),r=n[0],a=n[1],c=n[2],h=i[3];for(const i of o){const n=r*i[0]+a*i[1]+h;if(n+c*e<=0||n+c*t<=0){s=!1;break}}if(s)return!1}}return!0}_isCylinderVisibleInFrustum(e){const t=this._frustumMbsCenter,i=this._frustumMbsRadius,s=o(H,t);s[2]=0;const n=e.radius,r=e.getAxis(ie);return u(s,r)<=n+i}isGeometryVisible(e){if(!this._useFrustumCulling)return!0;const t=e.geometryObbInRenderSR;return t?.doesIntersectFrustumConservativeApproximation(this._frustum)??this.isNodeVisible(e)}_isMBSinClippingArea(e){return null==this._clippingArea||0!==w(this._clippingArea,e)}_screenSpaceDiameterMbs(e,t){const i=this.getServiceMbsInRenderSR(e),s=Math.sqrt(l(F(i),this._camPos)),n=s-i[3];return this._updateMinMaxDistance(s),n<0?.5*Number.MAX_VALUE:t/n*this._screenSizeFactor}calcCameraDistance(e){return this.calcCameraDistanceToCenter(e)-this.getServiceMbsInRenderSR(e)[3]}calcCameraDistanceToCenter(e){const t=this.getServiceMbsInRenderSR(e),i=d(F(t),this._camPos);return this._updateMinMaxDistance(i),i}calcAngleDependentLoD(e){const t=this.getServiceMbsInRenderSR(e),i=t[3],s=(Math.abs(t[0]*(t[0]-this._camPos[0])+t[1]*(t[1]-this._camPos[1])+t[2]*(t[2]-this._camPos[2]))/m(F(t))+i)/d(F(t),this._camPos);return Math.min(1,s)}hasLOD(e){return 0!==e.lodMetric}_getDistanceGlobeMode(e,t){const s=m(F(t)),n=m(e)-s;h(this._tmp0,e,i(e,F(t))/_(e));const o=l(F(t),this._tmp0),a=t[3];if(o<=a*a)return Math.abs(n);{const o=h(this._tmp0,F(t),1/s),c=s,u=a*a/2/c,l=h(this._tmp1,o,c-u),_=e,f=r(this._tmp2,_,l),v=r(this._tmp2,f,h(this._tmp3,o,i(o,f))),g=p(this._tmp2,l,h(this._tmp2,v,a/m(v)));let b=d(_,g);if(n>=2e5){const e=r(this._tmp1,_,g);let t=i(e,o)/m(e);t<.08&&(t=1e-4),b/=t}return b}}_getDistance(e,t){return this._isGlobalMode?this._getDistanceGlobeMode(e,t):z(e,t)}_updateMinMaxDistance(e){e>0?(this.minDistance=Math.min(this.minDistance,e),this.maxDistance=Math.max(this.maxDistance,e)):(this.minDistance=0,this.maxDistance=Math.max(this.maxDistance,-e))}getLodLevel(e){if(0===e.lodMetric)return 0;if(0===e.childCount)return this.maxLodLevel;if(this._useFrustumCulling&&this._progressiveLoadFactor<1){const t=this._progressiveLoadFactor*this._screenspaceErrorBias,i=this._screenspaceErrorBias;return this.evaluateLODmetric(e,t)?this.evaluateLODmetric(e,i)?2:1:0}return this.evaluateLODmetric(e,this._screenspaceErrorBias)?this.maxLodLevel:0}evaluateLODmetric(e,t){switch(e.lodMetric){case 2:{const i=this.getServiceMbsInRenderSR(e),s=this._getDistance(this._camPos,i),n=2*s/this._screenSizeFactor,r=s+i[3];return this._updateMinMaxDistance(r),e.maxError*t<=n}case 1:{let i=this._screenSpaceDiameterMbs(e,e.serviceMbsInIndexSR[3]*t);return this._options.angleDependentLoD&&(i*=this.calcAngleDependentLoD(e)),i<e.maxError}case 3:return this._screenSpaceDiameterMbs(e,e.maxError)*t<10;case 4:return this.calcCameraDistance(e)>e.maxError*t}return!1}distToCameraPOIRay(e){if(null==e)return 0;const t=this.getServiceMbsInRenderSR(e),s=F(t),n=i(s,this._cameraPOIDirection),r=n*n,o=_(s)-r;return Math.sqrt(o)-t[3]}distCameraToPOI(){return d(this._camPos,this._poi)}}function z(e,t){const i=e[0]-t[0],s=e[1]-t[1],n=e[2]-t[2],r=i*i+s*s,o=t[3];if(r<=o*o)return Math.abs(n);const a=Math.sqrt(r)-o;return Math.sqrt(n*n+a*a)}const N=C(),T=f(),H=f(),W=f(),Z=f(),X=f(),Y=new q,J=f(),K=[f(),f(),f(),f(),f(),f(),f(),f()],Q=f(),$=f(),ee=f(),te=f(),ie=f();export{k as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import"../../../../../core/has.js";import e from"../../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import i from"../../../../../core/PooledArray.js";import{isTypedArray as o}from"../../../../../core/typedArrayUtil.js";import{s as n}from"../../../../../chunks/vec32.js";import{clone as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s}from"../../../../../geometry/support/aaBoundingBox.js";import{compactIndices as a}from"../../../../../geometry/support/Indices.js";import{c}from"../../../../../chunks/vec3.js";import{c as l}from"../../../../../chunks/vec33.js";import{encodeSymbolColor as m}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as h}from"../../../support/orientedBoundingBox.js";import{glLayout as f}from"../../../support/buffer/glUtil.js";import{ComponentData as p}from"./ComponentData.js";import{ComponentObject as g}from"./ComponentObject.js";import{IntersectionGeometry as u}from"./IntersectionGeometry.js";import{Renderable as d}from"./Renderable.js";import{RenderGeometry as b}from"./RenderGeometry.js";import{RenderSubmitSystem as v}from"./RenderSubmitSystem.js";import{createVertexBufferLayout as y}from"./SourceGeometry.js";import{UniformComponentParameters as _}from"./UniformComponentParameters.js";import{ComponentParametersVarying as C,ComponentParametersUniform as M,ComponentMaterial as w}from"./Material/ComponentMaterial.js";import{indexGlLayout as j}from"./Material/ComponentTechnique.js";import{maxElevationOffset as x,maxPackedRGBEmission as O}from"./Material/shader/ComponentData.glsl.js";import{olidEnabled as D}from"../../effects/geometry/olidUtils.js";import{getVisibility as S,updatePickabilityWithCount as R}from"../../lib/ComponentUtils.js";import{VertexArrayObject as A}from"../../lib/VertexArrayObject.js";import{getVerticalOffsetI3S as P}from"../../lib/verticalOffsetUtils.js";import{BufferManager as V}from"../../lib/TextureBackedBuffer/BufferManager.js";import{BufferObject as B}from"../../../../webgl/BufferObject.js";import{PrimitiveType as E}from"../../../../webgl/enums.js";import{VertexBuffer as H}from"../../../../webgl/VertexBuffer.js";const U=()=>e.getLogger("esri.views.3d.webgl-engine.collections.Component.ComponentObjectCollection");class I{constructor(e,t){this._renderManager=e,this._viewingMode=t,this._elevationRangeCacheVerticalOffset=NaN,this._elevationRangeCacheMin=NaN,this._elevationRangeCacheMax=NaN,this._activeHighlightOptions=new Map,this._visible=new i,this._hidden=new i,this._renderSubmit=new v(this),this._renderManager.register(this._renderSubmit),this._componentBufferManager=new V(e.rctx,N())}destroy(){this._componentBufferManager.destroy(),this._componentBufferManager=null,this._visible.forAll(e=>e.destroy()),this._visible.prune(),this._hidden.forAll(e=>e.destroy()),this._hidden.prune(),this._renderSubmit.destroy()}createObject(e){const{geometry:t}=e,i=new p(this._componentBufferManager,a(t.componentOffsets)),o=this._createRenderable(e,i),n=new u(this._viewingMode,t.positionData,i,e.elevationAlignable),r=new g(e.transform,e.obb.clone(),i,o,n);return(r.visible?this._visible:this._hidden).push(r),r}destroyObject(e){const t=e;(t.visible?this._visible:this._hidden).removeUnordered(t),t.destroy(),this._notifyDirty()}setObjectVisibility(e,t){const i=e;t!==i.visible&&(t?(this._hidden.removeUnordered(i),this._visible.push(i)):(this._visible.removeUnordered(i),this._hidden.push(i)),i.visible=t,this._notifyDirty())}preSubmit(e){const t=e.camera.eye;this.visibleObjects.forAll(e=>e.renderable.meta.cameraDepthSquared=n(t,e.obb.center))}getMaterial(e){return e.renderable.material}updateMaterial(e,t){const i=e.renderable.material;t(i),i.dirty&&this._notifyDirty()}setAllComponentVisibilities(e,t){const i=e;i.componentData.visibility.reset(t),i.componentData.markVisibilityDirty(),this._notifyDirty()}forEachVisibleComponent(e,t){return e.componentData.visibility.forEachComponent(t)}getComponentCount(e){const t=e,i=t.componentData.visibility.componentCount;return{visible:i,invisible:t.componentData.count-i}}setComponentData(e,t){const i=e,{renderable:o,componentData:n}=i,r=o.material,s=n.materialDataBuffer,a=n.materialDataIndices,c=new _,l=s.textureBuffer,f=l.getVec5Field("colorAndCastShadows"),p=l.getScalarField("elevationOffset"),g=l.getScalarField("emissiveStrength"),u=l.getScalarField("emissiveSourceMode"),d=l.getVec4Field("oidColor"),b=new Uint8Array(4),v=new Uint32Array(b.buffer);let y=0,w=0,j=0,x=0,O=0,A=n.verticalOffsets,P=1/0,V=-1/0,B=!1,E=!1,H=!1,U=0;for(let h=0;h<n.count;h++){t(h,c),y+=+(c.externalColor[3]<1),w+=+(3===c.externalColorMixMode&&1===c.externalColor[3]),x+=+(c.emissiveStrength>0),O+=+(1===c.emissiveSource),E||=1!==c.emissiveStrength,j+=+c.castShadows,m(c.externalColor,c.externalColorMixMode,b),f.setValues(a[h],b[0],b[1],b[2],b[3],+c.castShadows),B||=h>0&&U!==v[0],U=v[0],H||=0!==c.elevationOffset,H&&null==A&&(A=new Array(h).fill(0)),null!=A&&(A[h]=c.elevationOffset),P=Math.min(P,c.elevationOffset),V=Math.max(V,c.elevationOffset),p.set(a[h],c.elevationOffset),g.set(a[h],c.emissiveStrength),u.set(a[h],0===c.emissiveSource?0:255);const e=c.olidColor;null!=e&&d.setArray(a[h],e),c.pickable!==S(n.pickability,h)&&R(n,h,c.pickable)}n.verticalOffsets=H?A:null,i.offsetObb=H?h(i.obb,P,V,this._viewingMode,i.offsetObb??i.obb.clone()):null,B||H||D()||(E||O>0)&&x>0?(r.componentParameters=new C,r.componentParameters.castShadows=k(j,n.count),r.componentParameters.transparent=k(y,n.count),r.componentParameters.opaqueOverride=k(w,n.count),r.componentParameters.emissiveOverride=k(x,n.count),r.componentParameters.emissiveSourceOverride=k(O,n.count),r.componentParameters.texture=l,l.updateTexture()):(r.componentParameters=new M,r.componentParameters.castShadows=c.castShadows?0:2,r.componentParameters.externalColor=c.externalColor,r.componentParameters.externalColorMixMode=c.externalColorMixMode,r.componentParameters.emissiveStrength=c.emissiveStrength,r.componentParameters.emissiveSource=c.emissiveSource),this._elevationRangeCacheVerticalOffset=NaN,this._notifyDirty()}getComponentAabb(e,t,i,o=!1){e.intersectionGeometry.getComponentAabb(t,i);const n=e,r=n.componentData.verticalOffsets;if(o||null==r)return i;const s=r[t];if(2===this._viewingMode||0===s)return i[2]+=s,i[5]+=s,i;const a=P(s);return a.localOrigin=n.transform.position,a.applyToAabb(i)}getComponentObb(e){return e.obb}getObjectTransform(e){return e.transform}getComponentPositions(e,t,i){return e.intersectionGeometry.getComponentPositions(t,i)}expandRangeWithComponentObjectElevationRange(e,t,i,o){Number.isNaN(this._elevationRangeCacheVerticalOffset)||this._elevationRangeCacheVerticalOffset!==t||o.expandElevationRangeValues(this._elevationRangeCacheMin,this._elevationRangeCacheMax);const n=e,r=n.componentData,s=r.count,a=r.verticalOffsets,c=n.intersectionGeometry,l=2===this._viewingMode,m=c.getComponentAabbs(),h=G;let f=1/0,p=-1/0;for(let g=0;g<s;g++){const e=6*g,r=a?.[g]??0;let s=1/0,c=-1/0;if(l)s=m[e+2]+r+t,c=m[e+5]+r+t;else{if(h[0]=m[e],h[1]=m[e+1],h[2]=m[e+2],h[3]=m[e+3],h[4]=m[e+4],h[5]=m[e+5],0!==r){const e=P(r);e.localOrigin=n.transform.position,e.applyToAabb(h)}const s=Math.max(Math.abs(h[3]),Math.abs(h[0])),a=Math.max(Math.abs(h[4]),Math.abs(h[1])),c=t+h[5]+i;o.expandElevationRangeValues(t+h[2],Math.sqrt(s*s+a*a+c*c)-i)}o.expandElevationRangeValues(s,c),f=Math.min(f,s),p=Math.max(p,c)}this._elevationRangeCacheVerticalOffset=t,this._elevationRangeCacheMin=f,this._elevationRangeCacheMax=p}intersect(e,t,i,o,n,r){const s=e,{transform:a,componentData:c,intersectionGeometry:l}=s;return null!=o&&(o.localOrigin=a.position),l.intersect(t,i,o,c.verticalOffsets,a,n,r)}addEdges(e,t,i,o,n){const r=e,{indices:s,positions:a}=r.intersectionGeometry,c=r.componentData.offsets;return t.addComponentObject(r,a,s,c,i,o,n)}async extractEdgeInformation(e,t,i){const o=e,n=o.componentData.visibility;if(n.allInvisible()){const{extractComponentsEdgeLocationsLayout:e}=await import("../../lib/edgeRendering/edgeProcessing.js");return{buffer:e.createBuffer(0),origin:[0,0,0]}}const{indices:s,positions:a}=o.intersectionGeometry,m=o.componentData.offsets,{EdgeInputBufferLayout:h}=await import("../../lib/edgeRendering/bufferLayouts.js"),f=h.createBuffer(a.length/3);l(f.position.typedBuffer,a,f.position.typedBufferStride,3),c(f.position,f.position,o.transform.rotationScale),this._setComponentIndices(f.componentIndex,s,m);const p=f.count,g=this._computeVisibilityIndices(s,n,m,p);return{origin:r(o.transform.position),buffer:await t.extractComponentsEdgeLocations({indices:g,indicesLength:g.length,skipDeduplicate:!0,data:f,writerSettings:{reducedPrecision:!1,variants:0}},i)}}_setComponentIndices(e,t,i){let o=0;for(let n=0;n<i.length-1;n++){const r=i[n],s=i[n+1];for(let i=r;i<s;i++){const n=t?t[i]:i;e.set(n,o)}o++}}_computeVisibilityIndices(e,t,i,n){if(e&&t.allVisible())return e;let r=0;t.forEachComponentRange((e,t)=>(r+=i[t]-i[e],!0));const s=o(e)?2===e?.BYTES_PER_ELEMENT||n<=65536?new Uint16Array(r):new Uint32Array(r):new Array(r);let a=0;return t.forEachComponentRange((t,o)=>{const n=i[t],r=i[o];for(let i=n;i<r;i++)s[a++]=e?e[i]:i;return!0}),s}addComponentHighlight(e,i,o){const n=e.componentData,r=t(n.componentHighlights,o,()=>new Uint32Array(n.count+1));{const e=this._activeHighlightOptions.get(o)??0;this._activeHighlightOptions.set(o,e+1)}0===r[i]++&&(n.markHighlightsDirty(),this._notifyDirty()),r[n.count]++}removeComponentHighlight(e,t,i){const{componentData:o}=e,n=o.componentHighlights.get(i);if(void 0===n)return void U().warn("Removing non-existing highlight.");const r=n[t];if(0===r)return void U().warn("Removing non-existing highlight.");this._removeActiveHighlight(i);const s=n[o.count];if(r>1)return n[t]=r-1,void(n[o.count]=s-1);n[t]=0,1===s?o.componentHighlights.delete(i):n[o.count]=s-1,o.markHighlightsDirty(),this._notifyDirty()}_removeActiveHighlight(e,t=1){const i=this._activeHighlightOptions.get(e);if(void 0===i)U().warn("Removing non-existing highlight.");else{const o=i-t;o<0&&U().warn("Removing non-existing highlight."),o<=0?this._activeHighlightOptions.delete(e):this._activeHighlightOptions.set(e,o)}}clearHighlights(e){const{componentData:t}=e,{componentHighlights:i}=t;if(i.size>0){for(const e of i)this._removeActiveHighlight(e[0],e[1][t.count]);i.clear(),t.markHighlightsDirty(),this._notifyDirty()}}hasHighlight(e){return this._activeHighlightOptions.has(e)}getObjectGPUMemoryUsage(e){return e.renderable.meta.gpuMemoryEstimate}get visibleObjects(){return this._visible}_createRenderable(e,t){const i=this._renderManager.rctx,o=e.geometry,n=o.vertices.layoutParameters,r=f(y(n)),s=new H(i,r,o.vertices.data),a=o.indices?B.createIndex(i,35044,o.indices):null,c=new Uint16Array(o.vertices.count);for(let f=0;f<t.count;f++){const e=t.offsets[f],i=t.offsets[f+1],n=t.materialDataIndices[f];if(null!=o.indices)for(let t=e;t<i;t++){c[o.indices[t]]=n}else for(let t=e;t<i;t++)c[t]=n}const l=new H(i,j,c.buffer),m=new w(e.transform,e.toMapSpace,e.obb.radius<L),h=new A(i,new Map([["geometry",s],["componentIndices",l]]),a),p=new b(h,E.TRIANGLES,n,null!=a),g={cameraDepthSquared:.5,gpuMemoryEstimate:s.usedMemory+l.usedMemory+(null!=a?a.usedMemory:0)};return new d(m,p,g)}_notifyDirty(){this._renderManager.notifyDirty()}}function k(e,t){return e===t?0:0===e?2:1}function N(){const e=[{name:"colorAndCastShadows",type:"u8u8u7xu8"},{name:"elevationOffset",type:"packed-f32",maxValue:x},{name:"emissiveStrength",type:"packed-f24",maxValue:O},{name:"emissiveSourceMode",type:"u8"}];return D()&&e.push({name:"oidColor",type:"vec4u8"}),e}const G=s(),L=5e4;export{I as ComponentObjectCollection};
|
|
5
|
+
import"../../../../../core/has.js";import e from"../../../../../core/Logger.js";import{getOrCreateMapValue as t}from"../../../../../core/MapUtils.js";import i from"../../../../../core/PooledArray.js";import{isTypedArray as o}from"../../../../../core/typedArrayUtil.js";import{s as n}from"../../../../../chunks/vec32.js";import{clone as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as s}from"../../../../../geometry/support/aaBoundingBox.js";import{compactIndices as a}from"../../../../../geometry/support/Indices.js";import{c}from"../../../../../chunks/vec3.js";import{c as l}from"../../../../../chunks/vec33.js";import{encodeSymbolColor as m}from"../../../layers/support/symbolColorUtils.js";import{computeOffsetObb as f}from"../../../support/orientedBoundingBox.js";import{glLayout as h}from"../../../support/buffer/glUtil.js";import{ComponentData as p}from"./ComponentData.js";import{ComponentObject as g}from"./ComponentObject.js";import{IntersectionGeometry as u}from"./IntersectionGeometry.js";import{Renderable as d}from"./Renderable.js";import{RenderGeometry as b}from"./RenderGeometry.js";import{RenderSubmitSystem as v}from"./RenderSubmitSystem.js";import{createVertexBufferLayout as y}from"./SourceGeometry.js";import{UniformComponentParameters as _}from"./UniformComponentParameters.js";import{ComponentParametersVarying as C,ComponentParametersUniform as M,ComponentMaterial as w}from"./Material/ComponentMaterial.js";import{indexGlLayout as x}from"./Material/ComponentTechnique.js";import{maxElevationOffset as j,maxPackedRGBEmission as O}from"./Material/shader/ComponentData.glsl.js";import{olidEnabled as S}from"../../effects/geometry/olidUtils.js";import{getVisibility as D,updatePickabilityWithCount as R}from"../../lib/ComponentUtils.js";import{VertexArrayObject as B}from"../../lib/VertexArrayObject.js";import{getVerticalOffsetI3S as A}from"../../lib/verticalOffsetUtils.js";import{BufferManager as P}from"../../lib/TextureBackedBuffer/BufferManager.js";import{BufferObject as V}from"../../../../webgl/BufferObject.js";import{PrimitiveType as E}from"../../../../webgl/enums.js";import{VertexBuffer as H}from"../../../../webgl/VertexBuffer.js";const U=()=>e.getLogger("esri.views.3d.webgl-engine.collections.Component.ComponentObjectCollection");class k{constructor(e,t){this._renderManager=e,this._viewingMode=t,this._elevationRangeCacheVerticalOffset=NaN,this._elevationRangeCacheMin=NaN,this._elevationRangeCacheMax=NaN,this._activeHighlightOptions=new Map,this._visible=new i,this._hidden=new i,this._renderSubmit=new v(this),this._renderManager.register(this._renderSubmit),this._componentBufferManager=new P(e.rctx,N())}destroy(){this._componentBufferManager.destroy(),this._componentBufferManager=null,this._visible.forAll(e=>e.destroy()),this._visible.prune(),this._hidden.forAll(e=>e.destroy()),this._hidden.prune(),this._renderSubmit.destroy()}createObject(e){const{geometry:t}=e,i=new p(this._componentBufferManager,a(t.componentOffsets)),o=this._createRenderable(e,i),n=new u(this._viewingMode,t.positionData,i,e.elevationAlignable),r=new g(e.transform,e.obb.clone(),i,o,n);return(r.visible?this._visible:this._hidden).push(r),r}destroyObject(e){const t=e;(t.visible?this._visible:this._hidden).removeUnordered(t),t.destroy(),this._notifyDirty()}setObjectVisibility(e,t){const i=e;t!==i.visible&&(t?(this._hidden.removeUnordered(i),this._visible.push(i)):(this._visible.removeUnordered(i),this._hidden.push(i)),i.visible=t,this._notifyDirty())}preSubmit(e){const t=e.camera.eye;this.visibleObjects.forAll(e=>e.renderable.meta.cameraDepthSquared=n(t,e.obb.center))}getMaterial(e){return e.renderable.material}updateMaterial(e,t){const i=e.renderable.material;t(i),i.dirty&&this._notifyDirty()}setAllComponentVisibilities(e,t){const i=e;i.componentData.visibility.reset(t),i.componentData.markVisibilityDirty(),this._notifyDirty()}forEachVisibleComponent(e,t){return e.componentData.visibility.forEachComponent(t)}getComponentCount(e){const t=e,i=t.componentData.visibility.componentCount;return{visible:i,invisible:t.componentData.count-i}}setComponentData(e,t){const i=e,{renderable:o,componentData:n}=i,r=o.material,s=n.materialDataBuffer,a=n.materialDataIndices,c=new _,l=s.textureBuffer,h=l.getVec5Field("colorAndCastShadows"),p=l.getScalarField("elevationOffset"),g=l.getScalarField("emissiveStrength"),u=l.getScalarField("emissiveSourceMode"),d=l.getVec4Field("oidColor"),b=new Uint8Array(4),v=new Uint32Array(b.buffer);let y=0,w=0,x=0,j=0,O=0,B=n.verticalOffsets,A=1/0,P=-1/0,V=!1,E=!1,H=!1,U=0,k=!1;for(let f=0;f<n.count;f++){t(f,c),y+=+(c.externalColor[3]<1),w+=+(3===c.externalColorMixMode&&1===c.externalColor[3]),j+=+(c.emissiveStrength>0),O+=+(1===c.emissiveSource),E||=1!==c.emissiveStrength,x+=+c.castShadows,m(c.externalColor,c.externalColorMixMode,b),h.setValues(a[f],b[0],b[1],b[2],b[3],+c.castShadows),V||=f>0&&(U!==v[0]||k!==c.castShadows),U=v[0],k=c.castShadows,H||=0!==c.elevationOffset,H&&null==B&&(B=new Array(f).fill(0)),null!=B&&(B[f]=c.elevationOffset),A=Math.min(A,c.elevationOffset),P=Math.max(P,c.elevationOffset),p.set(a[f],c.elevationOffset),g.set(a[f],c.emissiveStrength),u.set(a[f],0===c.emissiveSource?0:255);const e=c.olidColor;null!=e&&d.setArray(a[f],e),c.pickable!==D(n.pickability,f)&&R(n,f,c.pickable)}n.verticalOffsets=H?B:null,i.offsetObb=H?f(i.obb,A,P,this._viewingMode,i.offsetObb??i.obb.clone()):null,V||H||S()||(E||O>0)&&j>0?(r.componentParameters=new C,r.componentParameters.castShadows=I(x,n.count),r.componentParameters.transparent=I(y,n.count),r.componentParameters.opaqueOverride=I(w,n.count),r.componentParameters.emissiveOverride=I(j,n.count),r.componentParameters.emissiveSourceOverride=I(O,n.count),r.textureBackedBufferParameters.textureBackedBuffer=l,l.updateTexture()):(r.componentParameters=new M,r.componentParameters.castShadows=c.castShadows?0:2,r.componentParameters.externalColor=c.externalColor,r.componentParameters.externalColorMixMode=c.externalColorMixMode,r.componentParameters.emissiveStrength=c.emissiveStrength,r.componentParameters.emissiveSource=c.emissiveSource,r.textureBackedBufferParameters.textureBackedBuffer=null),this._elevationRangeCacheVerticalOffset=NaN,this._notifyDirty()}getComponentAabb(e,t,i,o=!1){e.intersectionGeometry.getComponentAabb(t,i);const n=e,r=n.componentData.verticalOffsets;if(o||null==r)return i;const s=r[t];if(2===this._viewingMode||0===s)return i[2]+=s,i[5]+=s,i;const a=A(s);return a.localOrigin=n.transform.position,a.applyToAabb(i)}getComponentObb(e){return e.obb}getObjectTransform(e){return e.transform}getComponentPositions(e,t,i){return e.intersectionGeometry.getComponentPositions(t,i)}expandRangeWithComponentObjectElevationRange(e,t,i,o){Number.isNaN(this._elevationRangeCacheVerticalOffset)||this._elevationRangeCacheVerticalOffset!==t||o.expandElevationRangeValues(this._elevationRangeCacheMin,this._elevationRangeCacheMax);const n=e,r=n.componentData,s=r.count,a=r.verticalOffsets,c=n.intersectionGeometry,l=2===this._viewingMode,m=c.getComponentAabbs(),f=G;let h=1/0,p=-1/0;for(let g=0;g<s;g++){const e=6*g,r=a?.[g]??0;let s=1/0,c=-1/0;if(l)s=m[e+2]+r+t,c=m[e+5]+r+t;else{if(f[0]=m[e],f[1]=m[e+1],f[2]=m[e+2],f[3]=m[e+3],f[4]=m[e+4],f[5]=m[e+5],0!==r){const e=A(r);e.localOrigin=n.transform.position,e.applyToAabb(f)}const s=Math.max(Math.abs(f[3]),Math.abs(f[0])),a=Math.max(Math.abs(f[4]),Math.abs(f[1])),c=t+f[5]+i;o.expandElevationRangeValues(t+f[2],Math.sqrt(s*s+a*a+c*c)-i)}o.expandElevationRangeValues(s,c),h=Math.min(h,s),p=Math.max(p,c)}this._elevationRangeCacheVerticalOffset=t,this._elevationRangeCacheMin=h,this._elevationRangeCacheMax=p}intersect(e,t,i,o,n,r){const s=e,{transform:a,componentData:c,intersectionGeometry:l}=s;return null!=o&&(o.localOrigin=a.position),l.intersect(t,i,o,c.verticalOffsets,a,n,r)}addEdges(e,t,i,o,n){const r=e,{indices:s,positions:a}=r.intersectionGeometry,c=r.componentData.offsets;return t.addComponentObject(r,a,s,c,i,o,n)}async extractEdgeInformation(e,t,i){const o=e,n=o.componentData.visibility;if(n.allInvisible()){const{extractComponentsEdgeLocationsLayout:e}=await import("../../lib/edgeRendering/edgeProcessing.js");return{buffer:e.createBuffer(0),origin:[0,0,0]}}const{indices:s,positions:a}=o.intersectionGeometry,m=o.componentData.offsets,{EdgeInputBufferLayout:f}=await import("../../lib/edgeRendering/bufferLayouts.js"),h=f.createBuffer(a.length/3);l(h.position.typedBuffer,a,h.position.typedBufferStride,3),c(h.position,h.position,o.transform.rotationScale),this._setComponentIndices(h.componentIndex,s,m);const p=h.count,g=this._computeVisibilityIndices(s,n,m,p);return{origin:r(o.transform.position),buffer:await t.extractComponentsEdgeLocations({indices:g,indicesLength:g.length,skipDeduplicate:!0,data:h,writerSettings:{reducedPrecision:!1,variants:0}},i)}}_setComponentIndices(e,t,i){let o=0;for(let n=0;n<i.length-1;n++){const r=i[n],s=i[n+1];for(let i=r;i<s;i++){const n=t?t[i]:i;e.set(n,o)}o++}}_computeVisibilityIndices(e,t,i,n){if(e&&t.allVisible())return e;let r=0;t.forEachComponentRange((e,t)=>(r+=i[t]-i[e],!0));const s=o(e)?2===e?.BYTES_PER_ELEMENT||n<=65536?new Uint16Array(r):new Uint32Array(r):new Array(r);let a=0;return t.forEachComponentRange((t,o)=>{const n=i[t],r=i[o];for(let i=n;i<r;i++)s[a++]=e?e[i]:i;return!0}),s}addComponentHighlight(e,i,o){const n=e.componentData,r=t(n.componentHighlights,o,()=>new Uint32Array(n.count+1));{const e=this._activeHighlightOptions.get(o)??0;this._activeHighlightOptions.set(o,e+1)}0===r[i]++&&(n.markHighlightsDirty(),this._notifyDirty()),r[n.count]++}removeComponentHighlight(e,t,i){const{componentData:o}=e,n=o.componentHighlights.get(i);if(void 0===n)return void U().warn("Removing non-existing highlight.");const r=n[t];if(0===r)return void U().warn("Removing non-existing highlight.");this._removeActiveHighlight(i);const s=n[o.count];if(r>1)return n[t]=r-1,void(n[o.count]=s-1);n[t]=0,1===s?o.componentHighlights.delete(i):n[o.count]=s-1,o.markHighlightsDirty(),this._notifyDirty()}_removeActiveHighlight(e,t=1){const i=this._activeHighlightOptions.get(e);if(void 0===i)U().warn("Removing non-existing highlight.");else{const o=i-t;o<0&&U().warn("Removing non-existing highlight."),o<=0?this._activeHighlightOptions.delete(e):this._activeHighlightOptions.set(e,o)}}clearHighlights(e){const{componentData:t}=e,{componentHighlights:i}=t;if(i.size>0){for(const e of i)this._removeActiveHighlight(e[0],e[1][t.count]);i.clear(),t.markHighlightsDirty(),this._notifyDirty()}}hasHighlight(e){return this._activeHighlightOptions.has(e)}getObjectGPUMemoryUsage(e){return e.renderable.meta.gpuMemoryEstimate}get visibleObjects(){return this._visible}_createRenderable(e,t){const i=this._renderManager.rctx,o=e.geometry,n=o.vertices.layoutParameters,r=h(y(n)),s=new H(i,r,o.vertices.data),a=o.indices?V.createIndex(i,35044,o.indices):null,c=new Uint16Array(o.vertices.count);for(let h=0;h<t.count;h++){const e=t.offsets[h],i=t.offsets[h+1],n=t.materialDataIndices[h];if(null!=o.indices)for(let t=e;t<i;t++){c[o.indices[t]]=n}else for(let t=e;t<i;t++)c[t]=n}const l=new H(i,x,c.buffer),m=new w(e.transform,e.toMapSpace,e.obb.radius<L),f=new B(i,new Map([["geometry",s],["componentIndices",l]]),a),p=new b(f,E.TRIANGLES,n,null!=a),g={cameraDepthSquared:.5,gpuMemoryEstimate:s.usedMemory+l.usedMemory+(null!=a?a.usedMemory:0)};return new d(m,p,g)}_notifyDirty(){this._renderManager.notifyDirty()}}function I(e,t){return e===t?0:0===e?2:1}function N(){const e=[{name:"colorAndCastShadows",type:"u8u8u7xu8"},{name:"elevationOffset",type:"packed-f32",maxValue:j},{name:"emissiveStrength",type:"packed-f24",maxValue:O},{name:"emissiveSourceMode",type:"u8"}];return S()&&e.push({name:"oidColor",type:"vec4u8"}),e}const G=s(),L=5e4;export{k as ComponentObjectCollection};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as e}from"tslib";import{invert as t,transpose as
|
|
5
|
+
import{__decorate as e}from"tslib";import{invert as t,transpose as r}from"../../../../../../core/libs/gl-matrix-2/math/mat3.js";import{clone as s}from"../../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{I as o,q as i}from"../../../../../../chunks/vec32.js";import{freeze as a,ZEROS as l}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{v as n}from"../../../../../../chunks/vec42.js";import{freeze as h,fromValues as u}from"../../../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{ComponentTechnique as c}from"./ComponentTechnique.js";import{ComponentTechniqueConfiguration as p}from"./ComponentTechniqueConfiguration.js";import{parameter as d,parameterBlock as m,MaterialBase as v,MaterialParameterBlock as x}from"../../../core/material/MaterialBase.js";import{TextureBackedBufferParameters as g}from"../../../core/shaderLibrary/TextureBackedBuffer.glsl.js";import{TwoVectorPosition as f}from"../../../core/util/TwoVectorPosition.js";import{advancedMRRFactors as y}from"../../../materials/pbrUtils.js";import{defaultHighlightName as M}from"../../../../../support/HighlightDefaults.js";import{alphaCutoff as b}from"../../../../../../webscene/support/AlphaCutoff.js";class T extends v{constructor(e,o,i){super(),this.toMapSpace=o,this.useENUForGlobalOverlayUV=i,this.baseColor=h(1,1,1,1),this.usePBR=!1,this.hasParametersFromSource=!1,this.sphereDepthInterpolate=!1,this.mrrFactors=y,this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.normalTexture=null,this.occlusionTexture=null,this.emissionTexture=null,this.emissiveBaseColor=a(0,0,0),this.emissiveStrength=0,this.commonMaterialParameters=new S,this.componentParameters=new w,this.textureBackedBufferParameters=new g,this.objectOpacity=1,this.textureAlphaCutoff=b,this.alphaDiscardMode=1,this.isIntegratedMesh=!1,this.polygonOffsetEnabled=!1,this.ellipsoidMode=1,this.hasOccludees=!1;const l=new f(e.position),n=s(e.rotationScale);t(n,n),r(n,n),this.transformNormalGlobalFromModel=n,this.transformWorldFromModelTL=l.low,this.transformWorldFromModelTH=l.high,this.transformWorldFromModelRS=e.rotationScale}dispose(){this.baseColorTexture=null,this.metallicRoughnessTexture=null,this.emissionTexture=null,this.occlusionTexture=null,this.normalTexture=null}get _hasEmissiveBase(){return null!=this.emissionTexture||!i(this.emissiveBaseColor,l)}get _hasEmissiveStrength(){return 2!==this.componentParameters.emissiveOverride}get hasEmissions(){return this._hasEmissiveStrength&&(this._hasEmissiveBase||2!==this.componentParameters.emissiveSourceOverride)}get texture(){return this.baseColorTexture?.glTexture}get textureMetallicRoughness(){return this.metallicRoughnessTexture?.glTexture}get textureEmissive(){return this.emissionTexture?.glTexture}get textureOcclusion(){return this.occlusionTexture?.glTexture}get textureNormal(){return this.normalTexture?.glTexture}acquireTechnique(e,t,r,s){const o=new p(e.context.spherical,e.context.sphericalSR);o.renderOccluded=9===r.slot,o.hasVertexColors=s.hasVertexColors,o.hasNormals=s.hasNormals,o.textureCoordinateType=s.textureCoordinateType,o.hasMetallicRoughnessTexture=null!=this.metallicRoughnessTexture,o.hasOcclusionTexture=null!=this.occlusionTexture,o.hasNormalTexture=null!=this.normalTexture,o.sphereDepthInterpolate=this.sphereDepthInterpolate&&1===e.viewingMode,o.oitPass=0===t.identifier&&null!=r.oitPass?r.oitPass:0,o.terrainDepthTest=0===t.identifier&&r.terrainDepthTest,o.cullAboveTerrain=0===t.identifier&&r.cullAboveTerrain,o.ellipsoidMode=this.ellipsoidMode,o.componentData=this.componentParameters.type,o.textureBackedBufferLayout=this.textureBackedBufferParameters.textureBackedBuffer?.layout.hash??0,o.cullFace=this.commonMaterialParameters.cullFace,o.doubleSidedMode=this.commonMaterialParameters.doubleSided?1:0,o.hasColorTexture=null!=this.baseColorTexture;const i=this._computeWhichMaterialPass();o.blendingEnabled=1===i||2===i,o.alphaDiscardMode=this.alphaDiscardMode,o.integratedMeshMode=this.isIntegratedMesh?D(r)?C(r)?3:2:1:0,o.hasPolygonOffset=this.polygonOffsetEnabled,o.pbrMode=3===o.integratedMeshMode?4:this.usePBR?this.hasParametersFromSource?s.shadeNormals&&this.isIntegratedMesh?0:2:1:0;const a=1===this.componentParameters.emissiveSourceOverride,l=2===this.componentParameters.emissiveSourceOverride,n=null!=this.emissionTexture;if(o.emissionSource=this.hasEmissions?this._hasEmissiveBase&&1===o.pbrMode?l?n?4:2:a?n?5:7:6:a?7:6:0,o.shadeNormals=s.shadeNormals,o.normalType=o.hasNormals?1:2,o.hasSlicePlane=null!=r.slicePlane&&this.commonMaterialParameters.hasSlicePlane,o.receiveAmbientOcclusion=o.hasOccludees=o.receiveShadows=o.screenSpaceReflections=o.cloudReflections=o.hasHighlightMixTexture=!1,1===t.identifier)o.output=4,o.vertexDiscardMode=0;else if(3===t.identifier)o.output=7,o.vertexDiscardMode=0;else if(2===t.identifier)o.output=9,o.vertexDiscardMode=0,o.hasHighlightMixTexture=null!=r.highlightMixTexture;else{switch(o.vertexDiscardMode=2===i?t.transparent?2:1:0,o.output=t.output,t.output){case 0:case 1:o.receiveAmbientOcclusion=s.applySSAO&&null!=r.ssao?.getTexture(),o.hasOccludees=r.hasOccludees,o.receiveShadows=r.shadowMap.ready,o.screenSpaceReflections=null!=r.ssr.lastFrameColor,o.cloudReflections=null!=r.clouds.data?.cubeMap?.colorTexture;break;case 10:o.olidColor=!0}o.snowCover=r.snowCover>0}const h=e.get(c,o);return this._setClean(),h}submit(e,t,r){if(this.objectOpacity<=0)return;const{componentData:s,renderable:o}=r,{geometry:i}=o,a=o.meta.cameraDepthSquared;s.updateHighlights(t.highlights);const{geometryRanges:l,highlightRangesMap:n,shadowmapRanges:h}=s;switch(this._computeWhichMaterialPass()){case 0:e.opaque.submitDraw(this,i,l,a);break;case 1:e.transparent.submitDraw(this,i,l,a);break;case 2:e.opaque.submitDraw(this,i,l,a),e.transparent.submitDraw(this,i,l,a);break;case 3:e.integratedMesh.submitDraw(this,i,l,a),B(t)&&e.occludedGround.submitDraw(this,i,l,a),P(t)&&e.highlightIntegratedMesh.submitDraw(this,i,l,a);break;case 4:e.transparentIntegratedMesh.submitDraw(this,i,l,a)}if(2!==this.componentParameters.castShadows){if(null!=n)for(const t of n)t[0]===M&&e.highlightShadowMap.submitDraw(this,i,t[1],a,t[0]);null!=h&&e.defaultShadowMap.submitDraw(this,i,h,a),e.shadowMap.submitDraw(this,i,l,a)}if(null!=n)for(const u of n)e.highlight.submitDraw(this,i,u[1],a,u[0]);t.viewshedEnabled&&e.viewshedShadowMap.submitDraw(this,i,l,a)}_computeWhichMaterialPass(){if(this.isIntegratedMesh&&this.objectOpacity>=1)return 3;if(this.isIntegratedMesh&&this.objectOpacity<1)return 4;if(this.objectOpacity<1)return 1;if(0===this.componentParameters.opaqueOverride)return 0;if(this.baseColor[3]<1||0===this.alphaDiscardMode||3===this.alphaDiscardMode)return 1;switch(this.componentParameters.transparent){case 2:return 0;case 0:return 1;case 1:return 2}}}e([d({vectorOps:n})],T.prototype,"baseColor",void 0),e([d()],T.prototype,"usePBR",void 0),e([d()],T.prototype,"hasParametersFromSource",void 0),e([d()],T.prototype,"sphereDepthInterpolate",void 0),e([d({vectorOps:o})],T.prototype,"mrrFactors",void 0),e([d({dispose:!0})],T.prototype,"baseColorTexture",void 0),e([d({dispose:!0})],T.prototype,"metallicRoughnessTexture",void 0),e([d({dispose:!0})],T.prototype,"normalTexture",void 0),e([d({dispose:!0})],T.prototype,"occlusionTexture",void 0),e([d({dispose:!0})],T.prototype,"emissionTexture",void 0),e([d({vectorOps:o})],T.prototype,"emissiveBaseColor",void 0),e([d()],T.prototype,"emissiveStrength",void 0),e([m()],T.prototype,"commonMaterialParameters",void 0),e([m()],T.prototype,"componentParameters",void 0),e([m()],T.prototype,"textureBackedBufferParameters",void 0),e([d()],T.prototype,"objectOpacity",void 0),e([d()],T.prototype,"textureAlphaCutoff",void 0),e([d()],T.prototype,"alphaDiscardMode",void 0),e([d()],T.prototype,"isIntegratedMesh",void 0),e([d()],T.prototype,"polygonOffsetEnabled",void 0),e([d()],T.prototype,"ellipsoidMode",void 0),e([d()],T.prototype,"hasOccludees",void 0);class S extends x{constructor(){super(...arguments),this.doubleSided=!1,this.cullFace=2,this.hasSlicePlane=!0}}e([d()],S.prototype,"doubleSided",void 0),e([d()],S.prototype,"cullFace",void 0),e([d()],S.prototype,"hasSlicePlane",void 0);class w extends x{constructor(){super(...arguments),this.externalColor=u(1,1,1,1),this.externalColorMixMode=1,this.emissiveStrength=0,this.emissiveSource=0,this.castShadows=0}get transparent(){return this.externalColor[3]<1?0:2}get opaqueOverride(){return 3===this.externalColorMixMode&&1===this.externalColor[3]?0:2}get emissiveOverride(){return this.emissiveStrength>0?0:2}get emissiveSourceOverride(){return 1===this.emissiveSource?0:2}get visible(){return this.externalColor[3]>0?0:2}get type(){return 0}}e([d({vectorOps:n})],w.prototype,"externalColor",void 0),e([d()],w.prototype,"externalColorMixMode",void 0),e([d()],w.prototype,"emissiveStrength",void 0),e([d()],w.prototype,"emissiveSource",void 0),e([d()],w.prototype,"castShadows",void 0);class O extends x{constructor(){super(...arguments),this.transparent=2,this.opaqueOverride=2,this.emissiveOverride=2,this.emissiveSourceOverride=2,this.castShadows=2}get type(){return 1}}function P(e){return null!=e.overlay?.getTexture(2)}function C(e){return null!=e.overlay?.getTexture(3)}function D(e){return null!=e.overlay?.getTexture(1)}function B(e){return null!=e.overlay?.getTexture(e.overlay?.allSourcesOccluders?1:4)}e([d()],O.prototype,"transparent",void 0),e([d()],O.prototype,"opaqueOverride",void 0),e([d()],O.prototype,"emissiveOverride",void 0),e([d()],O.prototype,"emissiveSourceOverride",void 0),e([d()],O.prototype,"castShadows",void 0);export{S as CommonMaterialParameters,T as ComponentMaterial,w as ComponentParametersUniform,O as ComponentParametersVarying};
|
package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as
|
|
5
|
+
import{__decorate as e}from"tslib";import{isColorEmissionHighlightOrOID as o}from"../../../core/shaderLibrary/ShaderOutput.js";import{parameter as t,ShaderTechniqueConfiguration as i}from"../../../core/shaderTechnique/ShaderTechniqueConfiguration.js";import{MAX_COUNT_TEXTURE_BACKED_BUFFER_LAYOUTS as s}from"../../../lib/TextureBackedBuffer/TextureBackedBufferLayout.js";class r extends i{constructor(e,o){super(),this.spherical=e,this.sphericalSR=o,this.output=0,this.textureCoordinateType=0,this.componentData=0,this.textureBackedBufferLayout=0,this.cullFace=2,this.vertexDiscardMode=0,this.doubleSidedMode=2,this.alphaDiscardMode=1,this.integratedMeshMode=0,this.oitPass=0,this.ellipsoidMode=1,this.pbrMode=0,this.normalType=0,this.emissionSource=0,this.hasVertexColors=!1,this.hasNormals=!1,this.shadeNormals=!0,this.hasSlicePlane=!1,this.hasColorTexture=!1,this.hasHighlightMixTexture=!1,this.receiveAmbientOcclusion=!0,this.receiveShadows=!0,this.blendingEnabled=!0,this.screenSpaceReflections=!1,this.hasPolygonOffset=!1,this.hasMetallicRoughnessTexture=!1,this.hasOcclusionTexture=!1,this.hasNormalTexture=!1,this.hasOccludees=!1,this.terrainDepthTest=!1,this.cullAboveTerrain=!1,this.hasNormalTextureTransform=!1,this.cloudReflections=!0,this.snowCover=!1,this.olidColor=!1,this.renderOccluded=!1,this.sphereDepthInterpolate=!1,this.discardInvisibleFragments=!1,this.occlusionPass=!1,this.bindType=2,this.useCustomDTRExponentForWater=!1,this.hasVertexTangents=!1,this.highStepCount=!1,this.instanced=!1,this.instancedDoublePrecision=!1,this.hasModelTransformation=!1,this.useFillLights=!0,this.draped=!1}get overlayEnabled(){return(2===this.integratedMeshMode||3===this.integratedMeshMode)&&o(this.output)}}e([t({count:11})],r.prototype,"output",void 0),e([t({count:3})],r.prototype,"textureCoordinateType",void 0),e([t({count:2})],r.prototype,"componentData",void 0),e([t({count:s})],r.prototype,"textureBackedBufferLayout",void 0),e([t({count:3})],r.prototype,"cullFace",void 0),e([t({count:3})],r.prototype,"vertexDiscardMode",void 0),e([t({count:3})],r.prototype,"doubleSidedMode",void 0),e([t({count:4})],r.prototype,"alphaDiscardMode",void 0),e([t({count:4})],r.prototype,"integratedMeshMode",void 0),e([t({count:3})],r.prototype,"oitPass",void 0),e([t({count:4})],r.prototype,"ellipsoidMode",void 0),e([t({count:7})],r.prototype,"pbrMode",void 0),e([t({count:3})],r.prototype,"normalType",void 0),e([t({count:8})],r.prototype,"emissionSource",void 0),e([t()],r.prototype,"hasVertexColors",void 0),e([t()],r.prototype,"hasNormals",void 0),e([t()],r.prototype,"shadeNormals",void 0),e([t()],r.prototype,"hasSlicePlane",void 0),e([t()],r.prototype,"hasColorTexture",void 0),e([t()],r.prototype,"hasHighlightMixTexture",void 0),e([t()],r.prototype,"receiveAmbientOcclusion",void 0),e([t()],r.prototype,"receiveShadows",void 0),e([t()],r.prototype,"blendingEnabled",void 0),e([t()],r.prototype,"screenSpaceReflections",void 0),e([t()],r.prototype,"hasPolygonOffset",void 0),e([t()],r.prototype,"hasMetallicRoughnessTexture",void 0),e([t()],r.prototype,"hasOcclusionTexture",void 0),e([t()],r.prototype,"hasNormalTexture",void 0),e([t()],r.prototype,"hasOccludees",void 0),e([t()],r.prototype,"terrainDepthTest",void 0),e([t()],r.prototype,"cullAboveTerrain",void 0),e([t()],r.prototype,"hasNormalTextureTransform",void 0),e([t()],r.prototype,"cloudReflections",void 0),e([t()],r.prototype,"snowCover",void 0),e([t()],r.prototype,"olidColor",void 0),e([t()],r.prototype,"renderOccluded",void 0),e([t()],r.prototype,"sphereDepthInterpolate",void 0);export{r as ComponentTechniqueConfiguration};
|
|
@@ -2,42 +2,24 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{neverReached as o}from"../../../../../../../core/compilerUtils.js";import{packFloatRGBA as e,packFloatRGB as
|
|
6
|
-
float index = componentIndex * stride + typeOffset;
|
|
7
|
-
float texSize = float(textureSize(componentColorTex, 0).x);
|
|
8
|
-
float coordX = mod(index, texSize);
|
|
9
|
-
float coordY = floor(index / texSize);
|
|
10
|
-
return vec2(coordX, coordY) + 0.5;
|
|
11
|
-
}`),t.code.add(l`
|
|
12
|
-
vec4 _readComponentColor() {
|
|
13
|
-
vec2 textureCoordinates = getComponentTextureCoordinates(componentIndex, 0.0);
|
|
14
|
-
return texelFetch(componentColorTex, ivec2(textureCoordinates), 0);
|
|
15
|
-
}
|
|
16
|
-
|
|
5
|
+
import{neverReached as o}from"../../../../../../../core/compilerUtils.js";import{packFloatRGBA as e,packFloatRGB as r}from"../../../../../../../core/floatRGBA.js";import{DecodeSymbolColor as t}from"./DecodeSymbolColor.glsl.js";import{TextureBackedBufferModule as a,itemData as d}from"../../../../core/shaderLibrary/TextureBackedBuffer.glsl.js";import{Float4DrawUniform as n}from"../../../../core/shaderModules/Float4DrawUniform.js";import{FloatDrawUniform as l}from"../../../../core/shaderModules/FloatDrawUniform.js";import{glsl as i,If as s}from"../../../../core/shaderModules/glsl.js";import{IntegerDrawUniform as c}from"../../../../core/shaderModules/IntegerDrawUniform.js";import{getTextureBackedBufferLayout as u}from"../../../../lib/TextureBackedBuffer/TextureBackedBuffer.js";const f=429496.7296;function v(o,r){e(o/f*.5+.5,r)}const m=1e6;function x(o,e){r(o/m*.5+.5,e)}function C(e,r){switch(r.componentData){case 1:return M(e,r);case 0:return h(e,r);case 2:return;default:o(r.componentData)}}function M(o,e){const{vertex:r,fragment:n}=o,{output:l}=e;if(0===e.textureBackedBufferLayout)return;const c=u(e.textureBackedBufferLayout);if(null==c)throw new Error(`Invalid TextureBackedBufferLayout: ${e.textureBackedBufferLayout}. TextureBackedBuffer shader code generation only possible with valid buffer assigned.`);const f=10===l,v=1===l,m=o=>"emissiveSourceMode"===o||"emissiveStrength"===o?v:"oidColor"!==o||f;o.include(a(c,m,"componentIndex")),o.attributes.add("componentIndex","float"),o.varyings.add("vExternalColorMixMode","mediump float"),o.varyings.add("vExternalColor","vec4"),f&&o.varyings.add("vObjectAndLayerIdColor","vec4"),v&&(o.varyings.add("emissiveStrength","float"),o.varyings.add("emissiveSource","int")),o.include(t),r.code.add(i`
|
|
17
6
|
float readElevationOffset() {
|
|
18
|
-
|
|
19
|
-
vec4 encodedElevation = texelFetch(componentColorTex, ivec2(textureCoordinates), 0);
|
|
20
|
-
return uninterpolatedRGBAToFloat(encodedElevation) * ${l.float(x)};
|
|
7
|
+
return ${d("elevationOffset")};
|
|
21
8
|
}
|
|
22
9
|
|
|
23
10
|
void forwardEmissiveStrength() {
|
|
24
|
-
${
|
|
25
|
-
|
|
26
|
-
emissiveStrength = uninterpolatedRGBToFloat(encodedEmissive.rgb) * ${l.float(u)};
|
|
27
|
-
emissiveSource = encodedEmissive.a == 0.0 ? 0 : 1;`)}
|
|
11
|
+
${s(v,i`emissiveStrength = ${d("emissiveStrength")};
|
|
12
|
+
emissiveSource = ${d("emissiveSourceMode")} == 0.0 ? 0 : 1;`)}
|
|
28
13
|
}
|
|
29
14
|
|
|
30
15
|
void forwardObjectAndLayerIdColor() {
|
|
31
|
-
${
|
|
32
|
-
vObjectAndLayerIdColor = texelFetch(componentColorTex, ivec2(textureCoordinates), 0);`)}
|
|
16
|
+
${s(f,i`vObjectAndLayerIdColor = ${d("oidColor")};`)}
|
|
33
17
|
}
|
|
34
18
|
|
|
35
19
|
vec4 forwardExternalColor(out bool castShadows) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
componentColor.b -= shadowFlag;
|
|
40
|
-
castShadows = shadowFlag >= 1.0;
|
|
20
|
+
vec5 colorAndCastShadow = ${d("colorAndCastShadows")};
|
|
21
|
+
vec4 componentColor = vec4(colorAndCastShadow.x, colorAndCastShadow.y, colorAndCastShadow.z, colorAndCastShadow.w);
|
|
22
|
+
castShadows = colorAndCastShadow.v >= 1.0;
|
|
41
23
|
|
|
42
24
|
int decodedColorMixMode;
|
|
43
25
|
vExternalColor = decodeSymbolColor(componentColor, decodedColorMixMode) * 0.003921568627451; // = 1/255;
|
|
@@ -45,16 +27,16 @@ return vec2(coordX, coordY) + 0.5;
|
|
|
45
27
|
|
|
46
28
|
return vExternalColor;
|
|
47
29
|
}
|
|
48
|
-
`),
|
|
30
|
+
`),n.code.add(i`
|
|
49
31
|
void readExternalColor(out vec4 externalColor, out int externalColorMixMode) {
|
|
50
32
|
externalColor = vExternalColor;
|
|
51
33
|
externalColorMixMode = int(vExternalColorMixMode);
|
|
52
34
|
}
|
|
53
35
|
|
|
54
36
|
void outputObjectAndLayerIdColor() {
|
|
55
|
-
${
|
|
37
|
+
${f?i`fragColor = vObjectAndLayerIdColor;`:""}
|
|
56
38
|
}
|
|
57
|
-
`)}function
|
|
39
|
+
`)}function h(o,e){const{vertex:r,fragment:t}=o;o.varyings.add("vExternalColor","vec4"),t.uniforms.add(new l("emissiveStrength",o=>o.componentParameters.emissiveStrength)),r.uniforms.add(new n("externalColor",o=>o.componentParameters.externalColor)).code.add(i`float readElevationOffset() {
|
|
58
40
|
return 0.0;
|
|
59
41
|
}
|
|
60
42
|
void forwardObjectAndLayerIdColor() {}
|
|
@@ -63,13 +45,13 @@ vec4 forwardExternalColor(out bool castShadows) {
|
|
|
63
45
|
vExternalColor = externalColor;
|
|
64
46
|
castShadows = true;
|
|
65
47
|
return externalColor;
|
|
66
|
-
}`);const
|
|
48
|
+
}`);const a=10===e.output;t.uniforms.add(new c("externalColorMixMode",o=>o.componentParameters.externalColorMixMode)).code.add(i`
|
|
67
49
|
void readExternalColor(out vec4 color, out int colorMixMode) {
|
|
68
50
|
color = vExternalColor;
|
|
69
51
|
colorMixMode = externalColorMixMode;
|
|
70
52
|
}
|
|
71
53
|
|
|
72
54
|
void outputObjectAndLayerIdColor() {
|
|
73
|
-
${
|
|
55
|
+
${s(a,"fragColor = vec4(0, 0, 0, 0);")}
|
|
74
56
|
}
|
|
75
|
-
`)}export{
|
|
57
|
+
`)}export{C as ComponentData,v as encodeElevationOffset,x as encodeEmissiveStrength,f as maxElevationOffset,m as maxPackedRGBEmission};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import{__decorate as e}from"tslib";import{parameter as t,MaterialParameterBlock as o}from"../material/MaterialBase.js";import{glslType as r,decode_u8u8u7xu8 as a,glslDecodeField as d}from"./TextureBackedBufferFields.glsl.js";import{RgbaFloatEncoding as f}from"./util/RgbaFloatEncoding.glsl.js";import{glsl as c}from"../shaderModules/glsl.js";import{Texture2DDrawUniform as l}from"../shaderModules/Texture2DDrawUniform.js";class n extends o{constructor(e=null){super(),this.textureBackedBuffer=e}}function u(e,t=()=>!0,o){return r=>i(r,o,e,t)}function i(e,t,o,n){const{vertex:u}=e;u.constants.add("tbbStride","float",o.numTexels),u.uniforms.add(new l("componentColorTex",e=>e.textureBackedBufferParameters.textureBackedBuffer.texture));const i=o.fields.filter(e=>n(e.name));if(0===i.length)return;const m=[];for(let r=0;r<o.numTexels;++r)m.push(!1);for(const r of i)for(let e=0;e<r.numTexels;++e)m[r.startTexel+e]=!0;u.code.add(c`struct vec5 {
|
|
6
|
+
float x;
|
|
7
|
+
float y;
|
|
8
|
+
float z;
|
|
9
|
+
float w;
|
|
10
|
+
float v;
|
|
11
|
+
};`),u.code.add(c`struct TextureBackedBufferItemData {`);for(const a of i)u.code.add(c`\t${r(a)} ${a.name};`);u.code.add(c`};`),u.include(f),u.include(a),u.code.add(c`TextureBackedBufferItemData fetchTextureBackedBufferItemData(float itemIndex) {
|
|
12
|
+
TextureBackedBufferItemData itemData;
|
|
13
|
+
float index = itemIndex * tbbStride;
|
|
14
|
+
float texSize = float(textureSize(componentColorTex, 0).x);
|
|
15
|
+
float coordX = mod(index, texSize) + 0.5;
|
|
16
|
+
float coordY = floor(index / texSize) + 0.5;`);for(let r=0;r<m.length;++r)!1!==m[r]&&u.code.add(c`\tvec4 texel${c.int(r)} = texelFetch(componentColorTex, ivec2(coordX + ${c.float(r)}, coordY), 0);`);for(const r of i)u.code.add(c`\titemData.${r.name} = ${d(r)};`);u.code.add(c`return itemData;
|
|
17
|
+
}`),u.code.add(c`TextureBackedBufferItemData tbbItemData;`),u.main.add(c`tbbItemData = fetchTextureBackedBufferItemData(${t});`)}function m(e){return c`tbbItemData.${e}`}e([t()],n.prototype,"textureBackedBuffer",void 0);export{u as TextureBackedBufferModule,n as TextureBackedBufferParameters,m as itemData};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import{glsl as o}from"../shaderModules/glsl.js";function e(e){e.code.add(o`vec5 decode_u8u8u7xu8(float r, float g, float b, float a) {
|
|
6
|
+
vec4 componentColor = vec4(r, g, b, a) * 255.0;
|
|
7
|
+
float shadowFlag = mod(componentColor.b * 255.0, 2.0);
|
|
8
|
+
componentColor.b -= shadowFlag;
|
|
9
|
+
return vec5(componentColor.r, componentColor.g, componentColor.b, componentColor.a, shadowFlag);
|
|
10
|
+
}`)}function t(e){switch(e.elementCount){case 1:return o`float`;case 2:return o`vec2`;case 3:return o`vec3`;case 4:return o`vec4`;case 5:return o`vec5`;default:throw new Error("unsupported elementCount")}}function n(o){const{declaration:e,glslDecodeArgumentString:t}=o;return`${(0,r[e.type])(t,e)}`}const r={u8:e=>o`${e}`,"packed-f24":(e,t)=>o`uninterpolatedRGBToFloat(vec3(${e})) * ${o.float(t.maxValue)}`,"packed-f32":(e,t)=>o`uninterpolatedRGBAToFloat(vec4(${e})) * ${o.float(t.maxValue)}`,vec4u8:e=>o`vec4(${e})`,u8u8u7xu8:e=>o`decode_u8u8u7xu8(${e})`};export{e as decode_u8u8u7xu8,n as glslDecodeField,t as glslType};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{maxIndexCount as t,ManagedTextureBackedBuffer as e}from"./ManagedTextureBackedBuffer.js";
|
|
5
|
+
import{maxIndexCount as t,ManagedTextureBackedBuffer as e}from"./ManagedTextureBackedBuffer.js";class s{constructor(t,e){this._rctx=t,this._layoutDeclaration=e,this._bufferList=[]}garbageCollect(){const{_bufferList:t}=this;this._bufferList=t.filter(t=>0!==t.activeCount||(t.dispose(),!1))}destroy(){const{_bufferList:t}=this;t.forEach(t=>t.dispose()),this._bufferList=[]}getBuffer(s){const{_bufferList:r}=this;for(const t of r)if(t.availableCount>=s)return t;if(s>t)return null;const f=new e(this._rctx,this._layoutDeclaration);return r.push(f),f}updateTextures(){const t=this._bufferList;for(const e of t)e.textureBuffer.updateTexture()}}export{s as BufferManager};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{SimpleIndexManager as e}from"./SimpleIndexManager.js";import{
|
|
5
|
+
import{SimpleIndexManager as e}from"./SimpleIndexManager.js";import{TextureBackedBuffer as t}from"./TextureBackedBuffer.js";const r=65536;class i{constructor(i,n){this.textureBuffer=new t(i,n),this._indexManager=new e(r)}dispose(){this.textureBuffer.dispose(),this.textureBuffer=void 0}get availableCount(){return this._indexManager.availableCount}get activeCount(){return this._indexManager.activeCount}acquireIndex(){const e=this._indexManager.acquire();return this.textureBuffer.resizeToFit(e),e}acquireIndices(e){const t=new Uint16Array(e);let r=0;for(let i=0;i<e;++i){const e=this._indexManager.acquire();t[i]=e,r=Math.max(r,e)}return this.textureBuffer.resizeToFit(r),t}releaseIndex(e){this._indexManager.release(e)}}export{i as ManagedTextureBackedBuffer,r as maxIndexCount};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{
|
|
5
|
+
import{typeToCreationInfoMap as t}from"./TextureBackedBufferFields.js";import{hashTextureBackedBufferLayout as e,LayoutField as r,TextureBackedBufferLayout as i}from"./TextureBackedBufferLayout.js";import{Texture as s}from"../../../../webgl/Texture.js";import{TextureDescriptor as n}from"../../../../webgl/TextureDescriptor.js";class u{constructor(t,e){this._rctx=t,this._fields=[],this._nameToFieldMap=new Map,this._textureData=new Uint8Array(new ArrayBuffer),this._textureWidth=1,this._textureHeight=1,this._dirty=!0,this._generateLayout(e);const r=new n(this._textureWidth,this._textureHeight);r.samplingMode=9728,r.wrapMode=33071,this._texture=new s(this._rctx,r)}get layout(){return this._layout}dispose(){this._texture.dispose(),this._texture=void 0,this._textureData=void 0}get test(){return{data:this._textureData,fields:this._fields}}getScalarField(t){const e=this._nameToFieldMap.get(t);return 1===e?.elementCount?e:null}getVec4Field(t){const e=this._nameToFieldMap.get(t);return 4===e?.elementCount?e:null}getVec5Field(t){const e=this._nameToFieldMap.get(t);return 5===e?.elementCount?e:null}resizeToFit(t){const e=t+1;e>this._textureData.length/this._layout.byteStride&&this._resize(e)}updateTexture(){if(!this._dirty)return;const t=this._texture.descriptor.width,e=this._texture.descriptor.height;t===this._textureWidth&&e===this._textureHeight||this._texture.resize(this._textureWidth,this._textureHeight),this._texture.setData(this._textureData),this._dirty=!1}get texture(){return this._texture}_resize(t){const{_fields:e,_layout:r}=this,i=r.byteStride;if(0===t){const t=new ArrayBuffer;this._textureData=new Uint8Array(t);for(const r of e)r.updateBuffer(t);return void(this._dirty=!0)}const s=Math.ceil(Math.sqrt(t)),n=Math.ceil(t/s),u=s*i,a=Math.ceil(u/4),o=new ArrayBuffer(u*n);for(const _ of e)_.updateBuffer(o);const h=new Uint8Array(o);h.set(this._textureData),this._textureData=h,this._textureWidth=a,this._textureHeight=n,this._dirty=!0}_generateLayout(t){const e=h(t),r=this._textureData.buffer;this._fields=e.fields.map(t=>{const e=t.createField(()=>this._dirty=!0);return e.updateBuffer(r),this._nameToFieldMap.set(e.name,e),e}),this._layout=e}}const a=new Map;function o(t){return a.get(t)}function h(s){const n=e(s);let u=a.get(n);if(null!=u)return u;let o=0;const h=[];for(let e=0;e<s.length;++e){const r=s[e],{type:i}=r,n=t.get(i);null!=n&&(h.push({declaration:r,byteOffset:o,creationInfo:n}),o+=n.byteSize)}o=_(o);const l=o,d=h.map(({declaration:t,byteOffset:e,creationInfo:i})=>new r(t,e,l,i));return u=new i(n,d,l),a.set(n,u),u}function _(t){return t+3&-4}export{u as TextureBackedBuffer,o as getTextureBackedBufferLayout};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import{packFloatRGBA as e,packFloatRGB as t}from"../../../../../core/floatRGBA.js";import{BufferViewVec4u8 as s,BufferViewVec3u8 as r,BufferViewUint8 as i}from"../../../../../geometry/support/buffer/BufferView.js";import{elementTypeSize as f}from"../../../../../geometry/support/buffer/types.js";class u{constructor(e,t,s,r){this.name=e,this.byteOffset=t,this.byteStride=s,this.makeDirty=r}}class n extends u{constructor(e,t,s,r){super(e,t,s,r),this.elementCount=1}}class o extends n{constructor(e,t,s,r,i){super(e,s,r,i),this._bufferViewConstructor=t}updateBuffer(e){const{byteOffset:t,byteStride:s,_bufferViewConstructor:r}=this;this._bufferView=new r(e,t,s),this.makeDirty()}set(e,t){this._bufferView.set(e,t),this.makeDirty()}}class a extends n{constructor(e,t,s,r,i){super(e,t,s,r),this._maxValue=i}updateBuffer(e){const{byteOffset:t,byteStride:s}=this;this._bufferView=new r(e,t,s),this.makeDirty()}set(e,s){const{_bufferView:r,_maxValue:i,makeDirty:f}=this;t(s/i*.5+.5,p),r.setValues(e,p[0],p[1],p[2]),f()}}class c extends n{constructor(e,t,s,r,i){super(e,t,s,r),this._maxValue=i}updateBuffer(e){const{byteOffset:t,byteStride:r}=this;this._bufferView=new s(e,t,r),this.makeDirty()}set(t,s){const{_bufferView:r,_maxValue:i,makeDirty:f}=this;e(s/i*.5+.5,k),r.setValues(t,k[0],k[1],k[2],k[3]),f()}}class h extends u{constructor(e,t,s,r){super(e,t,s,r),this.elementCount=3}}class b extends h{constructor(e,t,s,r,i){super(e,s,r,i),this._bufferViewConstructor=t}updateBuffer(e){const{byteOffset:t,byteStride:s,_bufferViewConstructor:r}=this;this._bufferView=new r(e,t,s),this.makeDirty()}setValues(e,t,s,r){this._bufferView.set(e,0,t),this._bufferView.set(e,1,s),this._bufferView.set(e,2,r),this.makeDirty()}setElement(e,t,s){this._bufferView.set(e,t,s),this.makeDirty()}setVec(e,t){this._bufferView.setVec(e,t),this.makeDirty()}setArray(e,t){this._bufferView.set(e,0,t[0]),this._bufferView.set(e,1,t[1]),this._bufferView.set(e,2,t[2]),this.makeDirty()}}class V extends u{constructor(e,t,s,r){super(e,t,s,r),this.elementCount=4}}class w extends V{constructor(e,t,s,r,i){super(e,s,r,i),this._bufferViewConstructor=t}updateBuffer(e){const{byteOffset:t,byteStride:s,_bufferViewConstructor:r}=this;this._bufferView=new r(e,t,s),this.makeDirty()}setValues(e,t,s,r,i){this._bufferView.set(e,0,t),this._bufferView.set(e,1,s),this._bufferView.set(e,2,r),this._bufferView.set(e,3,i),this.makeDirty()}setElement(e,t,s){this._bufferView.set(e,t,s),this.makeDirty()}getElement(e,t){return this._bufferView.get(e,t)}setVec(e,t){this._bufferView.setVec(e,t),this.makeDirty()}setArray(e,t){this._bufferView.set(e,0,t[0]),this._bufferView.set(e,1,t[1]),this._bufferView.set(e,2,t[2]),this._bufferView.set(e,3,t[3]),this.makeDirty()}}class m extends u{constructor(e,t,s,r){super(e,t,s,r),this.elementCount=5}}class y extends m{constructor(e,t,s,r,i){super(e,s,r,i),this._bufferViewConstructor=t}updateBuffer(e){const{byteOffset:t,byteStride:s,_bufferViewConstructor:r}=this;this._bufferView=new r(e,t,s),this.makeDirty()}setValues(e,t,s,r,i,f){const u=254&r|f;this._bufferView.set(e,0,t),this._bufferView.set(e,1,s),this._bufferView.set(e,2,u),this._bufferView.set(e,3,i),this.makeDirty()}}const _={u8:{elementCount:1,byteSize:l(i),createField:(e,t,s,r)=>new o(e.name,i,t,s,r)},"packed-f24":{elementCount:1,byteSize:l(r),createField:(e,t,s,r)=>new a(e.name,t,s,r,e.maxValue)},"packed-f32":{elementCount:1,byteSize:l(s),createField:(e,t,s,r)=>new c(e.name,t,s,r,e.maxValue)},vec4u8:{elementCount:4,byteSize:l(s),createField:(e,t,r,i)=>new w(e.name,s,t,r,i)},u8u8u7xu8:{elementCount:5,byteSize:l(s),createField:(e,t,r,i)=>new y(e.name,s,t,r,i)}};function l(e){return f(e.ElementType)*e.ElementCount}const d=new Map;Object.entries(_).forEach(([e,t])=>{d.set(e,t)});const p=new Uint8Array(3),k=new Uint8Array(4);export{o as DefaultScalarField,b as DefaultVec3Field,w as DefaultVec4Field,u as Field,a as PackedF24Field,c as PackedF32Field,n as ScalarField,y as U8U8U7XU8Field,V as Vec4Field,m as Vec5Field,d as typeToCreationInfoMap};
|