@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 9.75 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import e from"../../../../Color.js";import{pt2px as t}from"../../../../core/screenUtils.js";import{e as i}from"../../../../chunks/earcut.js";import{create as r,fromBuffer as s,intersectsClippingArea as o,empty as n,expandWithAABB as a}from"../../../../geometry/support/aaBoundingBox.js";import{newDoubleArray as l,doubleSubArray as c}from"../../../../geometry/support/DoubleArray.js";import{newFloatArray as p,floatSubArray as h}from"../../../../geometry/support/FloatArray.js";import{SymbolUpdateType as u,elevationModeChangeUpdateType as d,needsElevationUpdates2D as m}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as y}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as _}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as g}from"./Graphics3DSymbolLayer.js";import{mixinColorAndOpacity as f}from"./graphicUtils.js";import{ApplyRendererDiffResult as b}from"./interfaces.js";import{parseCapType as x}from"./lineUtils.js";import{geometryAsPolygon as O,createIndices3D as v,createColorGeometry as D,PolygonCreationDataBase as C}from"./polygonUtils.js";import{initFastSymbolUpdatesState as S,updateFastSymbolUpdatesState as j,getAttributeValue as A,ConvertOptions as P}from"../support/FastSymbolUpdates.js";import{createMaterial as U,uvElevationAligner as E}from"../support/patternUtils.js";import{createMapSpaceUVCoords as G,createMapSpaceUVCoordsDraped as L}from"../support/uvUtils.js";import{createGeometry as F}from"../../support/engineContent/line.js";import{geometryToRenderInfo as w,geometryToRenderInfoDraped as R}from"../../support/renderInfoUtils/polygon.js";import{Object3D as I}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as M}from"../../webgl-engine/lib/RenderGeometry.js";import{getStipplePatternForLinePattern as V}from"../../webgl-engine/materials/lineStippleUtils.js";import{PatternMaterial as B}from"../../webgl-engine/materials/PatternMaterial.js";import{RibbonLineMaterial as T}from"../../webgl-engine/materials/RibbonLineMaterial.js";const z=["polyline","polygon","extent"],H=new P({size:!1,color:!0,rotation:!1,opacity:!1});class N extends g{constructor(e,t,i,r){super(e,t,i,r),this._needsUV=!1}async doLoad(){this._fastUpdates=S(this._context.renderer,H)}_createMaterials(){if(this._materials.length>0)return;const e=this.symbolLayer?.material?.color,i=this._getCombinedOpacityAndColor(e);this._materials[J.Fill]=U(this.symbolLayer,{color:i,forceTransparentMode:this.needsDrivenTransparentPass,discardInvisibleFragments:!0,polygonOffset:!1,hasVertexColors:!0,draped:this.draped,hasSlicePlane:this._context.slicePlaneEnabled,...this._fastUpdates?.materialParameters}),this._needsUV=this._materials[J.Fill]instanceof B;const r=this.symbolLayer.outline;if(K(r)){const e=V(r.pattern);this._materials[J.Outline]=new T({width:t(r.size),color:this._getOutlineColor(),hasPolygonOffset:!0,hasSlicePlane:this._context.slicePlaneEnabled,isClosed:!0,stipplePattern:e,cap:x(r.patternCap||"butt")})}this._context.stage.addMany(this._materials)}destroy(){super.destroy(),this._context.stage.removeMany(this._materials),this._materials.length=0}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,z,this.symbolLayer.type))return null;const i=this._getVertexOpacityAndColor(e.renderingInfo,255),r=this.setGraphicElevationContext(t);return this.ensureDrapedStatus("on-the-ground"===r.mode),this._createMaterials(),this.draped?this._createAsOverlay(t,i):this._createAs3DShape(t,i,r)}applyRendererDiff(e,t){for(const i in e.diff){if("visualVariables"!==i)return b.RecreateSymbol;if(!j(this._fastUpdates,t,H))return b.RecreateSymbol;this._materials[J.Fill]?.setParameters(this._fastUpdates.materialParameters)}return b.FastUpdate}layerOpacityChanged(){if(null!=this._materials[J.Fill]){const e=this._materials[J.Fill].parameters.color,t=this.symbolLayer?.material?.color,i=this._getCombinedOpacity(t);this._materials[J.Fill].setParameters({color:[e[0],e[1],e[2],i],forceTransparentMode:this.needsDrivenTransparentPass})}if(null!=this._materials[J.Outline]){const e=this._materials[J.Outline].parameters.color;this._materials[J.Outline].setParameters({color:[e[0],e[1],e[2],this._getOutlineOpacity()]})}}layerElevationInfoChanged(e,t,i){const r=this._elevationContext.mode,s=d(N.elevationModeChangeTypes,i,r);if(s!==u.UPDATE)return s;const o=m(r);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>o))}slicePlaneEnabledChanged(){if(this._materials[J.Fill]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),this._materials[J.Outline]){const e={hasSlicePlane:this._context.slicePlaneEnabled};this._materials[J.Outline].setParameters(e)}return!0}physicalBasedRenderingChanged(){return!0}_createAs3DShape(e,t,i){const r=O(e.geometry);if(!r)return null;const s=w(r,this._context.elevationProvider,this._context.renderCoordsHelper,i),o=new k(s,t,this._context.layer.uid,e.uid),n=o.renderData.position.length/3;if(this._needsUV&&(o.uvMapSpace=p(4*n,!0),o.boundingRect=l(9*n,!0),G(o.uvMapSpace,o.boundingRect,o.renderData.position,this._context.renderCoordsHelper)),o.objectAndLayerIdColor=this._context.stage.renderView?.getObjectAndLayerIdColor(o),this._createAs3DShapeFill(e,o),this._materials[J.Outline]&&this._createAs3DShapeOutline(o),this._logGeometryCreationWarnings(o.renderData,r.rings,"rings","FillSymbol3DLayer"),0===o.outGeometries.length)return null;const a=new I({geometries:o.outGeometries,castShadow:!1,layerUid:this._context.layer.uid,graphicUid:e.uid}),c=new _(this,a,o.outGeometries,null,null,E,i);return c.alignedSampledElevation=o.renderData.sampledElevation,c.needsElevationUpdates=m(i.mode),c}_createAs3DShapeFill(e,t){const i=t.renderData.polygons;for(const{position:r,mapPositions:n,holeIndices:a,index:l,count:p}of i){if(null!=this._context.clippingExtent&&(s(n,W),!o(W,this._context.clippingExtent)))continue;const i=v(n,a,this._context.elevationProvider.spatialReference);if(0===i.length)continue;const u=this._fastUpdates?.visualVariables.color,d=D({material:this._materials[J.Fill],indices:i,mapPositions:n,attributeData:{position:r,color:u?null:t.color,colorFeature:u?A(u.field,e):null,uvMapSpace:this._needsUV?h(t.uvMapSpace,4*l,4*p):null,boundingRect:this._needsUV?c(t.boundingRect,9*l,9*p):null,objectAndLayerIdColor:t.objectAndLayerIdColor}});t.outGeometries.push(d)}}_createAs3DShapeOutline(e){if(null==this._materials[J.Outline])return;const t=e.renderData.outlines;for(const{mapPositions:i,position:r}of t){if(null!=this._context.clippingExtent&&(s(i,W),!o(W,this._context.clippingExtent)))continue;const t=F(this._materials[J.Outline],{overlayInfo:null,removeDuplicateStartEnd:!0,mapPositions:i,attributeData:{position:r}},e.objectAndLayerIdColor);e.outGeometries.push(t)}}_createAsOverlay(e,t){const i=O(e.geometry);if(null==i)return null;this._materials[J.Fill].renderPriority=this._renderPriority+this._renderPriorityStep/2,null!=this._materials[J.Outline]&&(this._materials[J.Outline].renderPriority=this._renderPriority);const r=R(i,this._context.overlaySR),s=new q(r,t,this._context.layer.uid,e.uid),o=s.renderData.position.length/3;return this._needsUV&&(s.uvMapSpace=p(4*o,!0),L(s.uvMapSpace,s.renderData.position,this._context.overlaySR,this._context.graphicsCoreOwner.view.state.viewingMode)),s.outBoundingBox=n(),s.objectAndLayerIdColor=this._context.stage.renderView?.getObjectAndLayerIdColor(s),this._createAsOverlayFill(e,s),this._materials[J.Outline]&&this._createAsOverlayOutline(s),this._logGeometryCreationWarnings(s.renderData,i.rings,"rings","FillSymbol3DLayer"),0===s.outGeometries.length?null:new y(this,s.outGeometries,s.outBoundingBox,this._context.drapeSourceRenderer)}_createAsOverlayFill(e,t){const r=t.renderData.polygons;for(const{position:n,holeIndices:l,index:c,count:p}of r){const r=s(n,W);if(!o(r,this._context.clippingExtent))continue;const u=i(n,l,3);if(0===u.length)continue;a(t.outBoundingBox,r);const d=this._fastUpdates?.visualVariables.color,m=D({material:this._materials[J.Fill],indices:u,attributeData:{position:n,color:d?null:t.color,colorFeature:d?A(d.field,e):null,uvMapSpace:this._needsUV?h(t.uvMapSpace,4*c,4*p):null,objectAndLayerIdColor:t.objectAndLayerIdColor}});t.outGeometries.push(new M(m,t))}}_createAsOverlayOutline(e){if(null==this._materials[J.Outline])return;const t=e.renderData.outlines;for(let i=0;i<t.length;++i){const{position:r}=t[i];if(s(r,W),!o(W,this._context.clippingExtent))continue;a(e.outBoundingBox,W);const n=F(this._materials[J.Outline],{overlayInfo:{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper},removeDuplicateStartEnd:!0,attributeData:{position:r}},e.objectAndLayerIdColor);e.outGeometries.push(new M(n,e))}}_getOutlineOpacity(){const e=this.symbolLayer?.outline?.color;return(this.draped?1:this._getLayerOpacity())*(null!=e?e.a:0)}_getOutlineColor(){const t=this.symbolLayer?.outline?.color,i=this._getOutlineOpacity();return f(null!=t?e.toUnitRGB(t):null,i)}test(){return{...super.test(),createAsOverlay:(e,t)=>this._createAsOverlay(e,t),createAs3DShape:(e,t,i)=>this._createAs3DShape(e,t,i)}}}N.elevationModeChangeTypes={definedChanged:u.RECREATE,staysOnTheGround:u.NONE,onTheGroundChanged:u.RECREATE};const W=r();class k extends C{constructor(e,t,i,r){super(e,i,r),this.color=t}}class q extends C{constructor(e,t,i,r){super(e,i,r),this.color=t}}var J;function K(e){return null!=e?.size&&e.size>0&&null!=e.color&&(null==e.pattern||"style"!==e.pattern.type||"none"!==e.pattern.style)}!function(e){e[e.Fill=0]="Fill",e[e.Outline=1]="Outline"}(J||(J={}));export{N as Graphics3DPolygonFillSymbolLayer};