UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 9.57 kB
import e from"../../../../Color.js";import{isSome as t,get as i,isNone as r,unwrap as n}from"../../../../core/maybe.js";import{pt2px as o}from"../../../../core/screenUtils.js";import{e as s}from"../../../../chunks/earcut.js";import{s as a}from"../../../../chunks/vec4.js";import{create as l,empty as c,expandWithBuffer as h,intersectsClippingArea as p,expandWithAABB as u}from"../../../../geometry/support/aaBoundingBox.js";import{SymbolUpdateType as d,elevationModeChangeUpdateType as m,needsElevationUpdates2D as _}from"./elevationAlignmentUtils.js";import{ElevationContext as g}from"./ElevationContext.js";import y from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as f}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as b}from"./Graphics3DSymbolLayer.js";import{mixinColorAndOpacity as x}from"./graphicUtils.js";import{parseCapType as v}from"./lineUtils.js";import{geometryAsPolygon as O,createColorGeometry as C,PolygonCreationDataBase as D}from"./polygonUtils.js";import{createMaterial as S,uvElevationAligner as j}from"../support/patternUtils.js";import{createMapSpaceUVCoords as A,createMapSpaceUVCoordsDraped as M}from"../support/uvUtils.js";import{createGeometry as P}from"../../support/engineContent/line.js";import{geometryToRenderInfo as E,geometryToRenderInfoDraped as L}from"../../support/renderInfoUtils/polygon.js";import{newDoubleArray as G,doubleSubArray as w,doubleArrayFrom as U}from"../../webgl-engine/lib/DoubleArray.js";import{newFloatArray as I,floatSubArray as R}from"../../webgl-engine/lib/FloatArray.js";import{Object3D as V}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as B}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as T}from"../../webgl-engine/lib/VertexAttribute.js";import{getStipplePatternForLinePattern as F}from"../../webgl-engine/materials/lineStippleUtils.js";import{PatternMaterial as H}from"../../webgl-engine/materials/PatternMaterial.js";import{RibbonLineMaterial as W}from"../../webgl-engine/materials/RibbonLineMaterial.js";const k=["polyline","polygon","extent"];class z extends b{constructor(e,t,i,r){super(e,t,i,r),this._needsUV=!1,this._hasOutline=!1}async doLoad(){}_ensureMaterials(){this._ensureFillMaterial(),this._ensureOutlineMaterial()}_ensureFillMaterial(){if(t(this._material))return;const e=i(this.symbolLayer,"material","color"),r=this._getCombinedOpacityAndColor(e);this._material=S(this.symbolLayer,{color:r,transparent:r[3]<1||this.needsDrivenTransparentPass,polygonOffset:!1,hasVertexColors:!0,writeLinearDepth:!0,hasSlicePlane:this._context.slicePlaneEnabled},{isDraped:this.draped}),this._needsUV=this._material instanceof H,this._context.stage.add(this._material)}_ensureOutlineMaterial(){const e=this.symbolLayer.outline;if(t(this._outlineMaterial)||!this._isValidOutline(e))return;this._hasOutline=!0;const i=t=>{const i=F(e.pattern);return new W({width:t,color:this._getOutlineColor(),hasPolygonOffset:!0,hasSlicePlane:this._context.slicePlaneEnabled,isClosed:!0,stipplePattern:i,stippleScaleWithLineWidth:!0,cap:v(e.patternCap||"butt")})};this._outlineMaterial=i(o(e.size)),this._context.stage.add(this._outlineMaterial)}_isValidOutline(e){return t(e)&&null!=e.size&&e.size>0&&t(e.color)&&(r(e.pattern)||"style"!==e.pattern.type||"none"!==e.pattern.style)}destroy(){super.destroy(),this._context.stage.remove(this._material),this._material=null,this._context.stage.remove(this._outlineMaterial),this._outlineMaterial=null}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,k,this.symbolLayer.type))return null;const i=this._getVertexOpacityAndColor(e.renderingInfo,255),r=this.setGraphicElevationContext(t,new g);return this.ensureDrapedStatus("on-the-ground"===r.mode),this._ensureMaterials(),this.draped?this._createAsOverlay(t,i):this._createAs3DShape(t,i,r)}layerOpacityChanged(){if(t(this._material)){const e=this._material.parameters.color,t=i(this.symbolLayer,"material","color"),r=this._getCombinedOpacity(t);this._material.setParameters({color:[e[0],e[1],e[2],r],transparent:r<1||this.needsDrivenTransparentPass})}if(t(this._outlineMaterial)){const e=this._outlineMaterial.parameters.color;this._outlineMaterial.setParameters({color:[e[0],e[1],e[2],this._getOutlineOpacity()]})}}layerElevationInfoChanged(e,t,i){const r=this._elevationContext.mode,n=m(z.elevationModeChangeTypes,i,r);if(n!==d.UPDATE)return n;const o=_(r);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>o))}slicePlaneEnabledChanged(){if(t(this._material)&&this._material.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),t(this._outlineMaterial)){const e={hasSlicePlane:this._context.slicePlaneEnabled};this._outlineMaterial.setParameters(e)}return!0}physicalBasedRenderingChanged(){return!0}pixelRatioChanged(){return!0}skipHighSymbolLodsChanged(){return!0}_createAs3DShape(e,t,i){const n=O(e.geometry);if(r(n))return null;const o=E(n,this._context.elevationProvider,this._context.renderCoordsHelper,i),s=new q(o,t,this._context.layer.uid,e.uid),a=s.renderData.position.length/3;if(this._needsUV&&(s.uvMapSpace=I(4*a,!0),s.boundingRect=G(9*a,!0),A(s.uvMapSpace,s.boundingRect,s.renderData.position,this._context.renderCoordsHelper)),s.objectAndLayerIdColor=this._context.stage.renderView?.getObjectAndLayerIdColor(s),this._createAs3DShapeFill(s),this._hasOutline&&this._createAs3DShapeOutline(s),this._logGeometryCreationWarnings(s.renderData,n.rings,"rings","FillSymbol3DLayer"),0===s.outGeometries.length)return null;const l=new V({geometries:s.outGeometries,castShadow:!1,metadata:{layerUid:this._context.layer.uid,graphicUid:e.uid}}),c=new f(this,l,s.outGeometries,null,null,j,i);return c.alignedSampledElevation=s.renderData.sampledElevation,c.needsElevationUpdates=_(i.mode),c}_createAs3DShapeFill(e){const i=e.renderData.polygons;for(const{position:r,mapPositions:o,holeIndices:a,index:l,count:u}of i){if(t(this._context.clippingExtent)&&(c(N),h(N,o),!p(N,this._context.clippingExtent)))continue;const i=s(o,a,3);if(0===i.length)continue;const d=C({material:n(this._material),indices:i,mapPositions:o,attributeData:{position:r,color:e.color,uvMapSpace:this._needsUV?R(e.uvMapSpace,4*l,4*u):null,boundingRect:this._needsUV?w(e.boundingRect,9*l,9*u):null,objectAndLayerIdColor:e.objectAndLayerIdColor}});e.outGeometries.push(d)}}_createAs3DShapeOutline(e){if(!this._hasOutline)return;const i=e.renderData.outlines;for(let r=0;r<i.length;++r){const{mapPositions:o,position:s}=i[r];if(t(this._context.clippingExtent)&&(c(N),h(N,o),!p(N,this._context.clippingExtent)))continue;const a=P(n(this._outlineMaterial),{overlayInfo:null,removeDuplicateStartEnd:!0,mapPositions:o,attributeData:{position:s}},e.objectAndLayerIdColor),l=a.vertexAttributes.get(T.POSITION);l.data===s&&(l.data=U(s)),e.outGeometries.push(a)}}_createAsOverlay(e,i){const o=O(e.geometry);if(r(o))return null;n(this._material).renderPriority=this._renderPriority+this._renderPriorityStep/2,t(this._outlineMaterial)&&(this._outlineMaterial.renderPriority=this._renderPriority);const s=L(o,this._context.overlaySR),a=new J(s,i,this._context.layer.uid,e.uid),l=a.renderData.position.length/3;return this._needsUV&&(a.uvMapSpace=I(4*l,!0),M(a.uvMapSpace,a.renderData.position,this._context.overlaySR,this._context.graphicsCoreOwner.view.state.viewingMode)),a.outBoundingBox=c(),a.objectAndLayerIdColor=this._context.stage.renderView?.getObjectAndLayerIdColor(a),this._createAsOverlayFill(a),this._hasOutline&&this._createAsOverlayOutline(a),this._logGeometryCreationWarnings(a.renderData,o.rings,"rings","FillSymbol3DLayer"),0===a.outGeometries.length?null:new y(this,a.outGeometries,a.outBoundingBox,this._context.drapeSourceRenderer)}_createAsOverlayFill(e){const t=e.renderData.polygons;for(const{position:i,holeIndices:r,index:o,count:l}of t){const t=c(N);if(h(t,i),!p(t,this._context.clippingExtent))continue;const d=s(i,r,3);if(0===d.length)continue;u(e.outBoundingBox,t);const m=C({material:n(this._material),indices:d,attributeData:{position:i,color:e.color,uvMapSpace:this._needsUV?R(e.uvMapSpace,4*o,4*l):null,objectAndLayerIdColor:e.objectAndLayerIdColor}}),_=new B(m,e);a(_.boundingSphere,.5*(t[0]+t[3]),.5*(t[1]+t[4]),0,.5*Math.sqrt((t[3]-t[0])*(t[3]-t[0])+(t[4]-t[1])*(t[4]-t[1]))),e.outGeometries.push(_)}}_createAsOverlayOutline(e){if(!this._hasOutline)return;const t=e.renderData.outlines;for(let i=0;i<t.length;++i){const{position:r}=t[i];if(c(N),h(N,r),!p(N,this._context.clippingExtent))continue;u(e.outBoundingBox,N);const o=P(n(this._outlineMaterial),{overlayInfo:{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper},removeDuplicateStartEnd:!0,attributeData:{position:r}},e.objectAndLayerIdColor),s=new B(o,e),l=N;a(s.boundingSphere,.5*(l[0]+l[3]),.5*(l[1]+l[4]),0,.5*Math.sqrt((l[3]-l[0])*(l[3]-l[0])+(l[4]-l[1])*(l[4]-l[1]))),e.outGeometries.push(s)}}_getOutlineOpacity(){const e=i(this.symbolLayer,"outline","color");return(this.draped?1:this._getLayerOpacity())*(t(e)?e.a:0)}_getOutlineColor(){const r=i(this.symbolLayer,"outline","color"),n=this._getOutlineOpacity();return x(t(r)?e.toUnitRGB(r):null,n)}test(){return{...super.test(),createAsOverlay:(e,t)=>this._createAsOverlay(e,t),createAs3DShape:(e,t,i)=>this._createAs3DShape(e,t,i)}}}z.elevationModeChangeTypes={definedChanged:d.RECREATE,staysOnTheGround:d.NONE,onTheGroundChanged:d.RECREATE};const N=l();class q extends D{constructor(e,t,i,r){super(e,i,r),this.color=t}}class J extends D{constructor(e,t,i,r){super(e,i,r),this.color=t}}export{z as Graphics3DPolygonFillSymbolLayer};