@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 13.3 kB
JavaScript
import"../../../../geometry.js";import e from"../../../../core/Error.js";import{isSome as t,applySome as r,isNone as a,releaseMaybe as i,unwrapOr as s,get as o,unwrap as n}from"../../../../core/maybe.js";import{px2pt as l,pt2px as h}from"../../../../core/screenUtils.js";import{s as c}from"../../../../chunks/vec4.js";import{f as p,d}from"../../../../chunks/vec4f64.js";import{create as m,empty as _,expandWithBuffer as y,intersectsClippingArea as u,expandWithAABB as g}from"../../../../geometry/support/aaBoundingBox.js";import{getDriverAxisSizeValueAny as f}from"../../../../renderers/support/renderingInfoUtils.js";import{sharedGeometryElevationAligner as C}from"./ElevationAligners.js";import{SymbolUpdateType as M,elevationModeChangeUpdateType as b,needsElevationUpdates2D as v}from"./elevationAlignmentUtils.js";import{ElevationContext as E}from"./ElevationContext.js";import L from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as P}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as w,getAttributeValue as x}from"./Graphics3DSymbolLayer.js";import{ApplyRendererDiffResult as k}from"./interfaces.js";import{parseLineMarkerStyle as D,parseCapType as S}from"./lineUtils.js";import{initFastSymbolUpdatesState as U,updateFastSymbolUpdatesState as R}from"../support/FastSymbolUpdates.js";import A from"../../support/debugFlags.js";import{createGeometry as j}from"../../support/engineContent/line.js";import{prepareMarkerResources as z}from"../../support/engineContent/marker.js";import{geometryToRenderInfo as O,geometryToRenderInfoDraped as G}from"../../support/renderInfoUtils/line.js";import{Object3D as V}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as I}from"../../webgl-engine/lib/RenderGeometry.js";import{LineMarkerMaterial as T}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{getStipplePatternForLinePattern as F}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as W}from"../../webgl-engine/materials/RibbonLineMaterial.js";import H from"../../../../geometry/Extent.js";import B from"../../../../geometry/Polygon.js";const N=["polyline","polygon","extent"];class q extends w{constructor(e,t,r,a){super(e,t,r,a)}async doLoad(){if(this._vvConvertOptions={modelSize:[1,1,1],symbolSize:[1,1,1],unitInMeters:1,transformation:{anchor:[0,0,0],scale:[1,1,1],rotation:[0,0,0]},supportedTypes:{size:!0,color:!0,opacity:!0,rotation:!1}},this._context.renderer&&this._context.renderer.visualVariables&&this._context.renderer.visualVariables.length>0?this._fastUpdates=U(this._context.renderer,this._vvConvertOptions):this._fastUpdates={enabled:!1},!this._drivenProperties.size){if((null!=this.symbolLayer.size?this.symbolLayer.size:l(1))<0)throw new e("graphics3dlinesymbollayer:invalid-size","Symbol sizes may not be negative values")}this._markerTexture=t(this.symbolLayer.marker)&&t(this._context.sharedResources.textures)?z(this._context.sharedResources.textures,D(this.symbolLayer.marker.style)):null}_getMaterialParameters(e,t=!1){const r=this._getCombinedOpacityAndColor(t&&this._markerColor||this._materialColor);this._patternHidesLine&&!t&&(r[3]=0);const a={width:this._computeMaterialWidth(this.symbolLayer?.size),color:r,hasPolygonOffset:!0,join:this.symbolLayer.join||"miter",cap:S(this.symbolLayer.cap||"butt"),hasSlicePlane:this._context.slicePlaneEnabled,isClosed:e,stipplePattern:F(this.symbolLayer.pattern),stippleScaleWithLineWidth:!0};return this._fastUpdates&&this._fastUpdates.visualVariables?{...a,...this._fastUpdates.materialParameters}:a}get _materialColor(){return r(this.symbolLayer.material,(e=>e.color))}get _markerColor(){return r(this.symbolLayer.marker,(e=>e.color))}get _lineMaterial(){return a(this._lineMaterialCached)&&(this._lineMaterialCached=new W(this._getMaterialParameters(!1)),this._context.stage.add(this._lineMaterialCached)),this._lineMaterialCached}get _ringMaterial(){return a(this._ringMaterialCached)&&(this._ringMaterialCached=new W(this._getMaterialParameters(!0)),this._context.stage.add(this._ringMaterialCached)),this._ringMaterialCached}get _wireframeLineMaterial(){return a(this._wireframeLineMaterialCached)&&(this._wireframeLineMaterialCached=new W({...this._getMaterialParameters(!1),wireframe:!0}),this._context.stage.add(this._wireframeLineMaterialCached)),this._wireframeLineMaterialCached}get _wireframeRingMaterial(){return a(this._wireframeRingMaterialCached)&&(this._wireframeRingMaterialCached=new W({...this._getMaterialParameters(!0),wireframe:!0}),this._context.stage.add(this._wireframeRingMaterialCached)),this._wireframeRingMaterialCached}get _markerMaterial(){return a(this._markerMaterialCached)&&t(this.symbolLayer.marker)&&t(this._markerTexture)&&(this._markerMaterialCached=new T({...this._getMaterialParameters(!1,!0),placement:this.symbolLayer.marker.placement,textureId:this._markerTexture.texture.id}),this._context.stage.add(this._markerMaterialCached)),this._markerMaterialCached}destroy(){super.destroy(),this._forEachMaterial((e=>this._context.stage.remove(e))),this._lineMaterialCached=null,this._ringMaterialCached=null,this._wireframeLineMaterialCached=null,this._wireframeRingMaterialCached=null,this._markerMaterialCached=null,this._markerTexture=i(this._markerTexture)}_getDrivenSize(e){return this._drivenProperties.size&&e.size?h(f(e.size)):1}_getSizeFeatureAttributeData(e){return this._fastUpdates.enabled&&this._fastUpdates.visualVariables.size?x(this._fastUpdates.visualVariables.size.field,e):null}_getDrivenColor(e){const t=p(1,1,1,1);return this._drivenProperties.color&&e.color&&(t[0]=e.color[0],t[1]=e.color[1],t[2]=e.color[2],e.color.length>0&&(t[3]=e.color[3])),this._drivenProperties.opacity&&e.opacity&&(t[3]=e.opacity),t}_getColorFeatureAttributeData(e){return this._fastUpdates.enabled&&this._fastUpdates.visualVariables.color?x(this._fastUpdates.visualVariables.color.field,e):null}_getOpacityFeatureAttributeData(e){return this._fastUpdates.enabled&&this._fastUpdates.visualVariables.opacity?x(this._fastUpdates.visualVariables.opacity.field,e):null}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,N,this.symbolLayer.type))return null;const r=this.setGraphicElevationContext(t,new E);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.draped?this._createAsOverlay(e,this._context.layer.uid):this._createAs3DShape(e,r,t.uid)}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return k.Recreate_Symbol;if(!R(this._fastUpdates,t,this._vvConvertOptions))return k.Recreate_Symbol;this._forEachMaterial((e=>e.setParameters(this._fastUpdates.materialParameters)))}return k.Fast_Update}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff,r={};"complete"===t.size?.type&&(r.width=this._computeMaterialWidth(t.size.newValue),delete t.size),"complete"===t.cap?.type&&(r.cap=S(s(t.cap.newValue,"butt")),delete t.cap);const a=this._prepareMarkerPatch(e,t);this._prepareMaterialPatch(e,t,a),e.symbolLayerStatePatches.push((()=>this._forEachMaterial((e=>e.setParameters(r)))))}layerOpacityChanged(){this._forEachMaterial(((e,t)=>this._updateMaterialLayerOpacity(e,t)))}_forEachMaterial(e){t(this._lineMaterialCached)&&e(this._lineMaterialCached),t(this._ringMaterialCached)&&e(this._ringMaterialCached),t(this._wireframeLineMaterialCached)&&e(this._wireframeLineMaterialCached),t(this._wireframeRingMaterialCached)&&e(this._wireframeRingMaterialCached),t(this._markerMaterialCached)&&e(this._markerMaterialCached,!0)}_updateMaterialLayerOpacity(e,t=!1){const r=e.parameters.color,a=o(this.symbolLayer,"material","color"),i=this._patternHidesLine&&!t?0:this._getCombinedOpacity(a),s=p(r[0],r[1],r[2],i);e.setParameters({color:s})}layerElevationInfoChanged(e,t,r){const a=this._elevationContext.mode,i=b(q.elevationModeChangeTypes,r,a);if(i!==M.UPDATE)return i;const s=v(a);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>s))}slicePlaneEnabledChanged(){const e={hasSlicePlane:this._context.slicePlaneEnabled};return this._forEachMaterial((t=>t.setParameters(e))),!0}physicalBasedRenderingChanged(){return!0}pixelRatioChanged(){return!0}skipHighSymbolLodsChanged(){return!0}_getGeometryAsPolygonOrPolyline(e){switch(e.type){case"extent":if(e instanceof H)return B.fromExtent(e);break;case"polygon":case"polyline":return e}return null}_createAs3DShape(e,r,a){const i=e.graphic,s=this._getGeometryAsPolygonOrPolyline(i.geometry),o="polygon"===s.type?s.rings:s.paths,n=new Array,l=m(),h=O(s,this._context.elevationProvider,this._context.renderCoordsHelper,r),c="polygon"===s.type?"rings":"paths";this._logGeometryCreationWarnings(h,o,c,"LineSymbol3DLayer");for(let m=0;m<h.lines.length;m++){const r=h.lines[m],i=r.position,o=r.mapPositions;if(t(this._context.clippingExtent)&&(_(l),y(l,o),!u(l,this._context.clippingExtent)))continue;const c=this._createGeometry("polygon"===s.type?this._ringMaterial:this._lineMaterial,e,i,o,s.type,J.ELEVATED,a);n.push(c),A.LINE_WIREFRAMES&&n.push(c.instantiate({material:"polygon"===s.type?this._wireframeRingMaterial:this._wireframeLineMaterial})),t(this._markerMaterial)&&n.push(c.instantiate({material:this._markerMaterial}))}if(0===n.length)return null;const p=new V({geometries:n,castShadow:!1,metadata:{layerUid:this._context.layer.uid,graphicUid:a}}),d=new P(this,p,n,null,null,C,r);return d.alignedSampledElevation=h.sampledElevation,d.needsElevationUpdates=v(r.mode),d}_createGeometry(e,t,r,a,i,s,o){const n="polygon"===i,l=this._fastUpdates.enabled&&this._fastUpdates.visualVariables.color,h=this._fastUpdates.enabled&&this._fastUpdates.visualVariables.size,c=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:o,layerUid:this._context.layer.uid});return j(e,{overlayInfo:s===J.DRAPED?{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper}:null,removeDuplicateStartEnd:n,mapPositions:a,attributeData:{position:r,size:h?null:this._getDrivenSize(t.renderingInfo),color:l?null:this._getDrivenColor(t.renderingInfo),sizeFeature:this._getSizeFeatureAttributeData(t.graphic),colorFeature:this._getColorFeatureAttributeData(t.graphic),opacityFeature:this._getOpacityFeatureAttributeData(t.graphic)}},c)}_createAsOverlay(e,r){const a=e.graphic,i=this._getGeometryAsPolygonOrPolyline(a.geometry),s="polygon"===i.type?i.rings:i.paths,o="polygon"===i.type?this._ringMaterial:this._lineMaterial;o.renderPriority=this._renderPriority;const l=A.LINE_WIREFRAMES?"polygon"===i.type?this._wireframeRingMaterial:this._wireframeLineMaterial:null,h=this._markerMaterial;t(l)&&(l.renderPriority=this._renderPriority-.001),t(h)&&(h.renderPriority=this._renderPriority-.002);const c=new Array,p=m(),d=_(),f=G(i,this._context.overlaySR),C="polygon"===i.type?"rings":"paths";this._logGeometryCreationWarnings(f,s,C,"LineSymbol3DLayer");for(const m of f.lines){if(_(p),y(p,m.position),!u(p,this._context.clippingExtent))continue;g(d,p);const s=t=>{const s=this._createGeometry(t,e,m.position,void 0,i.type,J.DRAPED,a.uid),o=new I(s,{layerUid:r,graphicUid:a.uid});return c.push(o),o};if(t(h)){const e=s(h),t=n(this.symbolLayer.marker).placement;"begin"!==t&&"begin-end"!==t||y(p,m.position,0,1),"end"!==t&&"begin-end"!==t||y(p,m.position,m.position.length-3,1),this._updateBoundingSphere(e,p)}const f=s(o);if(this._updateBoundingSphere(f,p),A.LINE_WIREFRAMES){const e=s(l);this._updateBoundingSphere(e,p)}}return new L(this,c,d,this._context.drapeSourceRenderer)}_updateBoundingSphere(e,t){c(e.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])))}get _patternHidesLine(){const e=this.symbolLayer.pattern;return t(e)&&"style"===e.type&&"none"===e.style}_computeMaterialWidth(e){return e=s(e,l(1)),this._drivenProperties.size?this._fastUpdates.enabled&&this._fastUpdates.visualVariables.size?h(1):1:h(e)}_prepareMaterialPatch(e,t,i){const s=t.material;if(a(s))return void(i.changed&&i.useMaterialColor&&this._patchMaterialColor(this._getCombinedOpacityAndColor(this._materialColor),this._markerMaterialCached,e));if("collection"===s.type)return;const o="complete"===s.type?r(s.newValue,(e=>e.color)):"complete"===s.diff.color?.type?s.diff.color.newValue:null,n=this._getCombinedOpacityAndColor(o);i.useMaterialColor&&this._patchMaterialColor(d(n),this._markerMaterialCached,e),this._patternHidesLine&&(n[3]=0),this._patchMaterialColor(n,this._lineMaterialCached,e),delete t.material}_prepareMarkerPatch(e,r){const i=r.marker;if(a(i)||"partial"!==i.type||t(i.diff.style)||t(i.diff.placement)||t(i.diff.color)&&"complete"!==i.diff.color.type)return{changed:!1,useMaterialColor:a(this._markerColor)};const s=i.diff.color;if(a(s))return delete r.marker,{changed:!1,useMaterialColor:a(this._markerColor)};const o=n(s.newValue);return a(o)?(delete r.marker,{changed:!0,useMaterialColor:!0}):(this._patchMaterialColor(this._getCombinedOpacityAndColor(o),this._markerMaterialCached,e),delete r.marker,{changed:!0,useMaterialColor:!1})}_patchMaterialColor(e,t,r){a(t)||r.symbolLayerStatePatches.push((()=>t.setParameters({color:e})))}}var J;q.elevationModeChangeTypes={definedChanged:M.RECREATE,staysOnTheGround:M.NONE,onTheGroundChanged:M.RECREATE},function(e){e[e.DRAPED=0]="DRAPED",e[e.ELEVATED=1]="ELEVATED"}(J||(J={}));export{q as Graphics3DLineSymbolLayer};