UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 8.86 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import"../../../../../core/has.js";import e from"../../../../../core/Logger.js";import t from"../../../../../core/PooledArray.js";import{isTypedArray as i}from"../../../../../core/typedArrayUtil.js";import{clone as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as o}from"../../../../../geometry/support/aaBoundingBox.js";import{compactIndices as r}from"../../../../../geometry/support/Indices.js";import{c as s}from"../../../../../chunks/vec3.js";import{c as a}from"../../../../../chunks/vec32.js";import{ComponentData as c}from"./ComponentData.js";import{defaultComponentParameters as l,ComponentDrawParametersImplementation as m}from"./ComponentDrawParameters.js";import{ComponentObject as h}from"./ComponentObject.js";import{IntersectionGeometry as p}from"./IntersectionGeometry.js";import{Renderable as f}from"./Renderable.js";import{RenderGeometry as g}from"./RenderGeometry.js";import{RenderSubmitSystem as d}from"./RenderSubmitSystem.js";import{ComponentMaterialRepository as u}from"./Material/ComponentMaterialRepository.js";import{VertexArrayObject as b}from"../../lib/VertexArrayObject.js";import{getVerticalOffsetI3S as y}from"../../lib/verticalOffsetUtils.js";import{BufferManager as v}from"../../lib/TextureBackedBuffer/BufferManager.js";import{getComponentDataLayout as _,IndexGlLayout as M}from"../../materials/DefaultLayouts.js";import{BufferObject as C}from"../../../../webgl/BufferObject.js";import{PrimitiveType as j}from"../../../../webgl/enums.js";import{VertexBuffer as w}from"../../../../webgl/VertexBuffer.js";const O=()=>e.getLogger("esri.views.3d.webgl-engine.collections.Component.ComponentObjectCollection");class D{constructor(e,i,n){this._renderManager=e,this._viewingMode=i,this._elevationRangeCacheVerticalOffset=NaN,this._elevationRangeCacheMin=NaN,this._elevationRangeCacheMax=NaN,this._activeHighlightOptions=new Map,this._visible=new t,this._hidden=new t,this._renderSubmit=new d(this),this._renderManager.register(this._renderSubmit);const{rctx:o}=e;this._componentBufferManager=new v(o,_());const r=2===this._viewingMode?0:n?1:2;this.materialRepository=new u(o,r)}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,t){const{geometry:i}=e,n=new c(this._componentBufferManager,r(i.componentOffsets)),o=this._createRenderable(e,t,n),s=new p(this._viewingMode,i.positions,n,e.elevationAlignable),a=new h(this,e.transform,e.obb.clone(),n,o,s);return(a.visible?this._visible:this._hidden).push(a),a}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{camera:t}=e;this._componentBufferManager.updateTextures(),this.visibleObjects.forAll(e=>e.updateCameraDerivedParameters(t))}updateMaterial(e,t){e.updateMaterial(t)}getObjectOpacity(e){return e.renderable.drawParameters.opacity}updateObjectOpacity(e,t){const i=e;i.opacity!==t&&(i.updateOpacity(t),this._notifyDirty())}isSliceplaneEnabled(e){return e.renderable.material.slicePlaneEnabled}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,{componentData:i}=t,n=i.visibility.componentCount;return{visible:n,invisible:i.count-n}}setComponentData(e,t){e.setComponentData(t,this._viewingMode),this._elevationRangeCacheVerticalOffset=NaN,this._notifyDirty()}getComponentAabb(e,t,i,n=!1){e.intersectionGeometry.getComponentAabb(t,i);const o=e,r=o.componentData.verticalOffsets;if(n||null==r)return i;const s=r[t];if(2===this._viewingMode||0===s)return i[2]+=s,i[5]+=s,i;const a=y(s);return a.localOrigin=o.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,n){Number.isNaN(this._elevationRangeCacheVerticalOffset)||this._elevationRangeCacheVerticalOffset!==t||n.expandElevationRangeValues(this._elevationRangeCacheMin,this._elevationRangeCacheMax);const o=e,{componentData:r}=o,s=r.count,{verticalOffsets:a}=r,{intersectionGeometry:c}=o,l=2===this._viewingMode,m=c.getComponentAabbs(),h=R;let p=1/0,f=-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=y(r);e.localOrigin=o.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;n.expandElevationRangeValues(t+h[2],Math.sqrt(s*s+a*a+c*c)-i)}n.expandElevationRangeValues(s,c),p=Math.min(p,s),f=Math.max(f,c)}this._elevationRangeCacheVerticalOffset=t,this._elevationRangeCacheMin=p,this._elevationRangeCacheMax=f}intersect(e,t,i,n,o,r){const s=e,{transform:a,componentData:c,intersectionGeometry:l}=s;return null!=n&&(n.localOrigin=a.position),l.intersect(t,i,n,c.verticalOffsets,a,o,r)}addEdges(e,t,i,n,o){const r=e,{indices:s,positions:a}=r.intersectionGeometry,c=r.componentData.offsets;return t.addComponentObject(r,a,s,c,i,n,o)}async extractEdgeInformation(e,t,i){const o=e,r=o.componentData.visibility;if(r.allInvisible()){const{extractComponentsEdgeLocationsLayout:e}=await import("../../lib/edgeRendering/edgeProcessing.js");return{buffer:e.createBuffer(0),origin:[0,0,0]}}const{indices:c,positions:l}=o.intersectionGeometry,m=o.componentData.offsets,{EdgeInputBufferLayout:h}=await import("../../lib/edgeRendering/bufferLayouts.js"),p=h.createBuffer(l.length/3);a(p.position.typedBuffer,l,p.position.typedBufferStride,3),s(p.position,p.position,o.transform.rotationScale),this._setComponentIndices(p.componentIndex,c,m);const f=p.count,g=this._computeVisibilityIndices(c,r,m,f);return{origin:n(o.transform.position),buffer:await t.extractComponentsEdgeLocations({indices:g,indicesLength:g.length,skipDeduplicate:!0,data:p,writerSettings:{reducedPrecision:!1,variants:0}},i)}}_setComponentIndices(e,t,i){let n=0;for(let o=0;o<i.length-1;o++){const r=i[o],s=i[o+1];for(let i=r;i<s;i++){const o=t?t[i]:i;e.set(o,n)}n++}}_computeVisibilityIndices(e,t,n,o){if(e&&t.allVisible())return e;let r=0;t.forEachComponentRange((e,t)=>(r+=n[t]-n[e],!0));const s=i(e)?2===e?.BYTES_PER_ELEMENT||o<=65536?new Uint16Array(r):new Uint32Array(r):new Array(r);let a=0;return t.forEachComponentRange((t,i)=>{const o=n[t],r=n[i];for(let n=o;n<r;n++)s[a++]=e?e[n]:n;return!0}),s}addComponentHighlight(e,t,i){const n=e;{const e=this._activeHighlightOptions.get(i)??0;this._activeHighlightOptions.set(i,e+1)}n.addComponentHighlight(t,i)&&this._notifyDirty()}removeComponentHighlight(e,t,i){const n=e.removeComponentHighlight(t,i);"notfound"!==n&&(this._removeActiveHighlight(i),n&&this._notifyDirty())}_removeActiveHighlight(e,t=1){const i=this._activeHighlightOptions.get(e);if(void 0===i)O().warn(`Removing non-existing highlight "${e}".`);else{const n=i-t;n<0&&O().warn(`Removing non-existing highlight "${e}".`),n<=0?this._activeHighlightOptions.delete(e):this._activeHighlightOptions.set(e,n)}}clearHighlights(e){const t=e,{componentData:i}=t,{componentHighlights:n}=t.componentData;if(n.size>0){for(const e of n)this._removeActiveHighlight(e[0],e[1][i.count]);t.clearHighlights(),this._notifyDirty()}}hasHighlight(e){return this._activeHighlightOptions.has(e)}getObjectGPUMemoryUsage(e){return e.renderable.meta.gpuMemoryEstimate}get visibleObjects(){return this._visible}_createRenderable(e,t,i){const n=this._renderManager.rctx,o=e.geometry,r=o.parameters.layout,s=new w(n,r,o.vertices.data),a=o.indices?C.createIndex(n,35044,o.indices):null;let c=0;const h=[["geometry",s]];if(!t.isIntegratedMesh){const e=new Uint16Array(o.vertices.count);for(let n=0;n<i.count;n++){const t=i.offsets[n],r=i.offsets[n+1],s=i.materialDataIndices[n];if(null!=o.indices)for(let i=t;i<r;i++){e[o.indices[i]]=s}else for(let i=t;i<r;i++)e[i]=s}const t=new w(n,M,e.buffer);c+=t.usedMemory,h.push(["componentIndices",t])}const p=new b(n,new Map(h),a),d=new g(p,j.TRIANGLES,o.parameters,null!=a),u=this.materialRepository.acquireMaterial(t,d.parameters,l),y={cameraDepthSquared:.5,gpuMemoryEstimate:s.usedMemory+c+(null!=a?a.usedMemory:0)},v=new m(e,t);return new f(u,v,d,y)}_notifyDirty(){this._renderManager.notifyDirty()}}const R=o();export{D as ComponentObjectCollection};