@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 6.86 kB
JavaScript
import e from"../../../../Color.js";import{isSome as t,isNone as r,unwrap as o}from"../../../../core/maybe.js";import{getMetersPerUnitForSR as i}from"../../../../core/unitUtils.js";import{e as n}from"../../../../chunks/earcut.js";import{s}from"../../../../chunks/vec2.js";import{f as a,a as l}from"../../../../chunks/vec2f64.js";import{b as c,s as h}from"../../../../chunks/vec4.js";import{t as m}from"../../../../chunks/common.js";import{create as p,empty as u,expandWithBuffer as d,intersectsClippingArea as g,expandWithAABB as y}from"../../../../geometry/support/aaBoundingBox.js";import{create as f,empty as _,expandPointInPlace as v}from"../../../../geometry/support/aaBoundingRect.js";import{perVertexElevationAligner as x}from"./ElevationAligners.js";import{SymbolUpdateType as b,elevationModeChangeUpdateType as D,needsElevationUpdates2D as C}from"./elevationAlignmentUtils.js";import{ElevationContext as S}from"./ElevationContext.js";import w from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as G}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as j}from"./Graphics3DSymbolLayer.js";import{geometryAsPolygon as E,createWaterGeometry as P,PolygonCreationDataBase as A}from"./polygonUtils.js";import{geometryToRenderInfo as O,geometryToRenderInfoDraped as R}from"../../support/renderInfoUtils/polygon.js";import{newDoubleArray as T,doubleSubArray as L}from"../../webgl-engine/lib/DoubleArray.js";import{Object3D as U}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as B}from"../../webgl-engine/lib/RenderGeometry.js";import{WaterMaterialParameters as M,WaterMaterial as V}from"../../webgl-engine/materials/WaterMaterial.js";import{wavePresets as I}from"../../webgl-engine/materials/internal/waterMaterialUtils.js";const W=["polyline","polygon","extent"];class k extends j{constructor(e,t,r,o){super(e,t,r,o)}async doLoad(){}destroy(){super.destroy(),this._context.stage.remove(this._material),this._material=null}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,W,this.symbolLayer.type))return null;const r=this.setGraphicElevationContext(t,new S);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.ensureMaterial(),this.draped?this._createAsOverlay(t):this._createAs3DShape(t,r,t.uid)}ensureMaterial(){if(t(this._material))return;const r=new M,o=this.symbolLayer.color;t(o)&&(r.color=e.toUnitRGBA(o));const i=this._getCombinedOpacity(o,{hasIntrinsicColor:!0});r.color=[r.color[0],r.color[1],r.color[2],i],r.transparent=i<1||this.needsDrivenTransparentPass,r.waveDirection=t(this.symbolLayer.waveDirection)?k.headingVectorFromAngle(this.symbolLayer.waveDirection):a(0,0);const n=this.symbolLayer.waveStrength+"-"+this.symbolLayer.waterbodySize,s=I[n];r.waveStrength=s.waveStrength,r.waveTextureRepeat=s.textureRepeat,r.waveVelocity=s.waveVelocity,r.flowStrength=s.perturbationStrength,r.hasSlicePlane=this._context.slicePlaneEnabled,r.isDraped=this.draped,this._material=new V(r),this._context.stage.add(this._material)}layerOpacityChanged(){if(r(this._material))return;const e=this._material.parameters.color,t=this._getCombinedOpacity(this.symbolLayer.color,{hasIntrinsicColor:!0}),o=t<1||this.needsDrivenTransparentPass;this._material.setParameters({color:[e[0],e[1],e[2],t],transparent:o})}layerElevationInfoChanged(e,t,r){const o=this._elevationContext.mode,i=D(k.elevationModeChangeTypes,r,o);if(i!==b.UPDATE)return i;const n=C(o);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>n))}slicePlaneEnabledChanged(){return t(this._material)&&this._material.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),!0}physicalBasedRenderingChanged(){return!0}pixelRatioChanged(){return!0}skipHighSymbolLodsChanged(){return!0}_createAs3DShape(e,t,o){const i=E(e.geometry);if(r(i))return null;const n=O(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),s=n.position.length/3,a=T(2*s);this._createUVCoordsFromVertices(a,n.mapPositions,s,this._context.elevationProvider.spatialReference);const l=new q(n,a);if(this._create3DShapeGeometries(l),this._logGeometryCreationWarnings(l.renderData,i.rings,"rings","WaterSymbol3DLayer"),0===l.outGeometries.length)return null;const c=new U({geometries:l.outGeometries,castShadow:!1,metadata:{layerUid:this._context.layer.uid,graphicUid:o}}),h=new G(this,c,l.outGeometries,null,null,x,t);return h.alignedSampledElevation=l.renderData.sampledElevation,h.needsElevationUpdates=C(t.mode),h}_createUVCoordsFromVertices(e,t,r,o){const n=i(o);_(F);for(let i=0;i<r;i++)s(H,t[3*i],t[3*i+1]),v(F,H);c(F,F,n);const a=F[0]%k.unitSizeOfTexture,l=F[1]%k.unitSizeOfTexture;z[0]=F[0]-a,z[1]=F[1]-l;for(let i=0;i<r;i++)e[2*i]=(t[3*i]*n-z[0])/k.unitSizeOfTexture,e[2*i+1]=(t[3*i+1]*n-z[1])/k.unitSizeOfTexture}_create3DShapeGeometries(e){const r=e.renderData.polygons,i=e.uvCoords;for(const{count:s,index:a,position:l,mapPositions:c,holeIndices:h}of r){if(t(this._context.clippingExtent)&&(u(N),d(N,c),!g(N,this._context.clippingExtent)))continue;const r=n(c,h,3);if(0===r.length)continue;const m=L(i,2*a,2*s),p=P({material:o(this._material),indices:r,mapPositions:c,attributeData:{position:l,uv0:m}});e.outGeometries.push(p)}}_createAsOverlay(e){const t=E(e.geometry);if(r(t))return null;o(this._material).renderPriority=this._renderPriority;const i=R(t,this._context.overlaySR),n=i.position.length/3,s=T(2*n);this._createUVCoordsFromVertices(s,i.position,n,this._context.overlaySR);const a=new J(i,s,this._context.layer.uid,e.uid);return a.outBoundingBox=u(),this._createAsOverlayWater(a),this._logGeometryCreationWarnings(a.renderData,t.rings,"rings","WaterSymbol3DLayer"),0===a.outGeometries.length?null:new w(this,a.outGeometries,a.outBoundingBox,this._context.drapeSourceRenderer)}_createAsOverlayWater(e){const t=e.uvCoords,r=e.renderData.polygons;for(const{position:i,holeIndices:s,index:a,count:l}of r){if(u(N),d(N,i),!g(N,this._context.clippingExtent))continue;y(e.outBoundingBox,N);const r=n(i,s,3);if(0===r.length)continue;const c=L(t,2*a,2*l),m=P({material:o(this._material),indices:r,attributeData:{position:i,uv0:c}}),p=new B(m,e),f=N;h(p.boundingSphere,.5*(f[0]+f[3]),.5*(f[1]+f[4]),0,.5*Math.sqrt((f[3]-f[0])*(f[3]-f[0])+(f[4]-f[1])*(f[4]-f[1]))),e.outGeometries.push(p)}}static headingVectorFromAngle(e){const t=l(),r=m(e);return t[0]=Math.sin(r),t[1]=Math.cos(r),t}test(){return{...super.test(),create3DShape:e=>this._createAs3DShape(e.graphic,e.elevationContext,e.graphicUid),ensureMaterial:()=>this.ensureMaterial()}}}k.unitSizeOfTexture=100,k.elevationModeChangeTypes={definedChanged:b.RECREATE,staysOnTheGround:b.NONE,onTheGroundChanged:b.RECREATE};const z=l(),F=f(),H=l(),N=p();class q extends A{constructor(e,t){super(e,null,null),this.uvCoords=t}}class J extends A{constructor(e,t,r,o){super(e,r,o),this.uvCoords=t}}export{k as Graphics3DWaterSymbolLayer};