UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 6.6 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{getMetersPerUnitForSR as e}from"../../../../core/units.js";import{e as t}from"../../../../chunks/earcut.js";import{set as r}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{fromValues as i,create as o}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{scale as n}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{toRadian as s}from"../../../../core/libs/gl-matrix-2/math/common.js";import{fromBuffer as a,intersectsClippingArea as l,empty as c,expandWithAABB as h,create as p}from"../../../../geometry/support/aaBoundingBox.js";import{empty as m,expandPointInPlace as u,create as d}from"../../../../geometry/support/aaBoundingRect.js";import{newFloatArray as g,floatSubArray as y}from"../../../../geometry/support/FloatArray.js";import{perVertexElevationAligner as f}from"./ElevationAligners.js";import{elevationModeChangeUpdateType as v,needsElevationUpdates2D as x}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as _}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as b}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as w}from"./Graphics3DSymbolLayer.js";import{geometryAsPolygon as D,createWaterGeometry as S,PolygonCreationDataBase as C}from"./polygonUtils.js";import{polygonToRenderInfo as G,polygonToRenderInfoDraped as j}from"../../support/renderInfoUtils/polygon.js";import{Object3D as P}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as L}from"../../webgl-engine/lib/RenderGeometry.js";import{Parameters as O,WaterMaterial as A}from"../../webgl-engine/materials/WaterMaterial.js";import{wavePresets as E}from"../../webgl-engine/materials/internal/waterMaterialUtils.js";const T=["polyline","polygon","extent"];class U extends w{static{this.unitSizeOfTexture=100}static{this.elevationModeChangeTypes={definedChanged:2,staysOnTheGround:0,onTheGroundChanged:2}}constructor(e,t,r,i){super(e,t,r,i)}async doLoad(){}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,T,this.symbolLayer.type))return null;const r=this.createElevationContextForGraphic(t);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.ensureMaterial(),this.draped?this._createAsOverlay(t):this._createAs3DShape(t,r,t.uid)}ensureMaterial(){if(this._materials[0])return;const e=new O,t=this.symbolLayer.color.toUnitRGBA();t[3]*=this._getLayerOpacity(),e.color=t,e.transparent=t[3]<1||this.needsDrivenTransparentPass,e.waveDirection=null!=this.symbolLayer.waveDirection?B(this.symbolLayer.waveDirection):i(0,0);const r=this.symbolLayer.waveStrength+"-"+this.symbolLayer.waterbodySize,o=E[r];e.waveStrength=o.waveStrength,e.waveTextureRepeat=o.textureRepeat,e.waveVelocity=o.waveVelocity,e.flowStrength=o.perturbationStrength,e.hasSlicePlane=this._context.slicePlaneEnabled,e.draped=this.draped,this._materials[0]=new A(e,this._context)}layerOpacityChanged(){if(null==this._materials[0])return;const e=this._materials[0].parameters.color,t=this.symbolLayer.color.a*this._getLayerOpacity(),r=t<1||this.needsDrivenTransparentPass;this._materials[0].setParameters({color:[e[0],e[1],e[2],t],transparent:r})}layerScreenSizePerspectiveChanged(){}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,o=v(U.elevationModeChangeTypes,r,i);if(1!==o)return o;const n=x(i);return this.updateGraphics3DGraphicElevationInfo(e,t,()=>n)}slicePlaneEnabledChanged(){return this._materials[0]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),!0}physicalBasedRenderingChanged(){return!0}get needsDrivenTransparentPass(){return!1}_createAs3DShape(e,t,r){const i=D(e.geometry);if(null==i)return null;const o=G(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),n=o.position.length/3,s=g(2*n);M(s,o.mapPositions,n,this._context.elevationProvider.spatialReference);const a=new W(o,s,this._context.layerViewUid,e.uid);if(a.olidColor=this._context.stage.renderView?.getObjectAndLayerIdColor(a),this._create3DShapeGeometries(a),this._logGeometryCreationWarnings(a.renderData,i.rings,"rings","WaterSymbol3DLayer"),0===a.outGeometries.length)return null;const l=new P({geometries:a.outGeometries,castShadow:!1,layerViewUid:this._context.layerViewUid,graphicUid:r}),c=new b(this,l,null,f,t);return c.alignedSampledElevation=a.renderData.sampledElevation,c.needsElevationUpdates=x(t.mode),c}_create3DShapeGeometries(e){const r=e.renderData.polygons,i=e.uvCoords;for(const{count:o,index:n,position:s,mapPositions:c,holeIndices:h}of r){if(null!=this._context.clippingExtent&&(a(c,I),!l(I,this._context.clippingExtent)))continue;const r=t(c,h,3);if(0===r.length)continue;const p=y(i,2*n,2*o),m=S({material:this._materials[0],indices:r,mapPositions:c,attributeData:{position:s,uv0:p}},e.olidColor);e.outGeometries.push(m)}}_createAsOverlay(e){const t=D(e.geometry);if(null==t)return null;this._materials[0].renderPriority=this._renderPriority;const r=j(t,this._context.overlaySR),i=r.position.length/3,o=g(2*i);M(o,r.position,i,this._context.overlaySR);const n=new F(r,o,this._context.layerViewUid,e.uid);return n.olidColor=this._context.stage.renderView?.getObjectAndLayerIdColor(n),n.outBoundingBox=c(),this._createAsOverlayWater(n),this._logGeometryCreationWarnings(n.renderData,t.rings,"rings","WaterSymbol3DLayer"),0===n.outGeometries.length?null:new _(this,n.outGeometries,n.outBoundingBox,this._context.drapeSourceRenderer)}_createAsOverlayWater(e){const r=e.uvCoords,i=e.renderData.polygons;for(const{position:o,holeIndices:n,index:s,count:c}of i){if(a(o,I),!l(I,this._context.clippingExtent))continue;h(e.outBoundingBox,I);const i=t(o,n,3);if(0===i.length)continue;const p=y(r,2*s,2*c),m=S({material:this._materials[0],indices:i,attributeData:{position:o,uv0:p}},e.olidColor);e.outGeometries.push(new L(m,e))}}test(){return{...super.test(),create3DShape:e=>this._createAs3DShape(e.graphic,e.elevationContext,e.graphicUid),ensureMaterial:()=>this.ensureMaterial()}}}function B(e){const t=o(),r=s(e);return t[0]=Math.sin(r),t[1]=Math.cos(r),t}function M(t,i,o,s){const a=e(s);m(V);for(let e=0;e<o;e++)r(z,i[3*e],i[3*e+1]),u(V,z);n(V,V,a);const l=V[0]%U.unitSizeOfTexture,c=V[1]%U.unitSizeOfTexture;R[0]=V[0]-l,R[1]=V[1]-c;for(let e=0;e<o;e++)t[2*e]=(i[3*e]*a-R[0])/U.unitSizeOfTexture,t[2*e+1]=(i[3*e+1]*a-R[1])/U.unitSizeOfTexture}const R=o(),V=d(),z=o(),I=p();class W extends C{constructor(e,t,r,i){super(e,r,i),this.uvCoords=t}}class F extends C{constructor(e,t,r,i){super(e,r,i),this.uvCoords=t}}export{U as Graphics3DWaterSymbolLayer,B as headingVectorFromAngle};