UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 9.66 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */ import{clone as t}from"../../../../core/lang.js";import{getMetersPerVerticalUnitForSR as e}from"../../../../core/units.js";import{e as r}from"../../../../chunks/earcut.js";import{normalFromMat4 as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{invert as o,invertOrIdentity as n}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as l,sub as c,cross as m,add as p,normalize as h,transformMat4 as d}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{ONES as u,create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{computeTranslationToOriginAndRotation as y}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{create as f,fromBuffer as b,intersectsClippingArea as _}from"../../../../geometry/support/aaBoundingBox.js";import{newDoubleArray as x}from"../../../../geometry/support/DoubleArray.js";import{newIndexArray as j,getZeroIndexArray as S}from"../../../../geometry/support/Indices.js";import{t as w}from"../../../../chunks/vec3.js";import{SnappingCandidateVertex as P,SnappingCandidateEdge as v}from"../../../../layers/graphics/data/SnappingCandidate.js";import{getDriverAxisSizeValue as C}from"../../../../renderers/support/renderingInfoUtils.js";import{needsElevationUpdates3D as E,SampleElevationInfo as A}from"./elevationAlignmentUtils.js";import{extrudePolygon as D}from"./extrudeUtils.js";import{Object3DEdgeState as I,Graphics3DObject3DGraphicLayer as U}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as z}from"./Graphics3DSymbolLayer.js";import{computeCentroid as M}from"./graphicUtils.js";import{geometryAsPolygon as O}from"./polygonUtils.js";import{createMaterial as L}from"../support/edgeUtils.js";import{encodeNaNUInt8 as G}from"../support/symbolColorUtils.js";import{debugFlags as V}from"../../support/debugFlags.js";import{SamplePosition as T}from"../../support/ElevationProvider.js";import{polygonToRenderInfo as B}from"../../support/renderInfoUtils/polygon.js";import{Attribute as F}from"../../webgl-engine/lib/Attribute.js";import{Geometry as R}from"../../webgl-engine/lib/Geometry.js";import{isGeometryWithMapPositions as H}from"../../webgl-engine/lib/GeometryWithMapPositions.js";import{compressNormals as N,compressNormal as W}from"../../webgl-engine/lib/Normals.js";import{Object3D as k}from"../../webgl-engine/lib/Object3D.js";import{DefaultMaterial as q}from"../../webgl-engine/materials/DefaultMaterial.js";const Z=["polygon","extent"];class J extends z{constructor(t,e,r,s){super(t,e,r,s,$(e)),this.ensureDrapedStatus(!1)}async doLoad(){const t=this.symbolLayer,e=t?.material,r=this.symbolLayer.material?.color?.a,s=this.needsDrivenTransparentPass||null!=r&&1!==r,i=e?.emissive,o=("color"===i?.source?i?.strength:void 0)??0,n=!this._hasDrivenColorOrOpacity&&(null==r||0===r),a={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,ambient:u,diffuse:u,opacity:n?0:1,layerOpacity:this._getLayerOpacity(),drivenOpacity:s,hasSymbolColors:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:t.castShadows,emissiveStrengthFromSymbol:o,emissiveSource:1,offsetTransparentBackfaces:!0,normalType:1},l=new q(a,this._context),c=new q({...a,cullFace:2},this._context);this._materials[0]=l,this._materials[1]=c,this._updateTransparentDepedentMaterialParameters()}destroy(){super.destroy(),this._materials.length=0}createGraphics3DGraphic(t){const e=t.graphic;if(!this._validateGeometry(e.geometry,Z,this.symbolLayer.type))return null;const r=this._getDrivenUInt8ColorWithNaNSupport(t.renderingInfo,this._materialColor,!1);G(r,r);const s=this.createElevationContextForGraphic(e);return this._createAs3DShape(e,t.renderingInfo,r,s,e.uid)}layerOpacityChanged(t,e){const r=this._getLayerOpacity();this._materials[0]?.setParameters({layerOpacity:r}),this._materials[1]?.setParameters({layerOpacity:r}),this._updateTransparentDepedentMaterialParameters(),t?.forEach(t=>e(t)?.layerOpacityChanged(r,this._context.isAsync))}layerScreenSizePerspectiveChanged(){}layerElevationInfoChanged(t,e){return this.updateGraphics3DGraphicElevationInfo(t,e,E)}slicePlaneEnabledChanged(t,e){return this._materials[0]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),this._materials[1]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),t?.forEach(t=>{const r=e(t);null!=r&&r.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync)}),!0}physicalBasedRenderingChanged(){const t={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0};return this._materials[0]?.setParameters(t),this._materials[1]?.setParameters(t),!0}_getExtrusionSize(t){let e;return e=t.size&&this._drivenProperties.size?C(t.size.output,2)??0:this._getSymbolSize(),e/=this._context.renderCoordsHelper.unitInMeters,e}applyRendererDiff(t,e){return this._drivenPropertiesChanged(e)?0:1}async queryForSnapping(r,s,i,o){const n=this._getExtrusionSize(i)*this._context.renderCoordsHelper.unitInMeters/e(s),{objectId:a,target:l}=r,c=t(l);switch(c.z=(c.z??0)+n,r.type){case"edge":{const{start:e,end:s}=r,i=t(e),o=t(s);return i.z=(i.z??0)+n,o.z=(o.z??0)+n,[new v(a,c,1/0,i,o)]}case"vertex":return[new P(a,c,1/0),new v(a,l,1/0,l,c)];default:return[]}}_getSymbolSize(){return this.symbolLayer.size??1}_createAs3DShape(t,e,n,l,c){const m=O(t.geometry);if(null==m)return null;if(0===m.rings.length||!m.rings.some(t=>t.length>0))return this._logGeometryValidationWarnings(m.rings,"rings","ExtrudeSymbol3DLayer"),null;const p=B(m,this._context.elevationProvider,this._context.renderCoordsHelper,l);this._logGeometryCreationWarnings(p,m.rings,"rings","ExtrudeSymbol3DLayer");const h=M(m);if(null==h)return null;const d=new Array,u=new Array,S=f(),P=a(),v=g(),C=1===this._context.renderCoordsHelper.viewingMode;C||this._context.renderCoordsHelper.worldUpAtPosition(null,v),y(m.spatialReference,[h.x,h.y,0],P,this._context.renderCoordsHelper.spatialReference);const A=a();o(A,P);const z=i();s(z,A);const{polygons:G,mapPositions:V,position:T}=p,F=new Map,R=this._materials[0];for(const s of G){const t=s.count;if(this._context.clippingExtent&&(b(s.mapPositions,S),!_(S,this._context.clippingExtent)))continue;const i=r(s.mapPositions,s.holeIndices,3);if(0===i.length)continue;const o=i.length,a=6*t,l=j(a+o),m=j(o),p=x(3*a),h=x(3*a),g=x(3*a),y=x(a),f=this._getExtrusionSize(e);D(T,V,i,s,p,g,h,y,l,m,f,v,C),w(p,p,A);const E=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:c,layerViewUid:this._context.layerViewUid}),I=new at(p,g,N(h),y),U=K(R,l,l.length-m.length,I,n,E),z=t,M=t,O=2*s.count,L=new lt(z,M,O,o/3);Y(U,L,P),F.set(U,L),d.push(U,K(this._materials[1],m,0,I,n,E)),u.push(I.heights)}if(0===d.length)return null;const H=new k({geometries:d,layerViewUid:this._context.layerViewUid,graphicUid:c,isElevationSource:!0});H.transformation=P;const W=L(this.symbolLayer,{opacity:this._getLayerOpacity()}),q=W?new I(this._materials[0],W,this._context.slicePlaneEnabled):null,Z=new U(this,H,null,(t,e,r,s,i)=>X(t,e,r,s,i,u,F),l,q);return Z.alignedSampledElevation=p.sampledElevation,Z.needsElevationUpdates=E(l.mode),Z}get _materialColor(){return this.symbolLayer.material?.color}_updateTransparentDepedentMaterialParameters(){const t=this._materials[0];t&&t.setParameters({cullFace:t.transparent?0:2})}}function K(t,e,r,s,i,o){const n=S(e.length),a=[["position",new F(s.positions,e,3,!0)],["normalCompressed",new F(s.normals,e,2,!0)],["symbolColor",new F(i,n,4,!0)]];return new R(t,a,s.elevation,0,o,r)}const Q=g();function X(t,e,r,s,i,o,c){const m=t.stageObject,p=m.geometries,h=p.length,u="absolute-height"!==e.mode;let g=0;const y=m.transformation,f=n(a(),y);for(let n=0;n<h;n+=2){const t=p[n];if(!H(t))continue;const e=t.getMutableAttribute("position").data,a=o[n/2],h=new T(t.mapPositions),b=e.length/3;let _=!1,x=0;{let t=0;for(let o=0;o<b;o++){Q[0]=e[t],Q[1]=e[t+1],Q[2]=e[t+2],s(h,rt),u&&(x+=rt.sampledElevation),V.TESTS_DISABLE_OPTIMIZATIONS?(l(tt,h.array[h.offset],h.array[h.offset+1],rt.z+a[t/3]),null!=r&&i.toRenderCoords(tt,r,tt),d(tt,tt,f)):(l(tt,e[t],e[t+1],e[t+2]),d(tt,tt,y),i.setAltitude(tt,rt.z+a[t/3]),d(tt,tt,f)),e[t]=tt[0],e[t+1]=tt[1],e[t+2]=tt[2];const o=st/i.unitInMeters;(Math.abs(Q[0]-e[t])>=o||Math.abs(Q[1]-e[t+1])>=o||Math.abs(Q[2]-e[t+2])>=o)&&(_=!0),h.offset+=3,t+=3}}if(_){const e=c.get(t);e&&Y(t,e,y),m.geometryVertexAttributeUpdated(p[n],"normalCompressed"),t.invalidateBoundingInfo(),m.geometryVertexAttributeUpdated(p[n],"position"),p[n+1].invalidateBoundingInfo(),m.geometryVertexAttributeUpdated(p[n+1],"position")}g+=x/b}return g/h}function Y(t,e,r){const s=t.getMutableAttribute("position"),i=t.getMutableAttribute("normalCompressed").data,o=s.data,n=t.attributes.get("position").indices,{topVertexStart:a,topVertexCount:u,topFaceStart:g,topFaceCount:y}=e,f=g+y,b=a+u,_=it,x=ot,j=nt,S=et,w=tt;l(w,0,0,0);const P=(t,e)=>{const s=3*t;l(e,o[s+0],o[s+1],o[s+2]),d(e,e,r)};for(let l=g;l<f;++l){const t=3*l;P(n[t+0],_[0]),P(n[t+1],_[1]),P(n[t+2],_[2]),c(x,_[1],_[0]),c(j,_[2],_[0]),m(S,x,j),p(w,w,S)}h(w,w);for(let l=a;l<b;++l){const t=w[0],e=w[1],r=w[2];W(i,l,t,e,r)}}function $(t){return 1===(t.material?.color?.a??0)}const tt=g(),et=g(),rt=new A,st=.01,it=[g(),g(),g()],ot=g(),nt=g();class at{constructor(t,e,r,s){this.positions=t,this.elevation=e,this.normals=r,this.heights=s}}class lt{constructor(t,e,r,s){this.topVertexStart=t,this.topVertexCount=e,this.topFaceStart=r,this.topFaceCount=s}}export{J as Graphics3DExtrudeSymbolLayer};