@arcgis/core 4.33.0-next.20250415 → 4.33.0-next.20250416
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{3a84ee5d0434362286a6.js → 07f206719763173faa8d.js} +1 -1
- package/assets/esri/core/workers/chunks/{029705c229ccf2e6b78d.js → 29283c19e1ccdc6cfbde.js} +8 -8
- package/assets/esri/core/workers/chunks/{ed517687b3728fd2eb64.js → 2fd5b48976cefe7cc0ab.js} +1 -1
- package/assets/esri/core/workers/chunks/{4e711f4fa1cbedf4dae5.js → 42aab2a336ee22fd9055.js} +1 -1
- package/assets/esri/core/workers/chunks/{d88544ac332be633e3fe.js → e64e0c3240f8e577a61c.js} +1 -1
- package/assets/esri/core/workers/chunks/e9fba86036b8fe700a41.js +1 -0
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ar.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_bg.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_bs.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ca.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_cs.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_da.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_de.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_el.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_es.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_et.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_fi.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_fr.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_he.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_hr.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_hu.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_id.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_it.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ja.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ko.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_lt.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_lv.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_nl.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_no.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_pl.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_pt-BR.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_pt-PT.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ro.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_ru.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_sk.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_sl.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_sr.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_sv.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_th.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_tr.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_uk.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_vi.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_zh-CN.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_zh-HK.json +1 -1
- package/assets/esri/widgets/TimeSlider/t9n/TimeSlider_zh-TW.json +1 -1
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ar.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_bg.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_bs.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ca.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_cs.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_da.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_de.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_el.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_es.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_et.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_fi.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_fr.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_he.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_hr.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_hu.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_id.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_it.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ja.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ko.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_lt.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_lv.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_nl.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_no.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_pl.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_pt-BR.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_pt-PT.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ro.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_ru.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_sk.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_sl.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_sr.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_sv.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_th.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_tr.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_uk.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_vi.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_zh-CN.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_zh-HK.json +1 -0
- package/assets/esri/widgets/support/SelectionList/t9n/SelectionList_zh-TW.json +1 -0
- package/geometry/support/MeshTexture.js +1 -1
- package/interfaces.d.ts +44 -0
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/views/3d/analysis/Dimension/DimensionVisualization.js +1 -1
- package/views/3d/interactive/Manipulator3D.js +1 -1
- package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/Object3DVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/VisualElementResources.js +1 -1
- package/views/3d/layers/DrapedSubView3D.js +1 -1
- package/views/3d/layers/graphics/Graphics3DExtrudeSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DTextSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DWaterSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/LabelDeconflictor.js +1 -1
- package/views/3d/layers/graphics/Labeler.js +1 -1
- package/views/3d/layers/graphics/MeshFastUpdateProcessor.js +1 -1
- package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
- package/views/3d/layers/graphics/pipeline/rendering/DirectRenderer.js +1 -1
- package/views/3d/layers/graphics/pipeline/rendering/LodRenderer.js +1 -1
- package/views/3d/layers/graphics/polygonUtils.js +1 -1
- package/views/3d/layers/support/HeatmapFeatureProcessor.js +1 -1
- package/views/3d/support/MemoryController.js +1 -1
- package/views/3d/support/engineContent/line.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/webgl-engine/Stage.js +1 -1
- package/views/3d/webgl-engine/effects/bloom/BloomPresets.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/bloom/BloomRenderNode.js +1 -1
- package/views/3d/webgl-engine/lib/ContentObjectType.js +1 -1
- package/views/3d/webgl-engine/lib/Geometry.js +1 -1
- package/views/3d/webgl-engine/lib/GeometryUtil.js +1 -1
- package/views/3d/webgl-engine/lib/GridLocalOriginFactory.js +1 -1
- package/views/3d/webgl-engine/lib/IntersectableGeometry.js +5 -0
- package/views/3d/webgl-engine/lib/Material.js +1 -1
- package/views/3d/webgl-engine/lib/Object3D.js +1 -1
- package/views/3d/webgl-engine/lib/PathGeometry.js +1 -1
- package/views/3d/webgl-engine/lib/RayIntersections.js +1 -1
- package/views/3d/webgl-engine/lib/RenderContext.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/RendererBase.js +1 -1
- package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/WebGLLayer.js +1 -1
- package/views/3d/webgl-engine/materials/renderers/MergedRenderer.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/support/Scheduler.js +1 -1
- package/webscene/Slide.js +1 -1
- package/widgets/Editor/UpdateFeatureWorkflow.js +1 -1
- package/widgets/Features/FeaturesViewModel.js +1 -1
- package/widgets/support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/72d7e45e7eb28f2cc0b0.js +0 -1
- package/views/3d/webgl-engine/lib/MaterialCollection.js +0 -5
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t from"../../../../Color.js";import"../../../../core/has.js";import e from"../../../../core/Error.js";import{clone as r}from"../../../../core/lang.js";import{getMetersPerVerticalUnitForSR as o}from"../../../../core/unitUtils.js";import{e as s}from"../../../../chunks/earcut.js";import{normalFromMat4 as i}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{invert as a,invertOrIdentity as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{c as m,n as p,i as h,d as g,e as d,t as u,a as f}from"../../../../chunks/vec32.js";import{fromArray as y,create as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ZEROS as _}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{computeTranslationToOriginAndRotation as x}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{create as j,fromBuffer as S,intersectsClippingArea as P}from"../../../../geometry/support/aaBoundingBox.js";import{newDoubleArray as w}from"../../../../geometry/support/DoubleArray.js";import{newIndexArray as O,getZeroIndexArray as C}from"../../../../geometry/support/Indices.js";import{t as E}from"../../../../chunks/vec3.js";import{makeVertexCandidate as v,makeEdgeCandidate as M}from"../../../../layers/graphics/data/SnappingCandidate.js";import{getDriverAxisSizeValue as I}from"../../../../renderers/support/renderingInfoUtils.js";import{EmissiveSourceMode as A}from"../../../../symbols/support/materialUtils.js";import{ViewingMode as L}from"../../../ViewingMode.js";import{needsElevationUpdates3D as B,SampleElevationInfo as z}from"./elevationAlignmentUtils.js";import{Object3DEdgeState as R,Graphics3DObject3DGraphicLayer as U}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as D}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as V,computeCentroid as G}from"./graphicUtils.js";import{ApplyRendererDiffResult as T}from"./interfaces.js";import{geometryAsPolygon as N}from"./polygonUtils.js";import{createMaterial as F}from"../support/edgeUtils.js";import{debugFlags as k}from"../../support/debugFlags.js";import{SamplePosition as H}from"../../support/ElevationProvider.js";import{geometryToRenderInfo as W}from"../../support/renderInfoUtils/polygon.js";import{NormalType as q}from"../../webgl-engine/core/shaderLibrary/attributes/NormalAttribute.glsl.js";import{Attribute as Z}from"../../webgl-engine/lib/Attribute.js";import{CullFaceOptions as J}from"../../webgl-engine/lib/basicInterfaces.js";import{ContentObjectType as K}from"../../webgl-engine/lib/ContentObjectType.js";import{Geometry as Q}from"../../webgl-engine/lib/Geometry.js";import{isGeometryWithMapPositions as X}from"../../webgl-engine/lib/GeometryWithMapPositions.js";import{compressNormals as Y,compressNormal as $}from"../../webgl-engine/lib/Normals.js";import{Object3D as tt}from"../../webgl-engine/lib/Object3D.js";import{VertexAttribute as et}from"../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as rt}from"../../webgl-engine/materials/DefaultMaterial.js";const ot=["polygon","extent"];class st extends D{constructor(t,e,r,o){super(t,e,r,o,xt(e)),this.ensureDrapedStatus(!1)}async doLoad(){if(!this._drivenProperties.size){const t=V(this._getSymbolSize());if(t)throw new e("graphics3dextrudesymbollayer:invalid-size",t)}const t=this.symbolLayer,r=t?.material,o=r?.color,s=this._getCombinedOpacityAndColor(o),i=y(s),n=s[3],a=this.needsDrivenTransparentPass,l=r?.emissive,c={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,diffuse:i,ambient:i,opacity:n,drivenOpacity:a,hasVertexColors:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:t.castShadows,emissiveStrength:l?.strength??0,emissiveSource:A.Color,offsetTransparentBackfaces:!0,normalType:q.Compressed},m=new rt(c,this._context);m.setParameters({cullFace:m.transparent?J.None:J.Back});const p=new rt({...c,cullFace:J.Back},this._context);this._materials[At.Main]=m,this._materials[At.Bottom]=p,this._context.stage.addMany(this._materials)}destroy(){super.destroy(),this._context.stage.removeMany(this._materials),this._materials.length=0}createGraphics3DGraphic(t){const e=t.graphic;if(!this._validateGeometry(e.geometry,ot,this.symbolLayer.type))return null;const r=this._getVertexOpacityAndColor(t.renderingInfo,this._getFallbackOpacityAndColor(),255),o=this.setGraphicElevationContext(e);return this._createAs3DShape(e,t.renderingInfo,r,o,e.uid)}layerOpacityChanged(t,e){const r=this.symbolLayer?.material?.color,o=this._getCombinedOpacity(r);this._materials[At.Main]?.setParameters({opacity:o}),this._materials[At.Bottom]?.setParameters({opacity:o});const s=this._getLayerOpacity();t.forEach((t=>e(t)?.layerOpacityChanged(s,this._context.isAsync)))}layerElevationInfoChanged(t,e){return this.updateGraphics3DGraphicElevationInfo(t,e,B)}slicePlaneEnabledChanged(t,e){return this._materials[At.Main]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),this._materials[At.Bottom]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),t.forEach((t=>{const r=e(t);null!=r&&r.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync)})),!0}physicalBasedRenderingChanged(){const t={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0};return this._materials[At.Main]?.setParameters(t),this._materials[At.Bottom]?.setParameters(t),!0}_getExtrusionSize(t){let e;return e=t.size&&this._drivenProperties.size?I(t.size,2)??0:this._getSymbolSize(),e/=this._context.renderCoordsHelper.unitInMeters,e}applyRendererDiff(t,e){return this._drivenPropertiesChanged(e)?T.RecreateSymbol:T.RecreateGraphics}async queryForSnapping(t,e,s,i){const n=this._getExtrusionSize(s)*this._context.renderCoordsHelper.unitInMeters/o(e),{objectId:a,target:l}=t,c=r(l);switch(c.z=(c.z??0)+n,t.type){case"edge":{const{start:e,end:o}=t,s=r(e),i=r(o);return s.z=(s.z??0)+n,i.z=(i.z??0)+n,[M(a,c,1/0,s,i)]}case"vertex":return[v(a,c,1/0),M(a,l,1/0,l,c)];default:return[]}}_getSymbolSize(){return this.symbolLayer.size??1}_createAs3DShape(t,e,r,o,l){const m=N(t.geometry);if(null==m)return null;if(0===m.rings.length||!m.rings.some((t=>t.length>0)))return this._logGeometryValidationWarnings(m.rings,"rings","ExtrudeSymbol3DLayer"),null;const p=W(m,this._context.elevationProvider,this._context.renderCoordsHelper,o);this._logGeometryCreationWarnings(p,m.rings,"rings","ExtrudeSymbol3DLayer");const h=G(m);if(null==h)return null;const g=new Array,d=new Array,u=j(),f=c(),y=b(),_=this._context.renderCoordsHelper.viewingMode===L.Global;_||this._context.renderCoordsHelper.worldUpAtPosition(null,y),x(m.spatialReference,[h.x,h.y,0],f,this._context.renderCoordsHelper.spatialReference);const C=c();a(C,f);const v=n();i(v,C);const{polygons:M,mapPositions:I,position:A}=p,z=new Map,D=this._materials[At.Main];for(const i of M){const t=i.count;if(this._context.clippingExtent&&(S(i.mapPositions,u),!P(u,this._context.clippingExtent)))continue;const o=s(i.mapPositions,i.holeIndices,3);if(0===o.length)continue;const n=o.length,a=6*t,c=O(a+n),m=O(n),p=w(3*a),h=w(3*a),b=w(3*a),x=w(a);nt(A,I,o,i,p,b,h,x,c,m,this._getExtrusionSize(e),y,_),E(p,p,C);const j=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:l,layerViewUid:this._context.layerViewUid}),v=new Lt(p,b,Y(h),x),M=it(D,c,c.length-m.length,v,r,j),L=t,B=t,R=2*i.count,U=new Bt(L,B,R,n/3);_t(M,U,f),z.set(M,U),g.push(M,it(this._materials[At.Bottom],m,0,v,r,j)),d.push(v.heights)}if(0===g.length)return null;const V=new tt({geometries:g,layerViewUid:this._context.layerViewUid,graphicUid:l,isElevationSource:!0});V.transformation=f;const T=F(this.symbolLayer,{opacity:this._getLayerOpacity()}),k=T?new R(this._materials[At.Main],T,this._context.slicePlaneEnabled):null,H=new U(this,V,g,null,null,((t,e,r,o,s)=>bt(t,e,r,o,s,d,z)),o,k);return H.alignedSampledElevation=p.sampledElevation,H.needsElevationUpdates=B(o.mode),H}_getFallbackOpacityAndColor(){const e=this.symbolLayer?.material?.color;return t.toUnitRGBA(e)??_}}function it(t,e,r,o,s,i){const n=C(e.length),a=[[et.POSITION,new Z(o.positions,e,3,!0)],[et.NORMALCOMPRESSED,new Z(o.normals,e,2,!0)],[et.COLOR,new Z(s,n,4,!0)]];return new Q(t,a,o.elevation,K.Mesh,i,r)}function nt(t,e,r,o,s,i,n,a,l,c,m,p,h){{const g=r.length/3,d=2*o.count;at(t,e,o.index,o.count,r,0,g,s,i,n,a,l,c,d,m,p,h)}{let t=0,e=2*o.count,r=0;const c=o.pathLengths[0];mt(s,i,a,n,t,c,o.count,e,l,r,m),e+=4*c,r+=2*c,t+=c;for(let p=1;p<o.pathLengths.length;++p){const c=o.pathLengths[p];mt(s,i,a,n,t,c,o.count,e,l,r,m),e+=4*c,r+=2*c,t+=c}}}function at(t,e,r,o,s,i,n,a,l,c,h,g,d,u,f,y,b){m(St,y);{const s=f>0?1:-1;let i=3*r,n=0,m=3*n,g=o,d=3*g;for(let r=0;r<o;++r){const r=t[i],o=t[i+1],u=t[i+2];b&&(St[0]=r,St[1]=o,St[2]=u,p(St,St)),a[m+0]=r,a[m+1]=o,a[m+2]=u;const y=e[i+0],_=e[i+1],x=e[i+2];l[m+0]=y,l[m+1]=_,l[m+2]=x,c[m+0]=-s*St[0],c[m+1]=-s*St[1],c[m+2]=-s*St[2],h[n]=0,a[d+0]=r+f*St[0],a[d+1]=o+f*St[1],a[d+2]=u+f*St[2],l[d+0]=y,l[d+1]=_,l[d+2]=x,h[g]=f,m+=3,d+=3,i+=3,n+=1,g+=1}}{let t=3*i,e=0,r=3*u;const a=f<0?Ot:wt,l=f<0?wt:Ot;for(let i=0;i<n;++i)d[e]=s[t+a[0]],d[e+1]=s[t+a[1]],d[e+2]=s[t+a[2]],g[r]=s[t+l[0]]+o,g[r+1]=s[t+l[1]]+o,g[r+2]=s[t+l[2]]+o,e+=3,r+=3,t+=3}}function lt(t,e,r,o,s,i,n){o[i]=o[n],n*=3,t[i*=3]=t[n],t[i+1]=t[n+1],t[i+2]=t[n+2],e[i]=e[n],e[i+1]=e[n+1],e[i+2]=e[n+2],r[i]=s[0],r[i+1]=s[1],r[i+2]=s[2]}const ct=b();function mt(t,e,r,o,s,i,n,a,l,c,m){let p=s,h=s+1,g=s+n,d=s+n+1,u=a,f=a+1,y=a+2*i,b=a+2*i+1;m<0&&(p=s+n+1,d=s);let _=3*c;for(let x=0;x<i;++x)x===i-1&&(h=s,m>0?d=s+n:p=s+n),ft(t,p,h,g,ct),lt(t,e,o,r,ct,u,p),lt(t,e,o,r,ct,f,h),lt(t,e,o,r,ct,y,g),lt(t,e,o,r,ct,b,d),l[_]=u,l[_+1]=y,l[_+2]=b,l[_+3]=u,l[_+4]=b,l[_+5]=f,_+=6,p++,h++,g++,d++,u+=2,f+=2,y+=2,b+=2}const pt=b(),ht=b(),gt=b(),dt=b(),ut=b();function ft(t,e,r,o,s){e*=3,r*=3,o*=3,h(pt,t[e++],t[e++],t[e++]),h(ht,t[r++],t[r++],t[r++]),h(gt,t[o++],t[o++],t[o++]),g(dt,ht,pt),g(ut,gt,pt),d(s,ut,dt),p(s,s)}const yt=b();function bt(t,e,r,o,s,i,n){const a=t.stageObject,m=a.geometries,p=m.length,g="absolute-height"!==e.mode;let d=0;const f=a.transformation,y=l(c(),f);for(let l=0;l<p;l+=2){const t=m[l];if(!X(t))continue;const e=t.getMutableAttribute(et.POSITION).data,c=i[l/2],p=new H(t.mapPositions),b=e.length/3;let _=!1,x=0;{let t=0;for(let i=0;i<b;i++){yt[0]=e[t],yt[1]=e[t+1],yt[2]=e[t+2],o(p,Pt),g&&(x+=Pt.sampledElevation),k.TESTS_DISABLE_OPTIMIZATIONS?(h(jt,p.array[p.offset],p.array[p.offset+1],Pt.z+c[t/3]),null!=r&&s.toRenderCoords(jt,r,jt),u(jt,jt,y)):(h(jt,e[t],e[t+1],e[t+2]),u(jt,jt,f),s.setAltitude(jt,Pt.z+c[t/3]),u(jt,jt,y)),e[t]=jt[0],e[t+1]=jt[1],e[t+2]=jt[2];const i=Ct/s.unitInMeters;(Math.abs(yt[0]-e[t])>=i||Math.abs(yt[1]-e[t+1])>=i||Math.abs(yt[2]-e[t+2])>=i)&&(_=!0),p.offset+=3,t+=3}}if(_){const e=n.get(t);e&&_t(t,e,f),a.geometryVertexAttributeUpdated(m[l],et.NORMALCOMPRESSED),t.invalidateBoundingInfo(),a.geometryVertexAttributeUpdated(m[l],et.POSITION),m[l+1].invalidateBoundingInfo(),a.geometryVertexAttributeUpdated(m[l+1],et.POSITION)}d+=x/b}return d/p}function _t(t,e,r){const o=t.getMutableAttribute(et.POSITION),s=t.getMutableAttribute(et.NORMALCOMPRESSED).data,{topVertexStart:i,topVertexCount:n,topFaceStart:a,topFaceCount:l}=e,c=o.data,m=n,g=t.attributes.get(et.POSITION).indices,y=a+l,b=i+n,_=w(3*m);for(let p=0;p<m;++p){const t=3*p;_[t+0]=0,_[t+1]=0,_[t+2]=0}const x=Et,j=vt,S=Mt,P=It,O=St;for(let w=a;w<y;++w){const t=3*w;for(let e=0;e<3;++e){const o=g[t+e];P[e]=o;const s=3*o;h(jt,c[s+0],c[s+1],c[s+2]),u(x[e],jt,r)}f(j,x[1],x[0]),f(S,x[2],x[0]),d(O,j,S),p(O,O);for(let e=0;e<3;++e){const t=3*(P[e]-i);_[t+0]+=O[0],_[t+1]+=O[1],_[t+2]+=O[2]}}for(let p=i;p<b;++p){const t=3*(p-i),e=_[t+0],r=_[t+1],o=_[t+2],n=Math.sqrt(e*e+r*r+o*o);$(s,p,e/n,r/n,o/n)}}function xt(t){return 1===(t.material?.color?.a??1)}const jt=b(),St=b(),Pt=new z,wt=[0,2,1],Ot=[0,1,2],Ct=.01,Et=[b(),b(),b()],vt=b(),Mt=b(),It=[0,0,0];var At;!function(t){t[t.Main=0]="Main",t[t.Bottom=1]="Bottom"}(At||(At={}));class Lt{constructor(t,e,r,o){this.positions=t,this.elevation=e,this.normals=r,this.heights=o}}class Bt{constructor(t,e,r,o){this.topVertexStart=t,this.topVertexCount=e,this.topFaceStart=r,this.topFaceCount=o}}export{st as Graphics3DExtrudeSymbolLayer,nt as extrudePolygon};
|
|
5
|
+
import t from"../../../../Color.js";import"../../../../core/has.js";import e from"../../../../core/Error.js";import{clone as r}from"../../../../core/lang.js";import{getMetersPerVerticalUnitForSR as o}from"../../../../core/unitUtils.js";import{e as s}from"../../../../chunks/earcut.js";import{normalFromMat4 as i}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{invert as a,invertOrIdentity as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{c as m,n as p,i as h,d as g,e as d,t as u,a as f}from"../../../../chunks/vec32.js";import{fromArray as y,create as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ZEROS as _}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{computeTranslationToOriginAndRotation as x}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{create as S,fromBuffer as j,intersectsClippingArea as P}from"../../../../geometry/support/aaBoundingBox.js";import{newDoubleArray as w}from"../../../../geometry/support/DoubleArray.js";import{newIndexArray as O,getZeroIndexArray as C}from"../../../../geometry/support/Indices.js";import{t as E}from"../../../../chunks/vec3.js";import{makeVertexCandidate as v,makeEdgeCandidate as I}from"../../../../layers/graphics/data/SnappingCandidate.js";import{getDriverAxisSizeValue as A}from"../../../../renderers/support/renderingInfoUtils.js";import{EmissiveSourceMode as M}from"../../../../symbols/support/materialUtils.js";import{ViewingMode as L}from"../../../ViewingMode.js";import{needsElevationUpdates3D as B,SampleElevationInfo as z}from"./elevationAlignmentUtils.js";import{Object3DEdgeState as R,Graphics3DObject3DGraphicLayer as U}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as D}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as G,computeCentroid as V}from"./graphicUtils.js";import{ApplyRendererDiffResult as T}from"./interfaces.js";import{geometryAsPolygon as N}from"./polygonUtils.js";import{createMaterial as F}from"../support/edgeUtils.js";import{debugFlags as k}from"../../support/debugFlags.js";import{SamplePosition as H}from"../../support/ElevationProvider.js";import{geometryToRenderInfo as W}from"../../support/renderInfoUtils/polygon.js";import{NormalType as q}from"../../webgl-engine/core/shaderLibrary/attributes/NormalAttribute.glsl.js";import{Attribute as Z}from"../../webgl-engine/lib/Attribute.js";import{CullFaceOptions as J}from"../../webgl-engine/lib/basicInterfaces.js";import{Geometry as K}from"../../webgl-engine/lib/Geometry.js";import{isGeometryWithMapPositions as Q}from"../../webgl-engine/lib/GeometryWithMapPositions.js";import{compressNormals as X,compressNormal as Y}from"../../webgl-engine/lib/Normals.js";import{Object3D as $}from"../../webgl-engine/lib/Object3D.js";import{VertexAttribute as tt}from"../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as et}from"../../webgl-engine/materials/DefaultMaterial.js";import{GeometryType as rt}from"../../webgl-engine/lib/IntersectableGeometry.js";const ot=["polygon","extent"];class st extends D{constructor(t,e,r,o){super(t,e,r,o,xt(e)),this.ensureDrapedStatus(!1)}async doLoad(){if(!this._drivenProperties.size){const t=G(this._getSymbolSize());if(t)throw new e("graphics3dextrudesymbollayer:invalid-size",t)}const t=this.symbolLayer,r=t?.material,o=r?.color,s=this._getCombinedOpacityAndColor(o),i=y(s),n=s[3],a=this.needsDrivenTransparentPass,l=r?.emissive,c={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,diffuse:i,ambient:i,opacity:n,drivenOpacity:a,hasVertexColors:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:t.castShadows,emissiveStrength:l?.strength??0,emissiveSource:M.Color,offsetTransparentBackfaces:!0,normalType:q.Compressed},m=new et(c,this._context);m.setParameters({cullFace:m.transparent?J.None:J.Back});const p=new et({...c,cullFace:J.Back},this._context);this._materials[Mt.Main]=m,this._materials[Mt.Bottom]=p}destroy(){super.destroy(),this._materials.length=0}createGraphics3DGraphic(t){const e=t.graphic;if(!this._validateGeometry(e.geometry,ot,this.symbolLayer.type))return null;const r=this._getVertexOpacityAndColor(t.renderingInfo,this._getFallbackOpacityAndColor(),255),o=this.setGraphicElevationContext(e);return this._createAs3DShape(e,t.renderingInfo,r,o,e.uid)}layerOpacityChanged(t,e){const r=this.symbolLayer?.material?.color,o=this._getCombinedOpacity(r);this._materials[Mt.Main]?.setParameters({opacity:o}),this._materials[Mt.Bottom]?.setParameters({opacity:o});const s=this._getLayerOpacity();t.forEach((t=>e(t)?.layerOpacityChanged(s,this._context.isAsync)))}layerElevationInfoChanged(t,e){return this.updateGraphics3DGraphicElevationInfo(t,e,B)}slicePlaneEnabledChanged(t,e){return this._materials[Mt.Main]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),this._materials[Mt.Bottom]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),t.forEach((t=>{const r=e(t);null!=r&&r.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync)})),!0}physicalBasedRenderingChanged(){const t={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0};return this._materials[Mt.Main]?.setParameters(t),this._materials[Mt.Bottom]?.setParameters(t),!0}_getExtrusionSize(t){let e;return e=t.size&&this._drivenProperties.size?A(t.size,2)??0:this._getSymbolSize(),e/=this._context.renderCoordsHelper.unitInMeters,e}applyRendererDiff(t,e){return this._drivenPropertiesChanged(e)?T.RecreateSymbol:T.RecreateGraphics}async queryForSnapping(t,e,s,i){const n=this._getExtrusionSize(s)*this._context.renderCoordsHelper.unitInMeters/o(e),{objectId:a,target:l}=t,c=r(l);switch(c.z=(c.z??0)+n,t.type){case"edge":{const{start:e,end:o}=t,s=r(e),i=r(o);return s.z=(s.z??0)+n,i.z=(i.z??0)+n,[I(a,c,1/0,s,i)]}case"vertex":return[v(a,c,1/0),I(a,l,1/0,l,c)];default:return[]}}_getSymbolSize(){return this.symbolLayer.size??1}_createAs3DShape(t,e,r,o,l){const m=N(t.geometry);if(null==m)return null;if(0===m.rings.length||!m.rings.some((t=>t.length>0)))return this._logGeometryValidationWarnings(m.rings,"rings","ExtrudeSymbol3DLayer"),null;const p=W(m,this._context.elevationProvider,this._context.renderCoordsHelper,o);this._logGeometryCreationWarnings(p,m.rings,"rings","ExtrudeSymbol3DLayer");const h=V(m);if(null==h)return null;const g=new Array,d=new Array,u=S(),f=c(),y=b(),_=this._context.renderCoordsHelper.viewingMode===L.Global;_||this._context.renderCoordsHelper.worldUpAtPosition(null,y),x(m.spatialReference,[h.x,h.y,0],f,this._context.renderCoordsHelper.spatialReference);const C=c();a(C,f);const v=n();i(v,C);const{polygons:I,mapPositions:A,position:M}=p,z=new Map,D=this._materials[Mt.Main];for(const i of I){const t=i.count;if(this._context.clippingExtent&&(j(i.mapPositions,u),!P(u,this._context.clippingExtent)))continue;const o=s(i.mapPositions,i.holeIndices,3);if(0===o.length)continue;const n=o.length,a=6*t,c=O(a+n),m=O(n),p=w(3*a),h=w(3*a),b=w(3*a),x=w(a);nt(M,A,o,i,p,b,h,x,c,m,this._getExtrusionSize(e),y,_),E(p,p,C);const S=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:l,layerViewUid:this._context.layerViewUid}),v=new Lt(p,b,X(h),x),I=it(D,c,c.length-m.length,v,r,S),L=t,B=t,R=2*i.count,U=new Bt(L,B,R,n/3);_t(I,U,f),z.set(I,U),g.push(I,it(this._materials[Mt.Bottom],m,0,v,r,S)),d.push(v.heights)}if(0===g.length)return null;const G=new $({geometries:g,layerViewUid:this._context.layerViewUid,graphicUid:l,isElevationSource:!0});G.transformation=f;const T=F(this.symbolLayer,{opacity:this._getLayerOpacity()}),k=T?new R(this._materials[Mt.Main],T,this._context.slicePlaneEnabled):null,H=new U(this,G,null,((t,e,r,o,s)=>bt(t,e,r,o,s,d,z)),o,k);return H.alignedSampledElevation=p.sampledElevation,H.needsElevationUpdates=B(o.mode),H}_getFallbackOpacityAndColor(){const e=this.symbolLayer?.material?.color;return t.toUnitRGBA(e)??_}}function it(t,e,r,o,s,i){const n=C(e.length),a=[[tt.POSITION,new Z(o.positions,e,3,!0)],[tt.NORMALCOMPRESSED,new Z(o.normals,e,2,!0)],[tt.COLOR,new Z(s,n,4,!0)]];return new K(t,a,o.elevation,rt.Mesh,i,r)}function nt(t,e,r,o,s,i,n,a,l,c,m,p,h){{const g=r.length/3,d=2*o.count;at(t,e,o.index,o.count,r,0,g,s,i,n,a,l,c,d,m,p,h)}{let t=0,e=2*o.count,r=0;const c=o.pathLengths[0];mt(s,i,a,n,t,c,o.count,e,l,r,m),e+=4*c,r+=2*c,t+=c;for(let p=1;p<o.pathLengths.length;++p){const c=o.pathLengths[p];mt(s,i,a,n,t,c,o.count,e,l,r,m),e+=4*c,r+=2*c,t+=c}}}function at(t,e,r,o,s,i,n,a,l,c,h,g,d,u,f,y,b){m(jt,y);{const s=f>0?1:-1;let i=3*r,n=0,m=3*n,g=o,d=3*g;for(let r=0;r<o;++r){const r=t[i],o=t[i+1],u=t[i+2];b&&(jt[0]=r,jt[1]=o,jt[2]=u,p(jt,jt)),a[m+0]=r,a[m+1]=o,a[m+2]=u;const y=e[i+0],_=e[i+1],x=e[i+2];l[m+0]=y,l[m+1]=_,l[m+2]=x,c[m+0]=-s*jt[0],c[m+1]=-s*jt[1],c[m+2]=-s*jt[2],h[n]=0,a[d+0]=r+f*jt[0],a[d+1]=o+f*jt[1],a[d+2]=u+f*jt[2],l[d+0]=y,l[d+1]=_,l[d+2]=x,h[g]=f,m+=3,d+=3,i+=3,n+=1,g+=1}}{let t=3*i,e=0,r=3*u;const a=f<0?Ot:wt,l=f<0?wt:Ot;for(let i=0;i<n;++i)d[e]=s[t+a[0]],d[e+1]=s[t+a[1]],d[e+2]=s[t+a[2]],g[r]=s[t+l[0]]+o,g[r+1]=s[t+l[1]]+o,g[r+2]=s[t+l[2]]+o,e+=3,r+=3,t+=3}}function lt(t,e,r,o,s,i,n){o[i]=o[n],n*=3,t[i*=3]=t[n],t[i+1]=t[n+1],t[i+2]=t[n+2],e[i]=e[n],e[i+1]=e[n+1],e[i+2]=e[n+2],r[i]=s[0],r[i+1]=s[1],r[i+2]=s[2]}const ct=b();function mt(t,e,r,o,s,i,n,a,l,c,m){let p=s,h=s+1,g=s+n,d=s+n+1,u=a,f=a+1,y=a+2*i,b=a+2*i+1;m<0&&(p=s+n+1,d=s);let _=3*c;for(let x=0;x<i;++x)x===i-1&&(h=s,m>0?d=s+n:p=s+n),ft(t,p,h,g,ct),lt(t,e,o,r,ct,u,p),lt(t,e,o,r,ct,f,h),lt(t,e,o,r,ct,y,g),lt(t,e,o,r,ct,b,d),l[_]=u,l[_+1]=y,l[_+2]=b,l[_+3]=u,l[_+4]=b,l[_+5]=f,_+=6,p++,h++,g++,d++,u+=2,f+=2,y+=2,b+=2}const pt=b(),ht=b(),gt=b(),dt=b(),ut=b();function ft(t,e,r,o,s){e*=3,r*=3,o*=3,h(pt,t[e++],t[e++],t[e++]),h(ht,t[r++],t[r++],t[r++]),h(gt,t[o++],t[o++],t[o++]),g(dt,ht,pt),g(ut,gt,pt),d(s,ut,dt),p(s,s)}const yt=b();function bt(t,e,r,o,s,i,n){const a=t.stageObject,m=a.geometries,p=m.length,g="absolute-height"!==e.mode;let d=0;const f=a.transformation,y=l(c(),f);for(let l=0;l<p;l+=2){const t=m[l];if(!Q(t))continue;const e=t.getMutableAttribute(tt.POSITION).data,c=i[l/2],p=new H(t.mapPositions),b=e.length/3;let _=!1,x=0;{let t=0;for(let i=0;i<b;i++){yt[0]=e[t],yt[1]=e[t+1],yt[2]=e[t+2],o(p,Pt),g&&(x+=Pt.sampledElevation),k.TESTS_DISABLE_OPTIMIZATIONS?(h(St,p.array[p.offset],p.array[p.offset+1],Pt.z+c[t/3]),null!=r&&s.toRenderCoords(St,r,St),u(St,St,y)):(h(St,e[t],e[t+1],e[t+2]),u(St,St,f),s.setAltitude(St,Pt.z+c[t/3]),u(St,St,y)),e[t]=St[0],e[t+1]=St[1],e[t+2]=St[2];const i=Ct/s.unitInMeters;(Math.abs(yt[0]-e[t])>=i||Math.abs(yt[1]-e[t+1])>=i||Math.abs(yt[2]-e[t+2])>=i)&&(_=!0),p.offset+=3,t+=3}}if(_){const e=n.get(t);e&&_t(t,e,f),a.geometryVertexAttributeUpdated(m[l],tt.NORMALCOMPRESSED),t.invalidateBoundingInfo(),a.geometryVertexAttributeUpdated(m[l],tt.POSITION),m[l+1].invalidateBoundingInfo(),a.geometryVertexAttributeUpdated(m[l+1],tt.POSITION)}d+=x/b}return d/p}function _t(t,e,r){const o=t.getMutableAttribute(tt.POSITION),s=t.getMutableAttribute(tt.NORMALCOMPRESSED).data,{topVertexStart:i,topVertexCount:n,topFaceStart:a,topFaceCount:l}=e,c=o.data,m=n,g=t.attributes.get(tt.POSITION).indices,y=a+l,b=i+n,_=w(3*m);for(let p=0;p<m;++p){const t=3*p;_[t+0]=0,_[t+1]=0,_[t+2]=0}const x=Et,S=vt,j=It,P=At,O=jt;for(let w=a;w<y;++w){const t=3*w;for(let e=0;e<3;++e){const o=g[t+e];P[e]=o;const s=3*o;h(St,c[s+0],c[s+1],c[s+2]),u(x[e],St,r)}f(S,x[1],x[0]),f(j,x[2],x[0]),d(O,S,j),p(O,O);for(let e=0;e<3;++e){const t=3*(P[e]-i);_[t+0]+=O[0],_[t+1]+=O[1],_[t+2]+=O[2]}}for(let p=i;p<b;++p){const t=3*(p-i),e=_[t+0],r=_[t+1],o=_[t+2],n=Math.sqrt(e*e+r*r+o*o);Y(s,p,e/n,r/n,o/n)}}function xt(t){return 1===(t.material?.color?.a??1)}const St=b(),jt=b(),Pt=new z,wt=[0,2,1],Ot=[0,1,2],Ct=.01,Et=[b(),b(),b()],vt=b(),It=b(),At=[0,0,0];var Mt;!function(t){t[t.Main=0]="Main",t[t.Bottom=1]="Bottom"}(Mt||(Mt={}));class Lt{constructor(t,e,r,o){this.positions=t,this.elevation=e,this.normals=r,this.heights=o}}class Bt{constructor(t,e,r,o){this.topVertexStart=t,this.topVertexCount=e,this.topFaceStart=r,this.topFaceCount=o}}export{st as Graphics3DExtrudeSymbolLayer,nt as extrudePolygon};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../../Color.js";import{result as t,createTask as r}from"../../../../core/asyncUtils.js";import i from"../../../../core/Error.js";import has from"../../../../core/has.js";import{clone as s}from"../../../../core/lang.js";import{abortMaybe as o,releaseMaybe as a}from"../../../../core/maybe.js";import{throwIfAbortError as n,throwIfAborted as l}from"../../../../core/promiseUtils.js";import{pt2px as c,px2pt as h}from"../../../../core/screenUtils.js";import{numericHash as u}from"../../../../core/string.js";import{dataComponents as m}from"../../../../core/urlUtils.js";import{fromValues as d,create as p}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as _,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as y,ZEROS as g,fromValues as x}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{projectPointToVector as b}from"../../../../geometry/projection/projectPointToVector.js";import{containsPoint as v}from"../../../../geometry/support/aaBoundingBox.js";import S from"../../../../layers/support/FieldsIndex.js";import{createRendererExpression as P}from"../../../../support/ArcadeExpression.js";import{CIMSymbolHelper as w}from"../../../../symbols/cim/CIMSymbolHelper.js";import{evaluateValueOrFunction as R}from"../../../../symbols/cim/utils.js";import{scaleCIMSymbol as z}from"../../../../symbols/support/cimSymbolUtils.js";import{defaultPrimitive as C}from"../../../../symbols/support/IconSymbol3DLayerResource.js";import{Symbol3DAnchorPosition2D as O}from"../../../../symbols/support/Symbol3DAnchorPosition2D.js";import{getIconHref as M}from"../../../../symbols/support/utils.js";import{focusAreaHUDColor as j}from"../../../FocusAreas.js";import{transparentUnit as I}from"./constants.js";import{perObjectElevationAligner as E}from"./ElevationAligners.js";import{SymbolUpdateType as T,elevationModeChangeUpdateType as F,needsElevationUpdates2D as A}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as U}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as D}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as L}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as G}from"./graphicUtils.js";import{ApplyRendererDiffResult as V}from"./interfaces.js";import{namedAnchorToHUDMaterialAnchorPos as H}from"./placementUtils.js";import{placePointOnGeometry as k,updateStageObjectGeometry as B,getLocalOriginForPoint as N,extendPointGraphicElevationContext as $,createStageObject as W}from"./pointUtils.js";import{initFastSymbolUpdatesState as q,updateFastSymbolUpdatesState as J,evaluateModelTransformScale as Z,ConvertOptions as K}from"../support/FastSymbolUpdates.js";import{createTexture as Q,requiresHalfTexelOffset as X,defaultBoundingBox as Y,defaultSymbolSizeRatio as ee,defaultTexSize as te}from"../../support/engineContent/sdfPrimitives.js";import{drapedZ as re}from"../../terrain/OverlayRenderer.js";import{createPointGeometry as ie}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderGeometry as se}from"../../webgl-engine/lib/RenderGeometry.js";import{Texture as oe}from"../../webgl-engine/lib/Texture.js";import{HUDMaterial as ae}from"../../webgl-engine/materials/HUDMaterial.js";const ne=_(0,0,1),le=16,ce=1.5,he=[te*ee,te*ee];class ue extends L{static{this.PRIMITIVE_SIZE=he}getCachedSize(){return{size:this._getIconSize()}}static{this.elevationModeChangeTypes={definedChanged:T.UPDATE,staysOnTheGround:T.NONE,onTheGroundChanged:T.RECREATE}}constructor(e,t,r,i){super(e,t,r,i,ge(t)),this._cimData=null,this._overrideHelperClass=null,this._arcadeInfo=null,this._cimSymbolMaterials=new Map,this._cimSymbolTextures=new Map,this._cimMaterialParametersInfo=null,this._cimScaleFactorOrFunction=null,this._size=null,this._symbolTextureRatio=1,this._outlineSize=0,this._textureHandle=null,this._patchTask=null,this._elevationOptions={supportsOffsetAdjustment:!0,supportsOnTheGround:!0}}async doLoad(e){this._validateOrThrow();const t=this._prepareMaterialParameters(),r=this._getPrimitive();if(null!=r)this._prepareResourcesPrimitive(t,r);else{const r=M(this.symbolLayer),i=pe(r);null!=i?await this._prepareResourcesCIM(t,JSON.parse(i),e):await this._prepareResourcesHref(t,r,e)}}_validateOrThrow(){if(this._drivenProperties.size)return;const e=G(this._getIconSize());if(e)throw new i("graphics3diconsymbollayer:invalid-size",e)}_getIconSize(){const e=this.symbolLayer,t=Math.round(null!=e.size?c(e.size):le);return this._drivenProperties.size?Math.max(t,64):t}_generateTextureCIM(e,t){const r=this._overrideHelperClass;let i=this._cimData;if(r&&i&&i.symbol||this.logger.error("Can't create texture, CIM data is undefined"),i.primitiveOverrides){i=s(i);const o=i.primitiveOverrides;r.evaluateOverrides(o,e,this._arcadeInfo.geometryType,null,null,t.layer.fieldsIndex),r.applyOverrides(i.symbol,o)}const o=u(JSON.stringify(i));let a=this._cimSymbolTextures.get(o);if(a)return a;const n=this._context.sharedResources.cimSymbolRasterizer,l=this._context.renderer&&"dictionary"===this._context.renderer.type?this._context.renderer.fieldMap:null;l&&r.applyDictionaryTextOverrides(i.symbol,e,l,null);const c=null!=this._cimScaleFactorOrFunction?R(this._cimScaleFactorOrFunction,e):1;1!==c&&i.symbol&&z(i.symbol,c,!0);const h=w.getEnvelope(i,null,n.resourceManager);if(h?.width&&h.height){const e=h.x+h.width/2,t=h.y+h.height/2,r=n.rasterize({type:"cim",data:i},h.width,h.height,e,t,1,"esriGeometryPoint",0,null,this._context.graphicsCoreOwner.view.state.rasterPixelRatio),s=new O({x:-h.x/h.width-.5,y:(h.height+h.y)/h.height-.5});this._cimMaterialParametersInfo.anchorPosition=_e("relative",s),a=new oe(r,{width:r?.width??1,height:r?.height??1,reloadable:!0})}else a=new oe(new ImageData(1,1),{width:1,height:1,reloadable:!0});return this._cimSymbolTextures.set(o,a),this._context.stage.add(a),a}_prepareMaterialParameters(){const e={anchorPosition:_e(this.symbolLayer.anchor,this.symbolLayer.anchorPosition),rotation:this.symbolLayer.angle},t=this.symbol;if(me(t)){const{screenLength:r,minWorldLength:i,maxWorldLength:s}=t.verticalOffset;e.verticalOffset={screenLength:c(r),minWorldLength:i||0,maxWorldLength:null!=s?s:1/0}}this._context.screenSizePerspectiveEnabled&&(e.screenSizePerspective=this._context.sharedResources.screenSizePerspectiveSettings),(0!==e.rotation||this._drivenProperties.rotation)&&(e.hasRotation=!0);const r=!has("disable-feature:non-occluded-hud");return e.occlusionTest=!r,e.occludedFragmentFade=r,e.horizonCullingEnabled=r&&this._context.spherical,e.hasSlicePlane=this._context.slicePlaneEnabled,e}_prepareResourcesPrimitive(e,t){const r=this._getOutlineSize();if(de(t)&&0===r)throw new Error("Nothing to render");if(this._outlineSize=r,e.color=this._getFillColor(),e.outlineColor=this._getOutlineColor(),e.outlineSize=this._outlineSize,null!=this._context.sharedResources.textures){const r=this._context.sharedResources.textures.fromData(`${t}-icon`,(()=>Q(t)));this._textureHandle=r,e.textureId=r.texture.id}e.textureIsSignedDistanceField=!0,e.sampleSignedDistanceFieldTexelCenter=X(t),e.distanceFieldBoundingBox=Y;const i=this._getIconSize();this._size=[i,i],this._symbolTextureRatio=1/ee,this._createMaterialAndAddToStage(e,this._context.stage)}async _prepareResourcesHref(e,r,s){this._outlineSize=this._getOutlineSize(),e.color=this._getFillColor(),e.outlineColor=this._getOutlineColor(),e.outlineSize=this._outlineSize,e.textureIsSignedDistanceField=!1;const o=this._getIconSize(),a=o*this._context.graphicsCoreOwner.view.state.rasterPixelRatio;if(null!=this._context.sharedResources.textures){const l=await t(this._context.sharedResources.textures.fromUrl(r,a,{signal:s}));if(!1===l.ok){n(l.error);throw new i("graphics3diconsymbollayer:request-failed",`Failed to load (Request for icon resource failed: ${r})`)}this._textureHandle=l.value;const c=l.value.texture;this._size=fe(c,o),e.textureId=c.id}this._createMaterialAndAddToStage(e,this._context.stage)}async _prepareResourcesCIM(e,t,r){const{OverrideHelper:i}=await import("../../../../symbols/cim/OverrideHelper.js");if(this._overrideHelperClass=i,this._cimData=t,!this._context.sharedResources.cimSymbolRasterizer){const e=(await import("../../../../symbols/cim/CIMSymbolRasterizer.js")).CIMSymbolRasterizer;l(r),this._context.sharedResources.cimSymbolRasterizer||(this._context.sharedResources.cimSymbolRasterizer=new e(this._context.renderCoordsHelper.spatialReference))}const s=this._context.sharedResources.cimSymbolRasterizer,o=[],a=t,n=a?.symbol;w.fetchResources(n,s.resourceManager,o,r),w.fetchFonts(n,s.resourceManager,o);const c=this._context.layer.fields?this._context.layer.fields.map((e=>e.toJSON())):[],h=this._context.renderCoordsHelper.spatialReference;if(this._arcadeInfo={spatialReference:h,fields:c,geometryType:"esriGeometryPoint"},a?.primitiveOverrides&&o.push(i.createRenderExpressions(a.primitiveOverrides,this._arcadeInfo)),o.length>0&&(await Promise.all(o),l(r)),this._context.renderer&&"dictionary"===this._context.renderer.type&&this._context.renderer.scaleExpression){const e=this._context.renderer;if(e.scaleExpression){const t=e.scaleExpression,r=await P(t,this._context.layer.spatialReference),{default:i}=await import("../../../2d/arcade/callExpressionWithFeature.js"),s=new S(c);this._cimScaleFactorOrFunction=(e,t,o)=>{const a=i(r,e,{$view:o},"esriGeometryPoint",s,t);return null!==a?a:1}}}l(r),this._cimMaterialParametersInfo=e,this._cimMaterialParametersInfo.color=this._getFillColor(),this._cimMaterialParametersInfo.outlineColor=[0,0,0,0],this._cimMaterialParametersInfo.outlineSize=0,this._cimMaterialParametersInfo.textureIsSignedDistanceField=!1}_getPrimitive(){return ye(this.symbolLayer)}_getOutlineSize(){let e=0;const t=this.symbolLayer;if(null!=t.outline?.size)return Math.max(c(t.outline.size),0);return e=de(this._getPrimitive())?ce:0,Math.max(e,0)}_getOutlineColor(){const t=this._getLayerOpacity(),r=this.symbolLayer,i=r?.outline?.color;if(null!=i){const r=e.toUnitRGB(i),s=i.a*t;return[r[0],r[1],r[2],s]}return[0,0,0,0]}_getFillColor(){if(de(this._getPrimitive()))return I;const e=null==this._getPrimitive(),t=this.symbolLayer?.material?.color;return this._getCombinedOpacityAndColor(t,{hasIntrinsicColor:e})}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;if(null==t){return null==this._getPrimitive()?y:g}return e.toUnitRGBA(t)}_getFallbackSize(){const e=this._getIconSize(),{symbolLayer:{size:t}}=this;return(null!=t?Math.round(c(t)):le)/e}_createMaterialAndAddToStage(e,t){const r=this._context.spherical;if(this._cimData){this._fastUpdates=null;let i=e.textureId?this._cimSymbolMaterials.get(e.textureId):null;return i||(i=new ae(e,r),this._cimSymbolMaterials.set(e.textureId??0,i),t.add(i)),i}this._fastUpdates=q(this._context.renderer,this._fastVisualVariableConvertOptions()),this._fastUpdates&&(e={...e,...this._fastUpdates.materialParameters}),this._materials[0]=new ae(e,r),t.add(this._materials[0]),e.isFocused=!1;const i=this._context.stage.view.focusAreas.style;return e.color=j(e.color,i),e.outlineColor=j(e.outlineColor,i),this._materials[1]=new ae(e,r),t.add(this._materials[1]),this._materials[0]}_setDrapingDependentMaterialParameters(){this.draped&&(this._forEachMaterial((e=>{e.setParameters({verticalOffset:null,screenSizePerspective:null,occlusionTest:!1,hasSlicePlane:!1,shaderPolygonOffset:0,draped:this.draped})})),this.layerOpacityChanged())}destroy(){super.destroy(),this._patchTask=o(this._patchTask),this._forEachMaterial((e=>this._context.stage.remove(e))),this._materials.length=0,this._cimSymbolMaterials.clear(),this._cimSymbolTextures.forEach((e=>this._context.stage.remove(e))),this._cimSymbolTextures.clear(),this._textureHandle=a(this._textureHandle)}_getScaleFactor({size:e},t){if(!this._drivenProperties.size)return 1;if(null==e)return this._getFallbackSize();const[r,i,s]=e;return"symbol-value"===r?1:"number"==typeof r&&isFinite(r)?c(r)/t:"number"==typeof s&&isFinite(s)?c(s)/t:1}_getDrivenRotation(e){return this._drivenProperties.rotation?e.heading??0:0}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry))return null;let r,i=[0,0];const s=k(t.geometry);if(null==s)return this.logger.warn(`unsupported geometry type for text symbol: ${t.geometry.type}`),null;const o=this._context.stage.view.focusAreas.containsGeometry(s);if(this._cimData){if(!this._cimData.symbol)return null;const s=this._generateTextureCIM(t,e),a={textureId:s.id,isFocused:o,...this._cimMaterialParametersInfo};r=this._createMaterialAndAddToStage(a,this._context.stage);const n=this._context.graphicsCoreOwner.view.state.rasterPixelRatio;i=[s.parameters.width/n,s.parameters.height/n]}else i=this._size,r=o?this._materials[0]:this._materials[1];if(null==s)return this.logger.warn(`unsupported geometry type for icon symbol: ${t.geometry.type}`),null;const a=e.renderingInfo,n=this._getVertexOpacityAndColor(a,this._getFallbackOpacityAndColor()),l=this._getDrivenRotation(a);let c=1;if(!this._fastUpdates?.visualVariables.size){const e=i[0]>i[1]?i[0]:i[1];c=this._getScaleFactor(a,e)}c*=this._symbolTextureRatio;const h=d(i[0]*c,i[1]*c),u=this.setGraphicElevationContext(t);return this.ensureDrapedStatus("on-the-ground"===u.mode)&&this._setDrapingDependentMaterialParameters(),this.draped?this._createAsOverlay(t,s,r,n,l,h):this._createAs3DShape(t,s,r,n,l,h,u,t.uid)}layerOpacityChanged(){const e=this._getFillColor(),t=this._getOutlineColor();this._forEachMaterial((r=>{r.setParameters({color:e}),r.setParameters({outlineColor:t})}))}updateGeometry(e,t){if(this.draped||!this._validateGeometry(t))return!1;const{elevationContext:r,stageObject:i}=e;if(r.mode!==this.getGeometryElevationMode(t))return!1;const s=k(t);if(!s)return!1;const o=B(i,this._context,s,r);if(null==o)return!1;const a=N(this._context,s);return i.geometries[0].localOrigin===a&&(e.alignedSampledElevation=o,$(e,s,this._context.elevationProvider),!0)}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,s=F(ue.elevationModeChangeTypes,r,i);if(s!==T.UPDATE)return s;const o=A(i)||"absolute-height"===i;return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>o))}slicePlaneEnabledChanged(){return this.draped||this._forEachMaterial((e=>{e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled})})),!0}physicalBasedRenderingChanged(){return!0}get pixelRatioChanged(){return null!=this._getPrimitive()}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return V.RecreateSymbol;if(!J(this._fastUpdates,t,this._fastVisualVariableConvertOptions()))return V.RecreateSymbol;this._materials[0]?.setParameters(this._fastUpdates.materialParameters)}return V.FastUpdate}updateFocus(e,t){t.forEach((t=>{const r=k(t.graphic.geometry);if(null==r)return void this.logger.warn(`unsupported geometry type for text symbol: ${t.graphic.geometry.type}`);const i=this._context.stage.view.focusAreas.containsGeometry(r);t.layers.forEach((r=>{if(r?.graphics3DSymbolLayer===this){const s=r.stageObject.geometries.some((e=>e.material.parameters.isFocused!==i));s&&e(t)}}))}))}prepareSymbolLayerPatch(e){if(this._patchTask?.abort(),"partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchResource(e,t),this._preparePatchRotation(e,t)}_preparePatchResource(e,s){if(!s.resource||"partial"!==s.resource.type)return;const c=s.resource.diff;if("complete"!==c?.href?.type)return;const h=c.href.newValue,{textures:u}=this._context.sharedResources;if(null==h||null==u||null!=pe(h))return;const m=this._getIconSize(),d=m*this._context.graphicsCoreOwner.view.state.pixelRatio;e.symbolLayerStatePatches.push((()=>{this._patchTask=o(this._patchTask),this._patchTask=r((e=>this._context.schedule((async(e,r)=>{const s=await t(u.fromUrl(h,d,{signal:r}));l(r);const o=!s.ok;if(o&&n(s.error),this._textureHandle=a(this._textureHandle),this._patchTask=null,o){this._forEachMaterial((e=>{e.visible=!1,e.setParameters({textureId:null})}));const e=`Failed to load (Request for icon resource failed: ${h})`;return void this.logger.error(new i("graphics3diconsymbollayer:request-failed",e))}this._textureHandle=s.value;const c=s.value.texture;this._size=fe(c,m),this._forEachMaterial((e=>{e.setParameters({textureId:c.id}),e.visible=!0}))}),e)))})),delete c.href}_preparePatchRotation(e,t){if(!t.angle||"complete"!==t.angle.type)return;const r=t.angle.newValue??0,i=0!==r||this._drivenProperties.rotation;e.symbolLayerStatePatches.push((()=>{this._forEachMaterial((e=>e.setParameters({rotation:r,hasRotation:i})))})),delete t.angle}_defaultElevationInfoNoZ(){return xe}_createAs3DShape(e,t,r,i,s,o,a,n){const l=this.getFastUpdateAttrValues(e),c=this._context.layerViewUid,h=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:n,layerViewUid:c}),u=ie(r,{normal:ne,color:i,rotation:s,size:o,centerOffsetAndDistance:be,featureAttribute:l,objectAndLayerIdColor:h}),m=W(this._context,t,u,a,n);if(null==m)return null;const d=new D(this,m.object,[u],null,null,E,a);return d.alignedSampledElevation=m.sampledElevation,d.needsElevationUpdates=A(a.mode)||"absolute-height"===a.mode,d.getScreenSize=this._createScreenSizeGetter(o,l),d.calculateRelativeScreenBounds=e=>r.calculateRelativeScreenBounds(d.getScreenSize(),1,e),$(d,t,this._context.elevationProvider),d}_createAsOverlay(e,t,r,i,s,o){r.renderPriority=this._renderPriority;const a=f();b(t,a,this._context.overlaySR),a[2]=re;const n=this._context.clippingExtent;if(null!=n&&!v(n,a))return null;const l=this.getFastUpdateAttrValues(e),c=e.uid,h=this._context.layerViewUid,u=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:c,layerViewUid:h}),m=ie(r,{normal:ne,position:a,color:i,rotation:s,size:o,featureAttribute:l,objectAndLayerIdColor:u}),d=new se(m,{layerViewUid:h,graphicUid:c}),p=new U(this,[d],null,this._context.drapeSourceRenderer);return p.getScreenSize=this._createScreenSizeGetter(o,l),p.calculateRelativeScreenBounds=e=>r.calculateRelativeScreenBounds(p.getScreenSize(),1,e),p}_createScreenSizeGetter(e,t){const r=this._outlineSize+2;if(this._fastUpdates&&t){const i=e[0]/this._symbolTextureRatio,s=e[1]/this._symbolTextureRatio;return(e=p())=>{const[o,a]=Z(ve,this._fastUpdates.materialParameters,t);return e[0]=o*i+r,e[1]=a*s+r,e}}const i=e[0]/this._symbolTextureRatio+r,s=e[1]/this._symbolTextureRatio+r;return(e=p())=>(e[0]=i,e[1]=s,e)}_fastVisualVariableConvertOptions(){const e=Math.max(this._size[0],this._size[1]),t=_(e,e,e),r=h(1),i=e*r,s=_(i,i,i),o=this._getFallbackSize();return new K({supports:{size:!0,color:!0,rotation:!0,opacity:!1},modelSize:t,symbolSize:s,unitInMeters:r,fallbackColor:this._getFallbackOpacityAndColor(),fallbackSize:_(o,o,o)})}_forEachMaterial(e){this._materials.forEach(e),this._cimSymbolMaterials.forEach(e)}test(){return{...super.test(),material:this._materials[0]}}}function me(e){return e&&"point-3d"===e.type&&e.hasVisibleVerticalOffset()}function de(e){return null!=e&&("cross"===e||"x"===e)}function pe(e){const t=m(e);return"application/json"===t?.mediaType?t.data:void 0}function _e(e,t){return"relative"===e?d((t.x||0)+.5,.5-(t.y||0)):e in H?H[e]:H.center}function fe({parameters:e},t){const r=(e.width??1)/(e.height??1);return r>1?[t,Math.round(t/r)]:[Math.round(t*r),t]}function ye(e){return e.resource?.href?null:e.resource?.primitive??C}function ge(e){return 1===(e.material?.color?.a??1)&&null!=ye(e)}const xe={mode:"relative-to-ground",offset:0},be=x(0,0,0,1),ve=f();export{ue as Graphics3DIconSymbolLayer};
|
|
5
|
+
import e from"../../../../Color.js";import{result as t,createTask as r}from"../../../../core/asyncUtils.js";import i from"../../../../core/Error.js";import has from"../../../../core/has.js";import{clone as s}from"../../../../core/lang.js";import{abortMaybe as o,releaseMaybe as a}from"../../../../core/maybe.js";import{throwIfAbortError as n,throwIfAborted as l}from"../../../../core/promiseUtils.js";import{pt2px as c,px2pt as h}from"../../../../core/screenUtils.js";import{numericHash as u}from"../../../../core/string.js";import{dataComponents as m}from"../../../../core/urlUtils.js";import{fromValues as d,create as p}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{fromValues as _,create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as y,ZEROS as g,fromValues as x}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{projectPointToVector as b}from"../../../../geometry/projection/projectPointToVector.js";import{containsPoint as v}from"../../../../geometry/support/aaBoundingBox.js";import S from"../../../../layers/support/FieldsIndex.js";import{createRendererExpression as P}from"../../../../support/ArcadeExpression.js";import{CIMSymbolHelper as w}from"../../../../symbols/cim/CIMSymbolHelper.js";import{evaluateValueOrFunction as R}from"../../../../symbols/cim/utils.js";import{scaleCIMSymbol as z}from"../../../../symbols/support/cimSymbolUtils.js";import{defaultPrimitive as C}from"../../../../symbols/support/IconSymbol3DLayerResource.js";import{Symbol3DAnchorPosition2D as O}from"../../../../symbols/support/Symbol3DAnchorPosition2D.js";import{getIconHref as j}from"../../../../symbols/support/utils.js";import{focusAreaHUDColor as I}from"../../../FocusAreas.js";import{transparentUnit as M}from"./constants.js";import{perObjectElevationAligner as E}from"./ElevationAligners.js";import{SymbolUpdateType as F,elevationModeChangeUpdateType as T,needsElevationUpdates2D as U}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as D}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as A}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as L}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as G}from"./graphicUtils.js";import{ApplyRendererDiffResult as V}from"./interfaces.js";import{namedAnchorToHUDMaterialAnchorPos as H}from"./placementUtils.js";import{placePointOnGeometry as k,updateStageObjectGeometry as B,getLocalOriginForPoint as N,extendPointGraphicElevationContext as $,createStageObject as W}from"./pointUtils.js";import{initFastSymbolUpdatesState as q,updateFastSymbolUpdatesState as J,evaluateModelTransformScale as Z,ConvertOptions as K}from"../support/FastSymbolUpdates.js";import{createTexture as Q,requiresHalfTexelOffset as X,defaultBoundingBox as Y,defaultSymbolSizeRatio as ee,defaultTexSize as te}from"../../support/engineContent/sdfPrimitives.js";import{drapedZ as re}from"../../terrain/OverlayRenderer.js";import{createPointGeometry as ie}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderGeometry as se}from"../../webgl-engine/lib/RenderGeometry.js";import{Texture as oe}from"../../webgl-engine/lib/Texture.js";import{HUDMaterial as ae}from"../../webgl-engine/materials/HUDMaterial.js";const ne=_(0,0,1),le=16,ce=1.5,he=[te*ee,te*ee];class ue extends L{static{this.PRIMITIVE_SIZE=he}getCachedSize(){return{size:this._getIconSize()}}static{this.elevationModeChangeTypes={definedChanged:F.UPDATE,staysOnTheGround:F.NONE,onTheGroundChanged:F.RECREATE}}constructor(e,t,r,i){super(e,t,r,i,ge(t)),this._cimData=null,this._overrideHelperClass=null,this._arcadeInfo=null,this._cimSymbolMaterials=new Map,this._cimSymbolTextures=new Map,this._cimMaterialParametersInfo=null,this._cimScaleFactorOrFunction=null,this._size=null,this._symbolTextureRatio=1,this._outlineSize=0,this._textureHandle=null,this._patchTask=null,this._elevationOptions={supportsOffsetAdjustment:!0,supportsOnTheGround:!0}}async doLoad(e){this._validateOrThrow();const t=this._prepareMaterialParameters(),r=this._getPrimitive();if(null!=r)this._prepareResourcesPrimitive(t,r);else{const r=j(this.symbolLayer),i=pe(r);null!=i?await this._prepareResourcesCIM(t,JSON.parse(i),e):await this._prepareResourcesHref(t,r,e)}}_validateOrThrow(){if(this._drivenProperties.size)return;const e=G(this._getIconSize());if(e)throw new i("graphics3diconsymbollayer:invalid-size",e)}_getIconSize(){const e=this.symbolLayer,t=Math.round(null!=e.size?c(e.size):le);return this._drivenProperties.size?Math.max(t,64):t}_generateTextureCIM(e,t){const r=this._overrideHelperClass;let i=this._cimData;if(r&&i&&i.symbol||this.logger.error("Can't create texture, CIM data is undefined"),i.primitiveOverrides){i=s(i);const o=i.primitiveOverrides;r.evaluateOverrides(o,e,this._arcadeInfo.geometryType,null,null,t.layer.fieldsIndex),r.applyOverrides(i.symbol,o)}const o=u(JSON.stringify(i));let a=this._cimSymbolTextures.get(o);if(a)return a;const n=this._context.sharedResources.cimSymbolRasterizer,l=this._context.renderer&&"dictionary"===this._context.renderer.type?this._context.renderer.fieldMap:null;l&&r.applyDictionaryTextOverrides(i.symbol,e,l,null);const c=null!=this._cimScaleFactorOrFunction?R(this._cimScaleFactorOrFunction,e):1;1!==c&&i.symbol&&z(i.symbol,c,!0);const h=w.getEnvelope(i,null,n.resourceManager);if(h?.width&&h.height){const e=h.x+h.width/2,t=h.y+h.height/2,r=n.rasterize({type:"cim",data:i},h.width,h.height,e,t,1,"esriGeometryPoint",0,null,this._context.graphicsCoreOwner.view.state.rasterPixelRatio),s=new O({x:-h.x/h.width-.5,y:(h.height+h.y)/h.height-.5});this._cimMaterialParametersInfo.anchorPosition=_e("relative",s),a=new oe(r,{width:r?.width??1,height:r?.height??1,reloadable:!0})}else a=new oe(new ImageData(1,1),{width:1,height:1,reloadable:!0});return this._cimSymbolTextures.set(o,a),this._context.stage.add(a),a}_prepareMaterialParameters(){const e={anchorPosition:_e(this.symbolLayer.anchor,this.symbolLayer.anchorPosition),rotation:this.symbolLayer.angle},t=this.symbol;if(me(t)){const{screenLength:r,minWorldLength:i,maxWorldLength:s}=t.verticalOffset;e.verticalOffset={screenLength:c(r),minWorldLength:i||0,maxWorldLength:null!=s?s:1/0}}this._context.screenSizePerspectiveEnabled&&(e.screenSizePerspective=this._context.sharedResources.screenSizePerspectiveSettings),(0!==e.rotation||this._drivenProperties.rotation)&&(e.hasRotation=!0);const r=!has("disable-feature:non-occluded-hud");return e.occlusionTest=!r,e.occludedFragmentFade=r,e.horizonCullingEnabled=r&&this._context.spherical,e.hasSlicePlane=this._context.slicePlaneEnabled,e}_prepareResourcesPrimitive(e,t){const r=this._getOutlineSize();if(de(t)&&0===r)throw new Error("Nothing to render");if(this._outlineSize=r,e.color=this._getFillColor(),e.outlineColor=this._getOutlineColor(),e.outlineSize=this._outlineSize,null!=this._context.sharedResources.textures){const r=this._context.sharedResources.textures.fromData(`${t}-icon`,(()=>Q(t)));this._textureHandle=r,e.textureId=r.texture.id}e.textureIsSignedDistanceField=!0,e.sampleSignedDistanceFieldTexelCenter=X(t),e.distanceFieldBoundingBox=Y;const i=this._getIconSize();this._size=[i,i],this._symbolTextureRatio=1/ee,this._createMaterial(e)}async _prepareResourcesHref(e,r,s){this._outlineSize=this._getOutlineSize(),e.color=this._getFillColor(),e.outlineColor=this._getOutlineColor(),e.outlineSize=this._outlineSize,e.textureIsSignedDistanceField=!1;const o=this._getIconSize(),a=o*this._context.graphicsCoreOwner.view.state.rasterPixelRatio;if(null!=this._context.sharedResources.textures){const l=await t(this._context.sharedResources.textures.fromUrl(r,a,{signal:s}));if(!1===l.ok){n(l.error);throw new i("graphics3diconsymbollayer:request-failed",`Failed to load (Request for icon resource failed: ${r})`)}this._textureHandle=l.value;const c=l.value.texture;this._size=fe(c,o),e.textureId=c.id}this._createMaterial(e)}async _prepareResourcesCIM(e,t,r){const{OverrideHelper:i}=await import("../../../../symbols/cim/OverrideHelper.js");if(this._overrideHelperClass=i,this._cimData=t,!this._context.sharedResources.cimSymbolRasterizer){const e=(await import("../../../../symbols/cim/CIMSymbolRasterizer.js")).CIMSymbolRasterizer;l(r),this._context.sharedResources.cimSymbolRasterizer||(this._context.sharedResources.cimSymbolRasterizer=new e(this._context.renderCoordsHelper.spatialReference))}const s=this._context.sharedResources.cimSymbolRasterizer,o=[],a=t,n=a?.symbol;w.fetchResources(n,s.resourceManager,o,r),w.fetchFonts(n,s.resourceManager,o);const c=this._context.layer.fields?this._context.layer.fields.map((e=>e.toJSON())):[],h=this._context.renderCoordsHelper.spatialReference;if(this._arcadeInfo={spatialReference:h,fields:c,geometryType:"esriGeometryPoint"},a?.primitiveOverrides&&o.push(i.createRenderExpressions(a.primitiveOverrides,this._arcadeInfo)),o.length>0&&(await Promise.all(o),l(r)),this._context.renderer&&"dictionary"===this._context.renderer.type&&this._context.renderer.scaleExpression){const e=this._context.renderer;if(e.scaleExpression){const t=e.scaleExpression,r=await P(t,this._context.layer.spatialReference),{default:i}=await import("../../../2d/arcade/callExpressionWithFeature.js"),s=new S(c);this._cimScaleFactorOrFunction=(e,t,o)=>{const a=i(r,e,{$view:o},"esriGeometryPoint",s,t);return null!==a?a:1}}}l(r),this._cimMaterialParametersInfo=e,this._cimMaterialParametersInfo.color=this._getFillColor(),this._cimMaterialParametersInfo.outlineColor=[0,0,0,0],this._cimMaterialParametersInfo.outlineSize=0,this._cimMaterialParametersInfo.textureIsSignedDistanceField=!1}_getPrimitive(){return ye(this.symbolLayer)}_getOutlineSize(){let e=0;const t=this.symbolLayer;if(null!=t.outline?.size)return Math.max(c(t.outline.size),0);return e=de(this._getPrimitive())?ce:0,Math.max(e,0)}_getOutlineColor(){const t=this._getLayerOpacity(),r=this.symbolLayer,i=r?.outline?.color;if(null!=i){const r=e.toUnitRGB(i),s=i.a*t;return[r[0],r[1],r[2],s]}return[0,0,0,0]}_getFillColor(){if(de(this._getPrimitive()))return M;const e=null==this._getPrimitive(),t=this.symbolLayer?.material?.color;return this._getCombinedOpacityAndColor(t,{hasIntrinsicColor:e})}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;if(null==t){return null==this._getPrimitive()?y:g}return e.toUnitRGBA(t)}_getFallbackSize(){const e=this._getIconSize(),{symbolLayer:{size:t}}=this;return(null!=t?Math.round(c(t)):le)/e}_createMaterial(e){const t=this._context.spherical;if(this._cimData){this._fastUpdates=null;let r=e.textureId?this._cimSymbolMaterials.get(e.textureId):null;return r||(r=new ae(e,t),this._cimSymbolMaterials.set(e.textureId??0,r)),r}this._fastUpdates=q(this._context.renderer,this._fastVisualVariableConvertOptions()),this._fastUpdates&&(e={...e,...this._fastUpdates.materialParameters}),this._materials[0]=new ae(e,t),e.isFocused=!1;const r=this._context.stage.view.focusAreas.style;return e.color=I(e.color,r),e.outlineColor=I(e.outlineColor,r),this._materials[1]=new ae(e,t),this._materials[0]}_setDrapingDependentMaterialParameters(){this.draped&&(this._forEachMaterial((e=>{e.setParameters({verticalOffset:null,screenSizePerspective:null,occlusionTest:!1,hasSlicePlane:!1,shaderPolygonOffset:0,draped:this.draped})})),this.layerOpacityChanged())}destroy(){super.destroy(),this._patchTask=o(this._patchTask),this._materials.length=0,this._cimSymbolMaterials.clear(),this._cimSymbolTextures.forEach((e=>this._context.stage.remove(e))),this._cimSymbolTextures.clear(),this._textureHandle=a(this._textureHandle)}_getScaleFactor({size:e},t){if(!this._drivenProperties.size)return 1;if(null==e)return this._getFallbackSize();const[r,i,s]=e;return"symbol-value"===r?1:"number"==typeof r&&isFinite(r)?c(r)/t:"number"==typeof s&&isFinite(s)?c(s)/t:1}_getDrivenRotation(e){return this._drivenProperties.rotation?e.heading??0:0}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry))return null;let r,i=[0,0];const s=k(t.geometry);if(null==s)return this.logger.warn(`unsupported geometry type for text symbol: ${t.geometry.type}`),null;const o=this._context.stage.view.focusAreas.containsGeometry(s);if(this._cimData){if(!this._cimData.symbol)return null;const s=this._generateTextureCIM(t,e),a={textureId:s.id,isFocused:o,...this._cimMaterialParametersInfo};r=this._createMaterial(a);const n=this._context.graphicsCoreOwner.view.state.rasterPixelRatio;i=[s.parameters.width/n,s.parameters.height/n]}else i=this._size,r=o?this._materials[0]:this._materials[1];if(null==s)return this.logger.warn(`unsupported geometry type for icon symbol: ${t.geometry.type}`),null;const a=e.renderingInfo,n=this._getVertexOpacityAndColor(a,this._getFallbackOpacityAndColor()),l=this._getDrivenRotation(a);let c=1;if(!this._fastUpdates?.visualVariables.size){const e=i[0]>i[1]?i[0]:i[1];c=this._getScaleFactor(a,e)}c*=this._symbolTextureRatio;const h=d(i[0]*c,i[1]*c),u=this.setGraphicElevationContext(t);return this.ensureDrapedStatus("on-the-ground"===u.mode)&&this._setDrapingDependentMaterialParameters(),this.draped?this._createAsOverlay(t,s,r,n,l,h):this._createAs3DShape(t,s,r,n,l,h,u,t.uid)}layerOpacityChanged(){const e=this._getFillColor(),t=this._getOutlineColor();this._forEachMaterial((r=>{r.setParameters({color:e}),r.setParameters({outlineColor:t})}))}updateGeometry(e,t){if(this.draped||!this._validateGeometry(t))return!1;const{elevationContext:r,stageObject:i}=e;if(r.mode!==this.getGeometryElevationMode(t))return!1;const s=k(t);if(!s)return!1;const o=B(i,this._context,s,r);if(null==o)return!1;const a=N(this._context,s);return i.geometries[0].localOrigin===a&&(e.alignedSampledElevation=o,$(e,s,this._context.elevationProvider),!0)}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,s=T(ue.elevationModeChangeTypes,r,i);if(s!==F.UPDATE)return s;const o=U(i)||"absolute-height"===i;return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>o))}slicePlaneEnabledChanged(){return this.draped||this._forEachMaterial((e=>{e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled})})),!0}physicalBasedRenderingChanged(){return!0}get pixelRatioChanged(){return null!=this._getPrimitive()}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return V.RecreateSymbol;if(!J(this._fastUpdates,t,this._fastVisualVariableConvertOptions()))return V.RecreateSymbol;this._materials[0]?.setParameters(this._fastUpdates.materialParameters)}return V.FastUpdate}updateFocus(e,t){t.forEach((t=>{const r=k(t.graphic.geometry);if(null==r)return void this.logger.warn(`unsupported geometry type for text symbol: ${t.graphic.geometry.type}`);const i=this._context.stage.view.focusAreas.containsGeometry(r);t.layers.forEach((r=>{if(r?.graphics3DSymbolLayer===this){const s=r.stageObject.geometries.some((e=>e.material.parameters.isFocused!==i));s&&e(t)}}))}))}prepareSymbolLayerPatch(e){if(this._patchTask?.abort(),"partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchResource(e,t),this._preparePatchRotation(e,t)}_preparePatchResource(e,s){if(!s.resource||"partial"!==s.resource.type)return;const c=s.resource.diff;if("complete"!==c?.href?.type)return;const h=c.href.newValue,{textures:u}=this._context.sharedResources;if(null==h||null==u||null!=pe(h))return;const m=this._getIconSize(),d=m*this._context.graphicsCoreOwner.view.state.pixelRatio;e.symbolLayerStatePatches.push((()=>{this._patchTask=o(this._patchTask),this._patchTask=r((e=>this._context.schedule((async(e,r)=>{const s=await t(u.fromUrl(h,d,{signal:r}));l(r);const o=!s.ok;if(o&&n(s.error),this._textureHandle=a(this._textureHandle),this._patchTask=null,o){this._forEachMaterial((e=>{e.visible=!1,e.setParameters({textureId:null})}));const e=`Failed to load (Request for icon resource failed: ${h})`;return void this.logger.error(new i("graphics3diconsymbollayer:request-failed",e))}this._textureHandle=s.value;const c=s.value.texture;this._size=fe(c,m),this._forEachMaterial((e=>{e.setParameters({textureId:c.id}),e.visible=!0}))}),e)))})),delete c.href}_preparePatchRotation(e,t){if(!t.angle||"complete"!==t.angle.type)return;const r=t.angle.newValue??0,i=0!==r||this._drivenProperties.rotation;e.symbolLayerStatePatches.push((()=>{this._forEachMaterial((e=>e.setParameters({rotation:r,hasRotation:i})))})),delete t.angle}_defaultElevationInfoNoZ(){return xe}_createAs3DShape(e,t,r,i,s,o,a,n){const l=this.getFastUpdateAttrValues(e),c=this._context.layerViewUid,h=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:n,layerViewUid:c}),u=ie(r,{normal:ne,color:i,rotation:s,size:o,centerOffsetAndDistance:be,featureAttribute:l,objectAndLayerIdColor:h}),m=W(this._context,t,u,a,n);if(null==m)return null;const d=new A(this,m.object,null,E,a);return d.alignedSampledElevation=m.sampledElevation,d.needsElevationUpdates=U(a.mode)||"absolute-height"===a.mode,d.getScreenSize=this._createScreenSizeGetter(o,l),d.calculateRelativeScreenBounds=e=>r.calculateRelativeScreenBounds(d.getScreenSize(),1,e),$(d,t,this._context.elevationProvider),d}_createAsOverlay(e,t,r,i,s,o){r.renderPriority=this._renderPriority;const a=f();b(t,a,this._context.overlaySR),a[2]=re;const n=this._context.clippingExtent;if(null!=n&&!v(n,a))return null;const l=this.getFastUpdateAttrValues(e),c=e.uid,h=this._context.layerViewUid,u=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:c,layerViewUid:h}),m=ie(r,{normal:ne,position:a,color:i,rotation:s,size:o,featureAttribute:l,objectAndLayerIdColor:u}),d=new se(m,{layerViewUid:h,graphicUid:c}),p=new D(this,[d],null,this._context.drapeSourceRenderer);return p.getScreenSize=this._createScreenSizeGetter(o,l),p.calculateRelativeScreenBounds=e=>r.calculateRelativeScreenBounds(p.getScreenSize(),1,e),p}_createScreenSizeGetter(e,t){const r=this._outlineSize+2;if(this._fastUpdates&&t){const i=e[0]/this._symbolTextureRatio,s=e[1]/this._symbolTextureRatio;return(e=p())=>{const[o,a]=Z(ve,this._fastUpdates.materialParameters,t);return e[0]=o*i+r,e[1]=a*s+r,e}}const i=e[0]/this._symbolTextureRatio+r,s=e[1]/this._symbolTextureRatio+r;return(e=p())=>(e[0]=i,e[1]=s,e)}_fastVisualVariableConvertOptions(){const e=Math.max(this._size[0],this._size[1]),t=_(e,e,e),r=h(1),i=e*r,s=_(i,i,i),o=this._getFallbackSize();return new K({supports:{size:!0,color:!0,rotation:!0,opacity:!1},modelSize:t,symbolSize:s,unitInMeters:r,fallbackColor:this._getFallbackOpacityAndColor(),fallbackSize:_(o,o,o)})}_forEachMaterial(e){this._materials.forEach(e),this._cimSymbolMaterials.forEach(e)}test(){return{...super.test(),material:this._materials[0]}}}function me(e){return e&&"point-3d"===e.type&&e.hasVisibleVerticalOffset()}function de(e){return null!=e&&("cross"===e||"x"===e)}function pe(e){const t=m(e);return"application/json"===t?.mediaType?t.data:void 0}function _e(e,t){return"relative"===e?d((t.x||0)+.5,.5-(t.y||0)):e in H?H[e]:H.center}function fe({parameters:e},t){const r=(e.width??1)/(e.height??1);return r>1?[t,Math.round(t/r)]:[Math.round(t*r),t]}function ye(e){return e.resource?.href?null:e.resource?.primitive??C}function ge(e){return 1===(e.material?.color?.a??1)&&null!=ye(e)}const xe={mode:"relative-to-ground",offset:0},be=x(0,0,0,1),ve=f();export{ue as Graphics3DIconSymbolLayer};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../../Color.js";import has from"../../../../core/has.js";import{pt2px as t}from"../../../../core/screenUtils.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ZEROS as
|
|
5
|
+
import e from"../../../../Color.js";import has from"../../../../core/has.js";import{pt2px as t}from"../../../../core/screenUtils.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ZEROS as n,create as i}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{RenderingInfo as s}from"../../../../renderers/support/RenderingInfo.js";import{textSymbolLayerSupportsVerticalOffset as o}from"../../../../symbols/callouts/calloutUtils.js";import{perObjectElevationAligner as a}from"./ElevationAligners.js";import{SymbolUpdateType as l,elevationModeChangeUpdateType as c,needsElevationUpdates2D as m}from"./elevationAlignmentUtils.js";import{ElevationContext as h}from"./ElevationContext.js";import{Graphics3DGraphicCreationContext as p}from"./Graphics3DGraphicCreationContext.js";import{Graphics3DObject3DGraphicLayer as d}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DObjectMetadata as f}from"./Graphics3DObjectMetadata.js";import{Graphics3DSymbolLayer as u}from"./Graphics3DSymbolLayer.js";import{computeCentroid as g}from"./graphicUtils.js";import{createStageObject as y,extendPointGraphicElevationContext as v}from"./pointUtils.js";import{SymbolComplexity as b}from"./SymbolComplexity.js";import{Attribute as x}from"../../webgl-engine/lib/Attribute.js";import{Geometry as O}from"../../webgl-engine/lib/Geometry.js";import{VertexAttribute as C}from"../../webgl-engine/lib/VertexAttribute.js";import{LineCalloutMaterial as _,Parameters as j,uniqueMaterialIdentifier as E}from"../../webgl-engine/materials/LineCalloutMaterial.js";import{GeometryType as P}from"../../webgl-engine/lib/IntersectableGeometry.js";class w extends u{static{this.elevationModeChangeTypes={definedChanged:l.UPDATE,staysOnTheGround:l.UPDATE,onTheGroundChanged:l.RECREATE}}constructor(e,t){super(e,null,t,A),this._elevationOptions={supportsOffsetAdjustment:!0,supportsOnTheGround:!1},this.ensureDrapedStatus(!1)}async doLoad(){this._materials[0]=new _(this._materialParameters,this._context.spherical)}_perInstanceMaterialParameters(e){const t=this._materialParameters;return t.horizontalScreenOffset=e.horizontalScreenOffset??0,t.centerOffsetUnits=e.centerOffsetUnits||"world",t}get _materialParameters(){const r=new j,i=this.symbol,s=i.callout;if(s.color){const t=e.toUnitRGBA(s.color);t[3]*=this._getLayerOpacity(),r.color=t}else r.color=n;if(r.size=t(s.size||0),i.verticalOffset){const{screenLength:e,minWorldLength:n,maxWorldLength:s}=i.verticalOffset;r.verticalOffset={screenLength:t(e),minWorldLength:n||0,maxWorldLength:null!=s?s:1/0}}r.borderColor=null!=s.border?.color?e.toUnitRGBA(s.border.color):null;const o="object"===i.symbolLayers.at(0).type,a="label-3d"===i.type;return r.occlusionTest=!o&&!!has("disable-feature:non-occluded-hud"),o&&(r.shaderPolygonOffset=0),r.hudDepthAlignStart=a,r.hasSlicePlane=this._context.slicePlaneEnabled,r.screenSizePerspective=this._context.screenSizePerspectiveEnabled?this._context.sharedResources.screenSizePerspectiveSettings:null,r}_defaultElevationInfoNoZ(){return U}createGraphics3DGraphic(e,t){const r=e.renderingInfo,n=e.graphic,i=this.setGraphicElevationContext(n,new h,r.elevationOffset||0),s=r.symbol,a="on-the-ground"===this._elevationContext.mode&&("cim"===s.type||!s.symbolLayers.some((e=>"object"===e.type||"text"===e.type)));if("label-3d"!==s.type&&a)return null;if("point-3d"===s.type&&s.symbolLayers.every((e=>"text"===e.type&&!o(e))))return null;const l=g(n.geometry);return null==l?null:this._createAs3DShape(l,i,r,n.uid,t)}layerOpacityChanged(){this._materials[0]?.setParameters(this._materialParameters)}layerElevationInfoChanged(e,t,r){const n=this._elevationContext.mode,i=c(w.elevationModeChangeTypes,r,n);return i!==l.UPDATE||e.forEach((e=>{const r=t(e);null!=r&&this.updateGraphicElevationContext(e.graphic,r)})),i}slicePlaneEnabledChanged(){return this._materials[0]?.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),!0}physicalBasedRenderingChanged(){return!0}setGraphicElevationContext(e,t,r=0){return super.setGraphicElevationContext(e,t),t.addOffsetRenderUnits(r),t}updateGraphicElevationContext(e,t){const{elevationContext:r,metadata:n}=t;this.setGraphicElevationContext(e,r,n?.elevationOffset??0),t.needsElevationUpdates=m(r.mode)}computeComplexity(){return new b({verticesPerFeature:6})}_getOrCreateMaterial(e,t){const r=this._perInstanceMaterialParameters(e),n=E(r);if(n===this._materials[0]?.uniqueMaterialIdentifier)return this._materials[0];if(t){let e=t.get(n);return null==e&&(e=new _(r,this._context.spherical),t.set(n,e)),e}return new _(r,this._context.spherical)}_createAs3DShape(e,t,r,n,i){const s=this._context.layerViewUid,o=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:n,layerViewUid:s}),l=this._getOrCreateMaterial(r,i),c=new O(l,G(r),null,P.Point,o),h=y(this._context,e,c,t,n);if(null==h)return null;const p=new d(this,h.object,null,a,t);return p.metadata=new f(r.elevationOffset),p.alignedSampledElevation=h.sampledElevation,p.needsElevationUpdates=m(t.mode),v(p,e,this._context.elevationProvider),p}}function G(e){const{translation:t,centerOffset:r}=e,n=new x(t?[t[0],t[1],t[2]]:[0,0,0],S,3,!0),i=new x(r?[r[0],r[1],r[2],r[3]]:[0,0,0,1],S,4,!0);return[[C.POSITION,n],[C.NORMAL,new x([0,0,1],S,3,!0)],[C.CENTEROFFSETANDDISTANCE,i]]}const S=[0],U={mode:"relative-to-ground",offset:0},A={ignoreDrivers:!0,renderPriority:0,renderPriorityStep:1};class D extends s{constructor(e,t,n=r(),s=i(),o=0,a="world",l=0){super(e,t),this.translation=n,this.centerOffset=s,this.horizontalScreenOffset=o,this.centerOffsetUnits=a,this.elevationOffset=l}}class L extends p{}export{w as Graphics3DLineCalloutSymbolLayer,L as LineCalloutCreationContext,D as LineCalloutSymbolLayerRenderingInfo};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../../Color.js";import t from"../../../../core/Error.js";import{px2pt as r,pt2px as i}from"../../../../core/screenUtils.js";import{fromValues as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as s}from"../../../../chunks/vec42.js";import{fromValues as o,clone as n,ZEROS as l,ones as c}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import p from"../../../../geometry/Extent.js";import m from"../../../../geometry/Polygon.js";import{create as h,fromBuffer as y,intersectsClippingArea as d,empty as f,expandWithAABB as u,expandWithBuffer as _}from"../../../../geometry/support/aaBoundingBox.js";import{getDriverAxisSizeValueAny as g}from"../../../../renderers/support/renderingInfoUtils.js";import{sharedGeometryElevationAligner as b}from"./ElevationAligners.js";import{SymbolUpdateType as M,elevationModeChangeUpdateType as L,needsElevationUpdates2D as v}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as k}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as C}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as P}from"./Graphics3DSymbolLayer.js";import{ApplyRendererDiffResult as E}from"./interfaces.js";import{parseCapType as w,parseLineMarkerStyle as R}from"./lineUtils.js";import{initFastSymbolUpdatesState as x,updateFastSymbolUpdatesState as A,getAttributeValue as D,ConvertOptions as V}from"../support/FastSymbolUpdates.js";import{debugFlags as O}from"../../support/debugFlags.js";import{createGeometry as S}from"../../support/engineContent/line.js";import{geometryToRenderInfo as U,geometryToRenderInfoDraped as j}from"../../support/renderInfoUtils/line.js";import{Object3D as z}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as F}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as G}from"../../webgl-engine/lib/VertexAttribute.js";import{LineMarkerMaterial as W}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{getStipplePatternForLinePattern as I}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as T}from"../../webgl-engine/materials/RibbonLineMaterial.js";const H=["polyline","polygon","extent"];class B extends P{static{this.elevationModeChangeTypes={definedChanged:M.RECREATE,staysOnTheGround:M.NONE,onTheGroundChanged:M.RECREATE}}constructor(e,t,r,i){super(e,t,r,i,J(t))}async doLoad(){this._fastUpdates=x(this._context.renderer,this._fastVisualVariableConvertOptions());const e=!0;if(this._fastMarkerUpdates=x(this._context.renderer,this._fastVisualVariableConvertOptions(e)),!this._drivenProperties.size){if((null!=this.symbolLayer.size?this.symbolLayer.size:r(1))<0)throw new t("graphics3dlinesymbollayer:invalid-size","Symbol sizes may not be negative values")}}_getMaterialParameters(e,t=!1){const r=this._getCombinedOpacityAndColor(t&&this._markerColor||this._materialColor);this._patternHidesLine&&!t&&(r[3]=0);const i={width:this._computeMaterialWidth(this.symbolLayer?.size),color:r,hasPolygonOffset:!0,join:this.symbolLayer.join||"miter",cap:w(this.symbolLayer.cap||"butt"),hasSlicePlane:this._context.slicePlaneEnabled,isClosed:e,stipplePattern:I(this.symbolLayer.pattern)};return t&&this._fastMarkerUpdates?.visualVariables?{...i,...this._fastMarkerUpdates.materialParameters}:this._fastUpdates?.visualVariables?{...i,...this._fastUpdates.materialParameters}:i}get _materialColor(){return this.symbolLayer.material?.color}get _markerColor(){return this.symbolLayer.marker?.color}get _lineMaterial(){return null==this._materials[Q.Line]&&(this._materials[Q.Line]=new T(this._getMaterialParameters(!1)),this._context.stage.add(this._materials[Q.Line])),this._materials[Q.Line]}get _ringMaterial(){return null==this._materials[Q.Ring]&&(this._materials[Q.Ring]=new T(this._getMaterialParameters(!0)),this._context.stage.add(this._materials[Q.Ring])),this._materials[Q.Ring]}get _wireframeLineMaterial(){return null==this._materials[Q.LineWireframe]&&(this._materials[Q.LineWireframe]=new T({...this._getMaterialParameters(!1),wireframe:!0}),this._context.stage.add(this._materials[Q.LineWireframe])),this._materials[Q.LineWireframe]}get _wireframeRingMaterial(){return null==this._materials[Q.RingWireframe]&&(this._materials[Q.RingWireframe]=new T({...this._getMaterialParameters(!0),wireframe:!0}),this._context.stage.add(this._materials[Q.RingWireframe])),this._materials[Q.RingWireframe]}get _markerMaterial(){return null==this._materials[Q.Marker]&&null!=this.symbolLayer.marker&&(this._materials[Q.Marker]=new W({...this._getMaterialParameters(!1,!0),placement:this.symbolLayer.marker.placement,markerPrimitive:R(this.symbolLayer.marker.style)}),this._context.stage.add(this._materials[Q.Marker])),this._materials[Q.Marker]}destroy(){super.destroy();for(const e of this._validMaterials())this._context.stage.remove(e);this._materials.length=0}_getDrivenSize(e){if(this._drivenProperties.size){const t=e.size;return null!=t?i(g(t)):this._getFallbackSize()}return 1}_getDrivenColor({color:e,opacity:t}){const r=o(1,1,1,1);return this._drivenProperties.color&&s(r,e??this._getFallbackOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackOpacity()),r}_getDrivenMarkerColor({color:e,opacity:t}){const r=c();return this._drivenProperties.color&&s(r,e??this._getFallbackMarkerOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackMarkerOpacity()),r}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,H,this.symbolLayer.type))return null;const r=this.setGraphicElevationContext(t);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.draped?this._createAsOverlay(e):this._createAs3DShape(e,r,t.uid)}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return E.RecreateSymbol;{const e=this._fastUpdates;if(!A(e,t,this._fastVisualVariableConvertOptions()))return E.RecreateSymbol;for(const t of this._validMaterials())t instanceof T&&t.setParameters(e.materialParameters);const r=this._fastMarkerUpdates,i=!0;if(!A(r,t,this._fastVisualVariableConvertOptions(i)))return E.RecreateSymbol;for(const t of this._validMaterials())t instanceof W&&t.setParameters(r.materialParameters)}}return E.FastUpdate}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=w(t.cap.newValue??"butt"),delete t.cap);const i=this._prepareMarkerPatch(e,t);this._prepareMaterialPatch(e,t,i),e.symbolLayerStatePatches.push((()=>{for(const e of this._validMaterials())e.setParameters(r)}))}layerOpacityChanged(){for(const e of this._validMaterials())this._updateMaterialLayerOpacity(e,e instanceof W)}_updateMaterialLayerOpacity(e,t=!1){if(null==e)return;const r=e.parameters.color,i=this.symbolLayer?.material?.color,a=this._patternHidesLine&&!t?0:this._getCombinedOpacity(i),s=o(r[0],r[1],r[2],a);e.setParameters({color:s})}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,a=L(B.elevationModeChangeTypes,r,i);if(a!==M.UPDATE)return a;const s=v(i);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>s))}slicePlaneEnabledChanged(){const e={hasSlicePlane:this._context.slicePlaneEnabled};for(const t of this._validMaterials())t.setParameters(e);return!0}physicalBasedRenderingChanged(){return!0}_createAs3DShape(e,t,r){const i=N(e.graphic.geometry),a="polygon"===i.type?i.rings:i.paths,s=new Array,o=h(),n=U(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),l="polygon"===i.type?"rings":"paths";this._logGeometryCreationWarnings(n,a,l,"LineSymbol3DLayer");for(let h=0;h<n.lines.length;h++){const t=n.lines[h],a=t.position,l=t.mapPositions;if(null!=this._context.clippingExtent&&(y(l,o),!d(o,this._context.clippingExtent)))continue;const c=this._createGeometry("polygon"===i.type?this._ringMaterial:this._lineMaterial,e,a,l,i.type,K.ELEVATED,r);if(s.push(c),O.LINE_WIREFRAMES&&s.push(c.instantiate({material:"polygon"===i.type?this._wireframeRingMaterial:this._wireframeLineMaterial})),null!=this._markerMaterial){const t=c.instantiate({material:this._markerMaterial});t.setAttributeData(G.COLOR,this._getDrivenMarkerColor(e.renderingInfo)),s.push(t)}}if(0===s.length)return null;const c=this._context.layerViewUid,p=new z({geometries:s,castShadow:!1,layerViewUid:c,graphicUid:r}),m=new C(this,p,s,null,null,b,t);return m.alignedSampledElevation=n.sampledElevation,m.needsElevationUpdates=v(t.mode),m}_createGeometry(e,t,r,i,a,s,o){const n=s===K.DRAPED?{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper}:null,l="polygon"===a,c=this._fastUpdates?.visualVariables.color,p=this._fastUpdates?.visualVariables.size,m=this._fastUpdates?.visualVariables.opacity,h=this._context.layerViewUid,y=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:o,layerViewUid:h}),d={position:r,size:p?null:this._getDrivenSize(t.renderingInfo),color:c?null:this._getDrivenColor(t.renderingInfo),sizeFeature:p?D(p.field,t.graphic):null,colorFeature:c?D(c.field,t.graphic):null,opacityFeature:m?D(m.field,t.graphic):null};return S(e,{overlayInfo:n,removeDuplicateStartEnd:l,mapPositions:i,attributeData:d},y)}_createAsOverlay(e){const t=e.graphic,r=N(t.geometry),i="polygon"===r.type?r.rings:r.paths,a="polygon"===r.type?this._ringMaterial:this._lineMaterial;a.renderPriority=this._renderPriority;const s=O.LINE_WIREFRAMES?"polygon"===r.type?this._wireframeRingMaterial:this._wireframeLineMaterial:null,o=this._markerMaterial;null!=s&&(s.renderPriority=this._renderPriority-.001),null!=o&&(o.renderPriority=this._renderPriority-.002);const n=new Array,l=h(),c=f(),p=j(r,this._context.overlaySR),m="polygon"===r.type?"rings":"paths";this._logGeometryCreationWarnings(p,i,m,"LineSymbol3DLayer");for(const h of p.lines){if(y(h.position,l),!d(l,this._context.clippingExtent))continue;u(c,l);const i=i=>{const a=this._createGeometry(i,e,h.position,void 0,r.type,K.DRAPED,t.uid),s=this._context.layerViewUid,o=new F(a,{layerViewUid:s,graphicUid:t.uid});n.push(o)};if(null!=o){i(o);const e=this.symbolLayer.marker.placement;"begin"!==e&&"begin-end"!==e||_(l,h.position,0,1),"end"!==e&&"begin-end"!==e||_(l,h.position,h.position.length-3,1)}i(a),O.LINE_WIREFRAMES&&i(s)}return new k(this,n,c,this._context.drapeSourceRenderer)}get _patternHidesLine(){const e=this.symbolLayer.pattern;return null!=e&&"style"===e.type&&"none"===e.style}_computeMaterialWidth(e){return e=e??r(1),this._drivenProperties.size?this._fastUpdates?.visualVariables.size?i(1):1:i(e)}_prepareMaterialPatch(e,t,r){const i=t.material;if(null==i)return void(r.changed&&r.useMaterialColor&&q(this._getCombinedOpacityAndColor(this._materialColor),this._materials[Q.Marker],e));if("collection"===i.type)return;const a="complete"===i.type?i.newValue?.color:"complete"===i.diff.color?.type?i.diff.color.newValue:null,s=this._getCombinedOpacityAndColor(a);r.useMaterialColor&&q(n(s),this._materials[Q.Marker],e),this._patternHidesLine&&(s[3]=0),q(s,this._materials[Q.Line],e),delete t.material}_prepareMarkerPatch(e,t){const r=t.marker,i=this._markerMaterial;if(null==r||"partial"!==r.type||null==r.diff||null!=r.diff.placement||null!=r.diff.style&&"complete"!==r.diff.style.type||null!=r.diff.color&&"complete"!==r.diff.color.type||null==i)return{changed:!1,useMaterialColor:null==this._markerColor};const a=r.diff.color,s=null!=a,o=s?a.newValue:null,n=null==o&&null==this._markerColor;o&&q(this._getCombinedOpacityAndColor(o),i,e);const l=r.diff.style?.newValue;return l&&e.symbolLayerStatePatches.push((()=>i.setParameters({markerPrimitive:R(l)}))),delete t.marker,{changed:s,useMaterialColor:n}}_fastVisualVariableConvertOptions(e=!1){const t=this._getFallbackSize();return new V({supports:{size:!0,color:!0,rotation:!1,opacity:!0},fallbackColor:e?this._getFallbackMarkerOpacityAndColor():this._getFallbackOpacityAndColor(),fallbackSize:a(t,t,t)})}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;return e.toUnitRGBA(t)??l}_getFallbackOpacity(){return this.symbolLayer?.material?.color?.a??0}_getFallbackMarkerOpacityAndColor(){const t=this.symbolLayer?.marker?.color;return e.toUnitRGBA(t)??l}_getFallbackMarkerOpacity(){return this.symbolLayer?.marker?.color?.a??0}_getFallbackSize(){const e=this.symbolLayer?.size;return null!=e?i(e):1}}function N(e){switch(e.type){case"extent":if(e instanceof p)return m.fromExtent(e);break;case"polygon":case"polyline":return e}return null}function q(e,t,r){null!=t&&r.symbolLayerStatePatches.push((()=>t.setParameters({color:e})))}function J(e){return 1===(e.material?.color?.a??1)&&1===(e.marker?.color?.a??1)}var K,Q;!function(e){e[e.DRAPED=0]="DRAPED",e[e.ELEVATED=1]="ELEVATED"}(K||(K={})),function(e){e[e.Line=0]="Line",e[e.Ring=1]="Ring",e[e.LineWireframe=2]="LineWireframe",e[e.RingWireframe=3]="RingWireframe",e[e.Marker=4]="Marker"}(Q||(Q={}));export{B as Graphics3DLineSymbolLayer};
|
|
5
|
+
import e from"../../../../Color.js";import t from"../../../../core/Error.js";import{px2pt as r,pt2px as i}from"../../../../core/screenUtils.js";import{fromValues as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as s}from"../../../../chunks/vec42.js";import{fromValues as o,clone as n,ZEROS as l,ones as c}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import p from"../../../../geometry/Extent.js";import m from"../../../../geometry/Polygon.js";import{create as h,fromBuffer as y,intersectsClippingArea as u,empty as d,expandWithAABB as f,expandWithBuffer as _}from"../../../../geometry/support/aaBoundingBox.js";import{getDriverAxisSizeValueAny as g}from"../../../../renderers/support/renderingInfoUtils.js";import{sharedGeometryElevationAligner as b}from"./ElevationAligners.js";import{SymbolUpdateType as L,elevationModeChangeUpdateType as M,needsElevationUpdates2D as k}from"./elevationAlignmentUtils.js";import{Graphics3DDrapedGraphicLayer as C}from"./Graphics3DDrapedGraphicLayer.js";import{Graphics3DObject3DGraphicLayer as v}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as P}from"./Graphics3DSymbolLayer.js";import{ApplyRendererDiffResult as E}from"./interfaces.js";import{parseCapType as w,parseLineMarkerStyle as R}from"./lineUtils.js";import{initFastSymbolUpdatesState as A,updateFastSymbolUpdatesState as D,getAttributeValue as V,ConvertOptions as O}from"../support/FastSymbolUpdates.js";import{debugFlags as S}from"../../support/debugFlags.js";import{createGeometry as U}from"../../support/engineContent/line.js";import{geometryToRenderInfo as j,geometryToRenderInfoDraped as x}from"../../support/renderInfoUtils/line.js";import{Object3D as z}from"../../webgl-engine/lib/Object3D.js";import{RenderGeometry as F}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as G}from"../../webgl-engine/lib/VertexAttribute.js";import{LineMarkerMaterial as W}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{getStipplePatternForLinePattern as I}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as T}from"../../webgl-engine/materials/RibbonLineMaterial.js";const H=["polyline","polygon","extent"];class B extends P{static{this.elevationModeChangeTypes={definedChanged:L.RECREATE,staysOnTheGround:L.NONE,onTheGroundChanged:L.RECREATE}}constructor(e,t,r,i){super(e,t,r,i,J(t))}async doLoad(){this._fastUpdates=A(this._context.renderer,this._fastVisualVariableConvertOptions());const e=!0;if(this._fastMarkerUpdates=A(this._context.renderer,this._fastVisualVariableConvertOptions(e)),!this._drivenProperties.size){if((null!=this.symbolLayer.size?this.symbolLayer.size:r(1))<0)throw new t("graphics3dlinesymbollayer:invalid-size","Symbol sizes may not be negative values")}}_getMaterialParameters(e,t=!1){const r=this._getCombinedOpacityAndColor(t&&this._markerColor||this._materialColor);this._patternHidesLine&&!t&&(r[3]=0);const i={width:this._computeMaterialWidth(this.symbolLayer?.size),color:r,hasPolygonOffset:!0,join:this.symbolLayer.join||"miter",cap:w(this.symbolLayer.cap||"butt"),hasSlicePlane:this._context.slicePlaneEnabled,isClosed:e,stipplePattern:I(this.symbolLayer.pattern)};return t&&this._fastMarkerUpdates?.visualVariables?{...i,...this._fastMarkerUpdates.materialParameters}:this._fastUpdates?.visualVariables?{...i,...this._fastUpdates.materialParameters}:i}get _materialColor(){return this.symbolLayer.material?.color}get _markerColor(){return this.symbolLayer.marker?.color}get _lineMaterial(){return null==this._materials[Q.Line]&&(this._materials[Q.Line]=new T(this._getMaterialParameters(!1))),this._materials[Q.Line]}get _ringMaterial(){return null==this._materials[Q.Ring]&&(this._materials[Q.Ring]=new T(this._getMaterialParameters(!0))),this._materials[Q.Ring]}get _wireframeLineMaterial(){return null==this._materials[Q.LineWireframe]&&(this._materials[Q.LineWireframe]=new T({...this._getMaterialParameters(!1),wireframe:!0})),this._materials[Q.LineWireframe]}get _wireframeRingMaterial(){return null==this._materials[Q.RingWireframe]&&(this._materials[Q.RingWireframe]=new T({...this._getMaterialParameters(!0),wireframe:!0})),this._materials[Q.RingWireframe]}get _markerMaterial(){return null==this._materials[Q.Marker]&&null!=this.symbolLayer.marker&&(this._materials[Q.Marker]=new W({...this._getMaterialParameters(!1,!0),placement:this.symbolLayer.marker.placement,markerPrimitive:R(this.symbolLayer.marker.style)})),this._materials[Q.Marker]}_getDrivenSize(e){if(this._drivenProperties.size){const t=e.size;return null!=t?i(g(t)):this._getFallbackSize()}return 1}_getDrivenColor({color:e,opacity:t}){const r=o(1,1,1,1);return this._drivenProperties.color&&s(r,e??this._getFallbackOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackOpacity()),r}_getDrivenMarkerColor({color:e,opacity:t}){const r=c();return this._drivenProperties.color&&s(r,e??this._getFallbackMarkerOpacityAndColor()),this._drivenProperties.opacity&&(r[3]=t??this._getFallbackMarkerOpacity()),r}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,H,this.symbolLayer.type))return null;const r=this.setGraphicElevationContext(t);return this.ensureDrapedStatus("on-the-ground"===r.mode),this.draped?this._createAsOverlay(e):this._createAs3DShape(e,r,t.uid)}applyRendererDiff(e,t){for(const r in e.diff){if("visualVariables"!==r)return E.RecreateSymbol;{const e=this._fastUpdates;if(!D(e,t,this._fastVisualVariableConvertOptions()))return E.RecreateSymbol;for(const t of this._materials)t instanceof T&&t.setParameters(e.materialParameters);const r=this._fastMarkerUpdates,i=!0;if(!D(r,t,this._fastVisualVariableConvertOptions(i)))return E.RecreateSymbol;for(const t of this._materials)t instanceof W&&t.setParameters(r.materialParameters)}}return E.FastUpdate}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=w(t.cap.newValue??"butt"),delete t.cap);const i=this._prepareMarkerPatch(e,t);this._prepareMaterialPatch(e,t,i),e.symbolLayerStatePatches.push((()=>{for(const e of this._materials)e?.setParameters(r)}))}layerOpacityChanged(){for(const e of this._materials)this._updateMaterialLayerOpacity(e,e instanceof W)}_updateMaterialLayerOpacity(e,t=!1){if(null==e)return;const r=e.parameters.color,i=this.symbolLayer?.material?.color,a=this._patternHidesLine&&!t?0:this._getCombinedOpacity(i),s=o(r[0],r[1],r[2],a);e.setParameters({color:s})}layerElevationInfoChanged(e,t,r){const i=this._elevationContext.mode,a=M(B.elevationModeChangeTypes,r,i);if(a!==L.UPDATE)return a;const s=k(i);return this.updateGraphics3DGraphicElevationInfo(e,t,(()=>s))}slicePlaneEnabledChanged(){const e={hasSlicePlane:this._context.slicePlaneEnabled};for(const t of this._materials)t?.setParameters(e);return!0}physicalBasedRenderingChanged(){return!0}_createAs3DShape(e,t,r){const i=N(e.graphic.geometry),a="polygon"===i.type?i.rings:i.paths,s=new Array,o=h(),n=j(i,this._context.elevationProvider,this._context.renderCoordsHelper,t),l="polygon"===i.type?"rings":"paths";this._logGeometryCreationWarnings(n,a,l,"LineSymbol3DLayer");for(let h=0;h<n.lines.length;h++){const t=n.lines[h],a=t.position,l=t.mapPositions;if(null!=this._context.clippingExtent&&(y(l,o),!u(o,this._context.clippingExtent)))continue;const c=this._createGeometry("polygon"===i.type?this._ringMaterial:this._lineMaterial,e,a,l,i.type,K.ELEVATED,r);if(s.push(c),S.LINE_WIREFRAMES&&s.push(c.instantiate({material:"polygon"===i.type?this._wireframeRingMaterial:this._wireframeLineMaterial})),null!=this._markerMaterial){const t=c.instantiate({material:this._markerMaterial});t.setAttributeData(G.COLOR,this._getDrivenMarkerColor(e.renderingInfo)),s.push(t)}}if(0===s.length)return null;const c=this._context.layerViewUid,p=new z({geometries:s,castShadow:!1,layerViewUid:c,graphicUid:r}),m=new v(this,p,null,b,t);return m.alignedSampledElevation=n.sampledElevation,m.needsElevationUpdates=k(t.mode),m}_createGeometry(e,t,r,i,a,s,o){const n=s===K.DRAPED?{spatialReference:this._context.overlaySR,renderCoordsHelper:this._context.renderCoordsHelper}:null,l="polygon"===a,c=this._fastUpdates?.visualVariables.color,p=this._fastUpdates?.visualVariables.size,m=this._fastUpdates?.visualVariables.opacity,h=this._context.layerViewUid,y=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:o,layerViewUid:h}),u={position:r,size:p?null:this._getDrivenSize(t.renderingInfo),color:c?null:this._getDrivenColor(t.renderingInfo),sizeFeature:p?V(p.field,t.graphic):null,colorFeature:c?V(c.field,t.graphic):null,opacityFeature:m?V(m.field,t.graphic):null};return U(e,{overlayInfo:n,removeDuplicateStartEnd:l,mapPositions:i,attributeData:u},y)}_createAsOverlay(e){const t=e.graphic,r=N(t.geometry),i="polygon"===r.type?r.rings:r.paths,a="polygon"===r.type?this._ringMaterial:this._lineMaterial;a.renderPriority=this._renderPriority;const s=S.LINE_WIREFRAMES?"polygon"===r.type?this._wireframeRingMaterial:this._wireframeLineMaterial:null,o=this._markerMaterial;null!=s&&(s.renderPriority=this._renderPriority-.001),null!=o&&(o.renderPriority=this._renderPriority-.002);const n=new Array,l=h(),c=d(),p=x(r,this._context.overlaySR),m="polygon"===r.type?"rings":"paths";this._logGeometryCreationWarnings(p,i,m,"LineSymbol3DLayer");for(const h of p.lines){if(y(h.position,l),!u(l,this._context.clippingExtent))continue;f(c,l);const i=i=>{const a=this._createGeometry(i,e,h.position,void 0,r.type,K.DRAPED,t.uid),s=this._context.layerViewUid,o=new F(a,{layerViewUid:s,graphicUid:t.uid});n.push(o)};if(null!=o){i(o);const e=this.symbolLayer.marker.placement;"begin"!==e&&"begin-end"!==e||_(l,h.position,0,1),"end"!==e&&"begin-end"!==e||_(l,h.position,h.position.length-3,1)}i(a),S.LINE_WIREFRAMES&&i(s)}return new C(this,n,c,this._context.drapeSourceRenderer)}get _patternHidesLine(){const e=this.symbolLayer.pattern;return null!=e&&"style"===e.type&&"none"===e.style}_computeMaterialWidth(e){return e=e??r(1),this._drivenProperties.size?this._fastUpdates?.visualVariables.size?i(1):1:i(e)}_prepareMaterialPatch(e,t,r){const i=t.material;if(null==i)return void(r.changed&&r.useMaterialColor&&q(this._getCombinedOpacityAndColor(this._materialColor),this._materials[Q.Marker],e));if("collection"===i.type)return;const a="complete"===i.type?i.newValue?.color:"complete"===i.diff.color?.type?i.diff.color.newValue:null,s=this._getCombinedOpacityAndColor(a);r.useMaterialColor&&q(n(s),this._materials[Q.Marker],e),this._patternHidesLine&&(s[3]=0),q(s,this._materials[Q.Line],e),delete t.material}_prepareMarkerPatch(e,t){const r=t.marker,i=this._markerMaterial;if(null==r||"partial"!==r.type||null==r.diff||null!=r.diff.placement||null!=r.diff.style&&"complete"!==r.diff.style.type||null!=r.diff.color&&"complete"!==r.diff.color.type||null==i)return{changed:!1,useMaterialColor:null==this._markerColor};const a=r.diff.color,s=null!=a,o=s?a.newValue:null,n=null==o&&null==this._markerColor;o&&q(this._getCombinedOpacityAndColor(o),i,e);const l=r.diff.style?.newValue;return l&&e.symbolLayerStatePatches.push((()=>i.setParameters({markerPrimitive:R(l)}))),delete t.marker,{changed:s,useMaterialColor:n}}_fastVisualVariableConvertOptions(e=!1){const t=this._getFallbackSize();return new O({supports:{size:!0,color:!0,rotation:!1,opacity:!0},fallbackColor:e?this._getFallbackMarkerOpacityAndColor():this._getFallbackOpacityAndColor(),fallbackSize:a(t,t,t)})}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;return e.toUnitRGBA(t)??l}_getFallbackOpacity(){return this.symbolLayer?.material?.color?.a??0}_getFallbackMarkerOpacityAndColor(){const t=this.symbolLayer?.marker?.color;return e.toUnitRGBA(t)??l}_getFallbackMarkerOpacity(){return this.symbolLayer?.marker?.color?.a??0}_getFallbackSize(){const e=this.symbolLayer?.size;return null!=e?i(e):1}}function N(e){switch(e.type){case"extent":if(e instanceof p)return m.fromExtent(e);break;case"polygon":case"polyline":return e}return null}function q(e,t,r){null!=t&&r.symbolLayerStatePatches.push((()=>t.setParameters({color:e})))}function J(e){return 1===(e.material?.color?.a??1)&&1===(e.marker?.color?.a??1)}var K,Q;!function(e){e[e.DRAPED=0]="DRAPED",e[e.ELEVATED=1]="ELEVATED"}(K||(K={})),function(e){e[e.Line=0]="Line",e[e.Ring=1]="Ring",e[e.LineWireframe=2]="LineWireframe",e[e.RingWireframe=3]="RingWireframe",e[e.Marker=4]="Marker"}(Q||(Q={}));export{B as Graphics3DLineSymbolLayer};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../../Color.js";import"../../../../core/has.js";import{deg2rad as t}from"../../../../core/mathUtils.js";import{releaseMaybe as r}from"../../../../core/maybe.js";import{isPromiseLike as o}from"../../../../core/promiseUtils.js";import{normalFromMat4 as a,fromMat4 as n}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{fromTranslation as i,multiply as l,invert as c,getTranslation as u}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as m,IDENTITY as f,clone as p}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{ONES as h}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{i as d,g,h as x,t as _,q as y,n as b,b as T,f as v,d as w,e as M}from"../../../../chunks/vec32.js";import{ZEROS as C,ONES as R,create as j}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as A,ZEROS as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{canProjectWithoutEngine as O}from"../../../../geometry/projection.js";import{computeTranslationToOriginAndRotation as E}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectBuffer as N}from"../../../../geometry/projection/projectBuffer.js";import{projectVectorToPoint as I}from"../../../../geometry/projection/projectVectorToPoint.js";import{create as S,fromBuffer as U,intersectsClippingArea as B}from"../../../../geometry/support/aaBoundingBox.js";import{newFloatArray as F}from"../../../../geometry/support/FloatArray.js";import{getZeroIndexArray as V,getContinuousIndexArray as L}from"../../../../geometry/support/Indices.js";import D from"../../../../geometry/support/MeshComponent.js";import G from"../../../../geometry/support/MeshMaterialMetallicRoughness.js";import $ from"../../../../geometry/support/MeshTextureTransform.js";import{isRelativeVertexSpace as H,isAbsoluteVertexSpace as k}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{equals as q,isPlateCarree as z}from"../../../../geometry/support/spatialReferenceUtils.js";import{t as W}from"../../../../chunks/vec3.js";import{transformNormal as Y,transformVectorENUPlateCarree as Z,VectorType as J,transformVectorWMPlateCarree as K,projectNormalToPCPF as Q,transformTangent as X,projectTangentToPCPF as ee}from"../../../../geometry/support/meshUtils/projection.js";import{projectMeshVertexPositions as te}from"../../../../geometry/support/meshUtils/projectMeshVertexPositions.js";import{makeDehydratedPoint as re}from"../../../../layers/graphics/dehydratedPoint.js";import{MeshTransformUpdateAction as oe}from"../../../../layers/graphics/sources/interfaces.js";import{getEmissiveMode as ae}from"../../../../symbols/support/materialUtils.js";import{ViewingMode as ne}from"../../../ViewingMode.js";import{isEncodedMeshTexture as se}from"../../glTF/internal/resourceUtils.js";import{getTransformMatrix as ie}from"../../glTF/internal/TextureTransformUtils.js";import{defaultSymbolLayerMemoryComplexity as le}from"./defaultSymbolComplexity.js";import{perObjectElevationAligner as ce}from"./ElevationAligners.js";import{needsElevationUpdates3D as ue,evaluateElevationInfoAtPoint as me}from"./elevationAlignmentUtils.js";import{Graphics3DMeshObject3DGraphicLayer as fe}from"./Graphics3DMeshObject3DGraphicLayer.js";import{Object3DEdgeState as pe}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as he}from"./Graphics3DSymbolLayer.js";import{MaterialInfoCache as de,MeshFastUpdateProcessor as ge}from"./MeshFastUpdateProcessor.js";import{SymbolComplexity as xe}from"./SymbolComplexity.js";import{hasEdges as _e,createMaterial as ye}from"../support/edgeUtils.js";import{parseColorMixMode as be,encodeSymbolColor as Te}from"../support/symbolColorUtils.js";import{debugFlags as ve}from"../../support/debugFlags.js";import{Attribute as we}from"../../webgl-engine/lib/Attribute.js";import{AlphaDiscardMode as Me,CullFaceOptions as Ce}from"../../webgl-engine/lib/basicInterfaces.js";import{ContentObjectType as Re}from"../../webgl-engine/lib/ContentObjectType.js";import{Geometry as je}from"../../webgl-engine/lib/Geometry.js";import{Object3D as Ae}from"../../webgl-engine/lib/Object3D.js";import{Texture as Pe}from"../../webgl-engine/lib/Texture.js";import{VertexAttribute as Oe}from"../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as Ee}from"../../webgl-engine/materials/DefaultMaterial.js";import{NativeLineMaterial as Ne}from"../../webgl-engine/materials/NativeLineMaterial.js";import{useSchematicPBR as Ie,advancedMRRFactors as Se,schematicMRRFactors as Ue}from"../../webgl-engine/materials/pbrUtils.js";import{TextureWrapMode as Be}from"../../../webgl/enums.js";const Fe=["mesh"];class Ve extends he{constructor(e,t,r,o){super(e,t,r,o,rt(t)),this._materialInfoCache=new de,this._fastUpdateProcessor=new ge,this._textures=new Map,this.ensureDrapedStatus(!1)}async doLoad(){ve.DRAW_MESH_GEOMETRY_NORMALS&&(this._debugVertexNormalMaterial=new Ne({color:[1,0,1,1]}),this._debugTangentNormalMaterial=new Ne({color:[1,.5,0,1]}),this._debugFaceNormalMaterial=new Ne({color:[0,1,1,1]})),this.updateComplexity()}destroy(){super.destroy(),this._textures.forEach((e=>e.unload())),this._context.stage.removeMany(this._materialInfoCache.materials),this._context.stage.removeMany(Array.from(this._textures.values())),this._materialInfoCache.clear(),this._textures.clear(),this._fastUpdateProcessor.destroy(this._context.stage)}get materials(){return this._materialInfoCache.materials}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,Fe,"fill on mesh-3d"))return null;const r=this.setGraphicElevationContext(t),o=e.renderingInfo;return this._createAs3DShape(t,o,r,t.uid)}onRemoveGraphic(e){this._fastUpdateProcessor.onRemoveGraphic(e,this._materialInfoCache,this._context)}layerOpacityChanged(e,t){const r=this._getLayerOpacity();this._updateMaterialParameters((e=>{e.material.setParameters({layerOpacity:r});const t=e.material.parameters;this._setMaterialTextureAlphaMode(t,e)})),e.forEach((e=>t(e)?.layerOpacityChanged(r,this._context.isAsync)))}layerElevationInfoChanged(e,t){return this.updateGraphics3DGraphicElevationInfo(e,t,ue)}slicePlaneEnabledChanged(e,t){return this._updateMaterialParameters((({material:e})=>{e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled})})),e.forEach((e=>t(e)?.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync))),!0}physicalBasedRenderingChanged(){const e=this._usePBR();return this._updateMaterialParameters((({material:t})=>t.setParameters({usePBR:e}))),!0}updateTransform(e,t,r,o){if(!e.fastTransformUpdatesAllowed)return!1;const a=e.fastTransformUpdatesEnabled;switch(o){case oe.EnableFastUpdates:if(a)return!0;break;case oe.DisableFastUpdates:if(!a)return!0;break;default:if(!a)return!!this.updateTransform(e,t,r,oe.EnableFastUpdates)&&(e.autoDisableFastTransformUpdates((()=>this.updateTransform(e,t,r,oe.DisableFastUpdates))),!0)}const n=this._context.renderCoordsHelper.spatialReference,s=ut,{origin:i,transform:l}=r;if(!E(t,d(nt,i.x,i.y,i.z??0),s,n))return!1;switch(o){case oe.EnableFastUpdates:this._fastUpdateProcessor.enable(e,this._materialInfoCache,this._context);break;case oe.DisableFastUpdates:this._fastUpdateProcessor.disable(e,this._materialInfoCache,this._context);break;case oe.UpdateFastLocalOrigin:e.updateFastLocalOrigin(s,l,this._context.localOriginFactory)}const{elevationContext:c}=e;c.centerPointInElevationSR=this._getCenterPointInElevationSR(s);const{elevationProvider:u,renderCoordsHelper:m}=this._context,f=(e,t)=>me(e,u,c,m,t);return e.alignedSampledElevation=ce(e,c,u.spatialReference,f,m,s),e.updateTransform(s,l,this._context.isAsync),e.updateAutoDisableFastTransformUpdates((()=>this.updateTransform(e,t,r,oe.DisableFastUpdates))),!0}computeComplexity(){if(!this._textures||0===this._textures.size)return super.computeComplexity();let e=0;for(const o of this._textures.values())e+=o.usedMemory;const t={...le(this.symbol,this.symbolLayer),resourceBytes:e},r=_e(this.symbolLayer)?2:0;return new xe({drawCallsPerFeature:r,memory:t})}_requiresSymbolVertexColors(){return this._drivenProperties.color||this._drivenProperties.opacity}_materialPropertiesDefault(e,t){const r=this._requiresSymbolVertexColors(),o=!!e.vertexAttributes.color,a=!!e.vertexAttributes.tangent;return{hasSymbolVertexColors:r,hasVertexColors:o,hasVertexTangents:a,uid:`vc:${o},vt:${a},vct${t},svc:${r}`}}_materialProperties(e,t,r){const o=this._materialPropertiesDefault(e,r);if(!t.material)return o;const{color:a,colorTexture:n,colorTextureTransform:s,normalTexture:i,normalTextureTransform:l,doubleSided:c,alphaCutoff:u,alphaMode:m}=t.material,f=Xe(a),p=Xe(n),h=et(s),d=Xe(i),g=et(l);if(o.color=a,o.colorTexture=n,o.normalTexture=i,o.uid=`${o.uid},cmuid:${f},ctmuid:${p},cttuid:${h},ntmuid:${d},nttuid:${g},ds:${c},ac:${u},am:${m}`,t.material instanceof G){const{metallic:e,roughness:r,metallicRoughnessTexture:a,metallicRoughnessTextureTransform:n,emissiveColor:i,emissiveTexture:c,emissiveTextureTransform:u,occlusionTexture:m,occlusionTextureTransform:f}=t.material,p=Xe(a),h=et(n),d=Xe(i),g=Xe(c),x=et(u),_=Xe(m),y=et(f);o.metallic=e,o.roughness=r,o.metallicRoughnessTexture=a,o.emissiveColor=i,o.emissiveTexture=c,o.occlusionTexture=m,o.colorTextureTransform=We(s),o.normalTextureTransform=We(l),o.emissiveTextureTransform=We(u),o.occlusionTextureTransform=We(f),o.metallicRoughnessTextureTransform=We(n),o.uid=`${o.uid},mrm:${e},mrr:${r},mrt:${p},mrtt:${h},emuid:${d},etmuid:${g},ett:${x},otmuid:${_},ott:${y}`}return o}_getInternalTexture(e,t=!1,a=Me.Opaque){const n=Qe(e);if(!n)return null;const s=`${e.contentHash}/${a}`;let i=this._textures.get(s);if(i){const e=this._context.stage.renderView.textures;let t=null;const a=e.acquire(i.id);return null==a||o(a)||(i.events.on("unloaded",(()=>t=r(t))),t=a),i}let l=null;const c=this._context.stage.renderView.renderingContext.parameters.maxMaxAnisotropy,u={wrap:Ye(e.wrap),noUnpackFlip:!0,maxAnisotropy:c,mipmap:c>1};return se(n)?(l=n.data,u.preMultiplyAlpha=!1,u.encoding=n.encoding):(l=n,u.preMultiplyAlpha=a!==Me.Opaque,u.compressionHandle=t?this._context.compressionHandle:void 0,u.compressionCallback=()=>this.updateComplexity()),i=new Pe(l,u),this._textures.set(s,i),i.events.on("loaded",(()=>this.updateComplexity())),i.load(this._context.stage.renderView.renderingContext),this._context.stage.add(i),i.events.on("unloaded",(()=>{this._textures.delete(s)})),i}_setInternalMaterialTextureParameters(t,r){if(null!=t.colorTexture){const e=r.textureAlphaMode!==Me.Opaque,o=this._getInternalTexture(t.colorTexture,e,r.textureAlphaMode);o?(r.textureId=o.id,r.textureAlphaPremultiplied=!!o.parameters.preMultiplyAlpha):r.textureId=void 0}t.normalTexture&&(r.normalTextureId=this._getInternalTexture(t.normalTexture)?.id),t.emissiveColor&&(r.emissiveBaseColor=e.toUnitRGB(t.emissiveColor)),t.emissiveTexture&&(r.emissiveTextureId=this._getInternalTexture(t.emissiveTexture,!0)?.id),t.occlusionTexture&&(r.occlusionTextureId=this._getInternalTexture(t.occlusionTexture,!0)?.id),t.metallicRoughnessTexture&&(r.metallicRoughnessTextureId=this._getInternalTexture(t.metallicRoughnessTexture,!0)?.id)}_setInternalMaterialParameters(e,t,r){null!=e.color&&Ke(e.color,t,r),this._setInternalMaterialTextureParameters(e,t),t.colorTextureTransformMatrix=ie(e.colorTextureTransform),t.normalTextureTransformMatrix=ie(e.normalTextureTransform);const o=null!=e.normalTextureTransform?.scale?e.normalTextureTransform?.scale:h;t.scale=[o[0],o[1]],t.occlusionTextureTransformMatrix=ie(e.occlusionTextureTransform),t.emissiveTextureTransformMatrix=ie(e.emissiveTextureTransform),t.metallicRoughnessTextureTransformMatrix=ie(e.metallicRoughnessTextureTransform)}_setExternalMaterialParameters(t,r=this.symbolLayer?.material?.color){const o=this._drivenProperties.color;let a=this.symbolLayer.material?.colorMixMode??null;if(o)t.externalColor=A;else{const o=r??null;o?t.externalColor=e.toUnitRGBA(o):(a=null,t.externalColor=A)}a&&(t.colorMixMode=a),t.castShadows=!!this.symbolLayer.castShadows,t.emissiveStrength=this.symbolLayer?.material?.emissive?.strength??1,t.emissiveSource=ae(this.symbolLayer?.material?.emissive?.source??"emissive")}_getOrCreateMaterial(t,r){const o=r.material?.color,a=r.material?.colorTexture,n=r.material?.alphaMode,s="blend"===n,i=!("opaque"===n)&&(Je(t)||null!=o&&o.a<1||a?.transparent||s),l=this._materialProperties(t,r,i),c=this._materialInfoCache.byUid(l.uid);if(c)return this._setInternalMaterialTextureParameters(l,c.material.parameters),c.material;const u={uid:l.uid,material:null,isComponentTransparent:i,alphaMode:r.material?r.material.alphaMode:"opaque"},m=Ie({normalTexture:l.normalTexture,metallicRoughnessTexture:l.metallicRoughnessTexture,metallicFactor:l.metallic,roughnessFactor:l.roughness,emissiveTexture:l.emissiveTexture,emissiveFactor:e.toUnitRGB(l.emissiveColor),occlusionTexture:l.occlusionTexture}),f={usePBR:this._usePBR(),isSchematic:m,hasVertexColors:l.hasVertexColors,hasSymbolColors:l.hasSymbolVertexColors,hasVertexTangents:l.hasVertexTangents,ambient:C,diffuse:R,opacity:1,doubleSided:!0,doubleSidedType:"winding-order",cullFace:Ce.None,layerOpacity:this._getLayerOpacity(),hasSlicePlane:this._context.slicePlaneEnabled,drivenOpacity:this.needsDrivenTransparentPass||u.isComponentTransparent};f.mrrFactors=m?Ue:[l.metallic,l.roughness,Se[2]],r.material&&(f.doubleSided=r.material.doubleSided,f.cullFace=r.material.doubleSided?Ce.None:Ce.Back,f.textureAlphaCutoff=r.material.alphaCutoff),this._setExternalMaterialParameters(f),this._setMaterialTextureAlphaMode(f,u),this._setInternalMaterialParameters(l,f,u);const p=new Ee(f,this._context);return u.material=p,this._materialInfoCache.set(l.uid,u),this._context.stage.add(p),p}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchColor(e,t)}_preparePatchColor(e,t){if(!t.material||"partial"!==t.material.type)return;const r=t.material.diff;if(!r.color||"complete"!==r.color.type||null==r.color.newValue||null==r.color.oldValue)return;const o=r.color.newValue;delete r.color,e.symbolLayerStatePatches.push((()=>{this._updateMaterialParameters((e=>{const t=e.material.parameters;this._setExternalMaterialParameters(t,o),this._setMaterialTextureAlphaMode(t,e),e.material.setParameters({externalColor:t.externalColor})}))}))}_usePBR(){return this._context.physicalBasedRenderingEnabled}_setMaterialTextureAlphaMode(e,t){if("auto"===t.alphaMode){const r=this.needsDrivenTransparentPass||t.isComponentTransparent||(e.layerOpacity??1)<1||(e.opacity??1)<1||(e.externalColor?.[3]??1)<1;e.textureAlphaMode=r?Me.MaskBlend:Me.Opaque}else e.textureAlphaMode="opaque"===t.alphaMode?Me.Opaque:"mask"===t.alphaMode?Me.Mask:Me.Blend}_createFaceDebugNormals(e,t){const r=t.length,o=e.spatialReference.isGeographic?20015077/180:1,n=.1*Math.max(e.extent.width*o,e.extent.height*o,e.extent.zmax-e.extent.zmin),i=[],l=[],c=t[0].transformation,u=a(s(),c);for(let a=0;a<r;a++){const e=t[a].attributes.get(Oe.POSITION);if(!e)continue;const r=e.data,o=e.indices;for(let t=0;t<o.length;t+=3)ze(r,o,t,lt),qe(r,o,t,nt,st,it),g(nt,nt,st),g(nt,nt,it),x(nt,nt,1/3),_(nt,nt,c),i.push(...nt),y(lt,lt,u),b(lt,lt),T(nt,nt,lt,n),i.push(...nt),l.push(l.length),l.push(l.length)}return i.length?new je(this._debugFaceNormalMaterial,[[Oe.POSITION,new we(i,l,3,!0)]],null,Re.Line):null}_createPerVertexDebugVectors(e,t,r,o,i){const l=t.length,c=e.spatialReference.isGeographic?20015077/180:1,u=.1*i*Math.max(e.extent.width*c,e.extent.height*c,e.extent.zmax-e.extent.zmin),m=[],f=[],p=t[0].transformation,h=a(s(),p);r===Oe.TANGENT&&n(h,p);for(let a=0;a<l;a++){const e=t[a],o=e.attributes.get(Oe.POSITION),n=e.attributes.get(r);if(!o||!n)continue;const s=o.data,i=o.indices,l=n.data,c=n.indices;for(let t=0;t<i.length;t++){const e=3*i[t],r=c[t]*n.stride;d(nt,s[e+0],s[e+1],s[e+2]),_(nt,nt,p),m.push(...nt),d(st,l[r+0],l[r+1],l[r+2]),y(st,st,h),b(st,st),T(nt,nt,st,u),m.push(...nt),f.push(f.length),f.push(f.length)}}return m.length?new je(o,[[Oe.POSITION,new we(m,f,3,!0)]],null,Re.Line):null}_createAs3DShape(e,t,r,o){const a=e.geometry;if("mesh"!==a.type)return null;const n=this._createGeometryInfo(a,t,o);if(null==n)return null;const{geometries:s,objectTransformation:i}=n;if(ve.DRAW_MESH_GEOMETRY_NORMALS){const e=this._createPerVertexDebugVectors(a,s,Oe.NORMAL,this._debugVertexNormalMaterial,1),t=this._createPerVertexDebugVectors(a,s,Oe.TANGENT,this._debugTangentNormalMaterial,.5),r=this._createFaceDebugNormals(a,s);e&&s.push(e),t&&s.push(t),r&&s.push(r)}const l=this._context.layerViewUid,c=new Ae({geometries:s,layerViewUid:l,graphicUid:o,isElevationSource:!0});c.transformation=i;const u=ye(this.symbolLayer,{opacity:this._getLayerOpacity()}),m=u?new pe(s[0].material,u,this._context.slicePlaneEnabled):null,f=new fe(this,c,s,null,null,ce,r,m);this._fastUpdateProcessor.onAddGraphic(),f.needsElevationUpdates=ue(r.mode),f.useObjectOriginAsAttachmentOrigin=!0,f.fastTransformUpdatesAllowed=this._fastTransformUpdatesAllowed(a),r.centerPointInElevationSR=this._getCenterPointInElevationSR(c.transformation);const{elevationProvider:p,renderCoordsHelper:h}=this._context,d=(e,t)=>me(e,p,r,h,t);return f.alignedSampledElevation=ce(f,r,p.spatialReference,d,h),f}_fastTransformUpdatesAllowed(e){const{vertexSpace:t,spatialReference:r}=e;if(!H(t))return!1;const{type:o}=t,{view:a}=this._context.graphicsCoreOwner,{viewingMode:n}=a.state,s=a.spatialReference;return n===ne.Global&&"local"===o||n===ne.Local&&q(s,r)&&"georeferenced"===o&&!r.isGeographic}_getCenterPointInElevationSR(e){const t=re(0,0,0,this._context.elevationProvider.spatialReference??null);return I([e[12],e[13],e[14]],this._context.renderCoordsHelper.spatialReference,t),t}_passthroughReprojectionInfo(e){return e.reprojection===pt.NONE&&!!e.objectTransformation}_createPositionBuffer(e,t){const r=e.vertexAttributes.position;let o,a=r;if(t.reprojection===pt.NONE)return{position:a,georeferencedPositionBuffer:o};const n=t.reprojection===pt.RENDER?t.transformBeforeProject:null;n&&(a=W(new Float64Array(a.length),a,n));const{normal:s,tangent:i}=e.vertexAttributes;this._passthroughReprojectionInfo(t)||!s&&!i||(o=a);const l=a===r||a===o?new Float64Array(a.length):a;return N(a,e.spatialReference,0,l,this._context.renderCoordsHelper.spatialReference,0),{position:l,georeferencedPositionBuffer:o}}_createNormalBuffer(e,t,r,o){const a=e.vertexAttributes.normal;if(null==a)return null;let n=a;const s=o.reprojection===pt.RENDER?o.transformBeforeProject:null;s&&(n=Y(n,new Float32Array(n.length),s));const i=this._context.graphicsCoreOwner.view.viewingMode;if(o.reprojection===pt.NONE)return n;if("local"===i){if(!z(this._context.renderCoordsHelper.spatialReference))return n;if(null==r)return null;if(e.spatialReference.isGeographic){const e=n===a?new Float32Array(n.length):n;return Z(n,J.NORMAL,r,e)}if(e.spatialReference.isWebMercator){const e=n===a?new Float32Array(n.length):n;return K(n,J.NORMAL,r,e)}return n}if(null==r)return null;const l=n===a?new Float32Array(n.length):n,c=this._context.renderCoordsHelper.spatialReference;return Q(n,r,e.spatialReference,t,c,l)}_createTangentBuffer(e,t,r,o){const a=e.vertexAttributes.tangent;if(null==a)return null;let n=a;const s=o.reprojection===pt.RENDER?o.transformBeforeProject:null;s&&(n=X(n,new Float32Array(n.length),s));const i=this._context.graphicsCoreOwner.view.viewingMode;if(o.reprojection===pt.NONE)return n;if("local"===i){if(!z(this._context.renderCoordsHelper.spatialReference))return n;if(null==r)return null;if(e.spatialReference.isGeographic){const e=n===a?new Float32Array(n.length):n;return Z(n,J.TANGENT,r,e)}if(e.spatialReference.isWebMercator){const e=n===a?new Float32Array(n.length):n;return K(n,J.TANGENT,r,e)}return n}if(null==r)return null;const l=n===a?new Float32Array(n.length):n,c=this._context.renderCoordsHelper.spatialReference;return ee(n,r,e.spatialReference,t,c,l)}_createSymbolColorBuffer(e){if(this._requiresSymbolVertexColors()){const t=this._getVertexOpacityAndColor(e,this._getFallbackOpacityAndColor()),r=be(this.symbolLayer?.material?.colorMixMode),o=new Uint8Array(4);return Te(t,r,o),o}return null}_createBuffers(e,t){const r=e.vertexAttributes&&e.vertexAttributes.position;if(!r)return this.logger.warn("Mesh geometry must contain position vertex attributes"),null;const o=e.vertexAttributes.normal,a=e.vertexAttributes.uv,n=e.vertexAttributes.tangent;if(o&&o.length!==r.length)return this.logger.warn("Mesh normal vertex buffer must contain the same number of elements as the position buffer"),null;if(n&&n.length/4!=r.length/3)return this.logger.warn("Mesh tangent vertex buffer must contain the same number of elements as the position buffer"),null;if(a&&a.length/2!=r.length/3)return this.logger.warn("Mesh uv vertex buffer must contain the same number of elements as the position buffer"),null;const s=this._computeReprojectionInfo(e),{position:i,georeferencedPositionBuffer:l}=this._createPositionBuffer(e,s),c=tt(e),u=this._createSymbolColorBuffer(t),f=this._createNormalBuffer(e,i,l,s),p=this._createTangentBuffer(e,i,l,s),h=a,{transformation:d,position:g,normal:x,tangent:_}=this._passthroughReprojectionInfo(s)?{transformation:s.objectTransformation,position:i,normal:f,tangent:p}:this._transformOriginLocal(e,i,f,p);return{positionBuffer:g,normalBuffer:x,tangentBuffer:_,uvBuffer:h,colorBuffer:c,symbolColorBuffer:u,objectTransformation:d,geometryTransformation:s.reprojection===pt.NONE&&s.geometryTransformation?s.geometryTransformation:m()}}_computeReprojectionInfo(e){const{vertexSpace:t}=e,r="georeferenced"===t.type?q(this._context.renderCoordsHelper.spatialReference,e.spatialReference)?pt.NONE:pt.RENDER:pt.NONE;if(k(t))return{reprojection:r};const o=t.origin,a=m(),n=e.transform?.localMatrix??f;if(r===pt.NONE){E(e.spatialReference,o,a,this._context.renderCoordsHelper.spatialReference);return{reprojection:r,objectTransformation:a,geometryTransformation:p(n)}}const s=i(m(),o);return l(s,s,n),{reprojection:r,transformBeforeProject:s}}_transformOriginLocal(e,t,r,o){const a=this._context.renderCoordsHelper.spatialReference,n=e.origin;at[0]=n.x,at[1]=n.y,at[2]=n.z??0;const s=m();E(e.spatialReference,at,s,a),c(ct,s);const{position:i,normal:l,tangent:u}=e.vertexAttributes,f=t===i?new Float64Array(t.length):t;W(f,t,ct);const p=r?r===l?new Float32Array(r.length):r:null,h=o?o===u?new Float32Array(o.length):o:null;return r&&p&&Y(r,p,ct),o&&h&&X(o,h,ct),{transformation:s,position:f,normal:p,tangent:h}}_validateFaces(e,t){const r=e.vertexAttributes.position.length/3,o=t.faces;if(o){let e=-1;for(let t=0;t<o.length;t++){const r=o[t];r>e&&(e=r)}if(r<=e)return this.logger.warn(`Vertex index ${e} is out of bounds of the mesh position buffer`),!1}else if(r%3!=0)return this.logger.warn("Mesh position buffer length must be a multiple of 9 if no component faces are defined (3 values per vertex * 3 vertices per triangle)"),!1;return!0}_isOutsideClippingArea(e){if(!this._context.clippingExtent)return!1;const t=e.vertexAttributes?.position;if(!t)return!1;const r=this._context.elevationProvider.spatialReference,o=te(e,r??e.spatialReference);return!!o&&(U(o,mt),!B(mt,this._context.clippingExtent))}_createGeometryInfo(e,t,r){if(!O(e.spatialReference,this._context.renderCoordsHelper.spatialReference))return this.logger.warn("Geometry spatial reference is not compatible with the view"),null;if(!this._validateVertexSpace(e))return null;if(this._isOutsideClippingArea(e))return null;const o=this._createBuffers(e,t);if(null==o)return null;const{positionBuffer:a,uvBuffer:n,colorBuffer:s,symbolColorBuffer:i,normalBuffer:l,tangentBuffer:c,objectTransformation:m,geometryTransformation:f}=o,p=e.components??ft,h=new Array;let d=!1;const g=u(nt,m),x=this._context.localOriginFactory.getOrigin(g);for(const u of p){if(!this._validateFaces(e,u))return null;const t=De(e,u);if(0===t.length)continue;const o=Ge(a,l,u,t);o.didFlipNormals&&(d=!0);const m=[[Oe.POSITION,new we(a,t,3,!0)],[Oe.NORMAL,new we(o.normals,o.indices,3,!0)]];s&&m.push([Oe.COLOR,new we(s,t,4,!0)]),i&&m.push([Oe.SYMBOLCOLOR,new we(i,V(t.length),4,!0)]),n&&m.push([Oe.UV0,new we(n,t,2,!0)]),c&&m.push([Oe.TANGENT,new we(c,t,4,!0)]);const p=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:r,layerViewUid:this._context.layerViewUid}),g=this._getOrCreateMaterial(e,u),_=new je(g,m,null,Re.Mesh,p);_.transformation=f,_.localOrigin=x,h.push(_)}return d&&this.logger.warn("Normals have been automatically flipped to be consistent with the counter clock wise face winding order. It is better to generate mesh geometries that have consistent normals."),{geometries:h,objectTransformation:m}}_updateMaterialParameters(e){this._materialInfoCache.forEachMaterialInfo(e),this._fastUpdateProcessor.forEachMaterialInfo(e),this._fastUpdateProcessor.forEachClonedMaterial(((e,t)=>{t.setParameters(e.parameters)}))}_validateVertexSpace(e){const{_context:{graphicsCoreOwner:{view:{state:{viewingMode:t}}}}}=this,{vertexSpace:r}=e;return t!==ne.Local||"local"!==r.type||(this.logger.warn("Displaying a mesh with a local vertex space in a view in local viewing mode is not supported."),!1)}test(){return{...super.test(),materials:this._materialInfoCache.materials}}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;return e.toUnitRGBA(t)??P}}class Le{constructor(e,t,r){this.normals=e,this.indices=t,this.didFlipNormals=r}}function De(e,t){return t.faces??L(e.vertexAttributes.position.length/3)}function Ge(e,t,r,o){switch(r.shading||"flat"){default:case"source":return He(e,t,r,o);case"flat":return $e(e,o);case"smooth":return ke(e,o)}}function $e(e,t){const r=F(t.length),o=new Array(3*t.length);for(let a=0;a<t.length;a+=3){const n=ze(e,t,a,lt);for(let e=0;e<3;e++)r[a+e]=n[e],o[a+e]=a/3}return new Le(r,o,!1)}function He(e,t,r,o){if(null==t)return $e(e,o);let a=!1;if(!r.trustSourceNormals)for(let n=0;n<o.length;n+=3){ze(e,o,n,lt);for(let e=0;e<3;e++){const r=3*o[n+e];nt[0]=t[r],nt[1]=t[r+1],nt[2]=t[r+2],v(lt,nt)<0&&(t[r]=-t[r],t[r+1]=-t[r+1],t[r+2]=-t[r+2],a=!0)}}return new Le(t,o,a)}function ke(e,t){const r={};for(let n=0;n<t.length;n+=3){const o=ze(e,t,n,lt);for(let e=0;e<3;e++){const a=t[n+e];let s=r[a];s||(s={normal:j(),count:0},r[a]=s),g(s.normal,s.normal,o),s.count++}}const o=F(3*t.length),a=new Array(3*t.length);for(let n=0;n<t.length;n++){const e=r[t[n]];1!==e.count&&(b(e.normal,e.normal),e.count=1);for(let t=0;t<3;t++)o[3*n+t]=e.normal[t];a[n]=n}return new Le(o,a,!1)}function qe(e,t,r,o,a,n){const s=3*t[r],i=3*t[r+1],l=3*t[r+2];o[0]=e[s],o[1]=e[s+1],o[2]=e[s+2],a[0]=e[i],a[1]=e[i+1],a[2]=e[i+2],n[0]=e[l],n[1]=e[l+1],n[2]=e[l+2]}function ze(e,t,r,o){return qe(e,t,r,nt,st,it),w(st,st,nt),w(it,it,nt),M(nt,st,it),b(o,nt),o}function We(e){if(!e)return null;const{scale:r,offset:o,rotation:a}=e;return{scale:r,offset:o,rotation:t(a)}}function Ye(e="repeat"){if("string"==typeof e){const t=Ze(e);return{s:t,t}}return{s:Ze(e.horizontal),t:Ze(e.vertical)}}function Ze(e){switch(e){case"clamp":return Be.CLAMP_TO_EDGE;case"mirror":return Be.MIRRORED_REPEAT;default:return Be.REPEAT}}function Je(e){const t=e.vertexAttributes.color;if(null==t)return!1;for(let r=3;r<t.length;r+=4)if(255!==t[r])return!0;return!1}function Ke(t,r,o){r.diffuse=e.toUnitRGB(t),r.opacity="opaque"===o.alphaMode?1:t.a}function Qe(e){return e.data??e.url}function Xe(t){return null==t?"-":t instanceof e?t.toHex():t.contentHash}function et(e){const{offset:t,scale:r,rotation:o}=e??ot;return`${t[0]},${t[1]},${o},${r[0]},${r[1]}`}function tt(e){return e.vertexAttributes.color}function rt(e){return 1===(e.material?.color?.a??1)}const ot=new $,at=j(),nt=j(),st=j(),it=j(),lt=j(),ct=m(),ut=m(),mt=S(),ft=[new D];var pt;!function(e){e[e.NONE=0]="NONE",e[e.RENDER=1]="RENDER"}(pt||(pt={}));export{Ve as Graphics3DMeshFillSymbolLayer};
|
|
5
|
+
import e from"../../../../Color.js";import"../../../../core/has.js";import{deg2rad as t}from"../../../../core/mathUtils.js";import{releaseMaybe as r}from"../../../../core/maybe.js";import{isPromiseLike as o}from"../../../../core/promiseUtils.js";import{normalFromMat4 as a,fromMat4 as n}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{fromTranslation as i,multiply as l,invert as c,getTranslation as u}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as m,IDENTITY as f,clone as p}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{ONES as h}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{i as d,g,h as x,t as _,q as y,n as b,b as T,f as v,d as w,e as M}from"../../../../chunks/vec32.js";import{ZEROS as R,ONES as C,create as j}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as A,ZEROS as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{canProjectWithoutEngine as O}from"../../../../geometry/projection.js";import{computeTranslationToOriginAndRotation as E}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectBuffer as N}from"../../../../geometry/projection/projectBuffer.js";import{projectVectorToPoint as I}from"../../../../geometry/projection/projectVectorToPoint.js";import{create as S,fromBuffer as U,intersectsClippingArea as B}from"../../../../geometry/support/aaBoundingBox.js";import{newFloatArray as F}from"../../../../geometry/support/FloatArray.js";import{getZeroIndexArray as V,getContinuousIndexArray as L}from"../../../../geometry/support/Indices.js";import D from"../../../../geometry/support/MeshComponent.js";import G from"../../../../geometry/support/MeshMaterialMetallicRoughness.js";import $ from"../../../../geometry/support/MeshTextureTransform.js";import{isRelativeVertexSpace as H,isAbsoluteVertexSpace as k}from"../../../../geometry/support/meshVertexSpaceUtils.js";import{equals as q,isPlateCarree as z}from"../../../../geometry/support/spatialReferenceUtils.js";import{t as W}from"../../../../chunks/vec3.js";import{transformNormal as Y,transformVectorENUPlateCarree as Z,VectorType as J,transformVectorWMPlateCarree as K,projectNormalToPCPF as Q,transformTangent as X,projectTangentToPCPF as ee}from"../../../../geometry/support/meshUtils/projection.js";import{projectMeshVertexPositions as te}from"../../../../geometry/support/meshUtils/projectMeshVertexPositions.js";import{makeDehydratedPoint as re}from"../../../../layers/graphics/dehydratedPoint.js";import{MeshTransformUpdateAction as oe}from"../../../../layers/graphics/sources/interfaces.js";import{getEmissiveMode as ae}from"../../../../symbols/support/materialUtils.js";import{ViewingMode as ne}from"../../../ViewingMode.js";import{isEncodedMeshTexture as se}from"../../glTF/internal/resourceUtils.js";import{getTransformMatrix as ie}from"../../glTF/internal/TextureTransformUtils.js";import{defaultSymbolLayerMemoryComplexity as le}from"./defaultSymbolComplexity.js";import{perObjectElevationAligner as ce}from"./ElevationAligners.js";import{needsElevationUpdates3D as ue,evaluateElevationInfoAtPoint as me}from"./elevationAlignmentUtils.js";import{Graphics3DMeshObject3DGraphicLayer as fe}from"./Graphics3DMeshObject3DGraphicLayer.js";import{Object3DEdgeState as pe}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as he}from"./Graphics3DSymbolLayer.js";import{MaterialInfoCache as de,MeshFastUpdateProcessor as ge}from"./MeshFastUpdateProcessor.js";import{SymbolComplexity as xe}from"./SymbolComplexity.js";import{hasEdges as _e,createMaterial as ye}from"../support/edgeUtils.js";import{parseColorMixMode as be,encodeSymbolColor as Te}from"../support/symbolColorUtils.js";import{debugFlags as ve}from"../../support/debugFlags.js";import{Attribute as we}from"../../webgl-engine/lib/Attribute.js";import{AlphaDiscardMode as Me,CullFaceOptions as Re}from"../../webgl-engine/lib/basicInterfaces.js";import{Geometry as Ce}from"../../webgl-engine/lib/Geometry.js";import{Object3D as je}from"../../webgl-engine/lib/Object3D.js";import{Texture as Ae}from"../../webgl-engine/lib/Texture.js";import{VertexAttribute as Pe}from"../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as Oe}from"../../webgl-engine/materials/DefaultMaterial.js";import{NativeLineMaterial as Ee}from"../../webgl-engine/materials/NativeLineMaterial.js";import{useSchematicPBR as Ne,advancedMRRFactors as Ie,schematicMRRFactors as Se}from"../../webgl-engine/materials/pbrUtils.js";import{TextureWrapMode as Ue}from"../../../webgl/enums.js";import{GeometryType as Be}from"../../webgl-engine/lib/IntersectableGeometry.js";const Fe=["mesh"];class Ve extends he{constructor(e,t,r,o){super(e,t,r,o,rt(t)),this._materialInfoCache=new de,this._fastUpdateProcessor=new ge,this._textures=new Map,this.ensureDrapedStatus(!1)}async doLoad(){ve.DRAW_MESH_GEOMETRY_NORMALS&&(this._debugVertexNormalMaterial=new Ee({color:[1,0,1,1]}),this._debugTangentNormalMaterial=new Ee({color:[1,.5,0,1]}),this._debugFaceNormalMaterial=new Ee({color:[0,1,1,1]})),this.updateComplexity()}destroy(){super.destroy(),this._textures.forEach((e=>e.unload())),this._context.stage.removeMany(Array.from(this._textures.values())),this._materialInfoCache.clear(),this._textures.clear(),this._fastUpdateProcessor.destroy()}get materials(){return this._materialInfoCache.materials}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,Fe,"fill on mesh-3d"))return null;const r=this.setGraphicElevationContext(t),o=e.renderingInfo;return this._createAs3DShape(t,o,r,t.uid)}onRemoveGraphic(e){this._fastUpdateProcessor.onRemoveGraphic(e,this._materialInfoCache)}layerOpacityChanged(e,t){const r=this._getLayerOpacity();this._updateMaterialParameters((e=>{e.material.setParameters({layerOpacity:r});const t=e.material.parameters;this._setMaterialTextureAlphaMode(t,e)})),e.forEach((e=>t(e)?.layerOpacityChanged(r,this._context.isAsync)))}layerElevationInfoChanged(e,t){return this.updateGraphics3DGraphicElevationInfo(e,t,ue)}slicePlaneEnabledChanged(e,t){return this._updateMaterialParameters((({material:e})=>{e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled})})),e.forEach((e=>t(e)?.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync))),!0}physicalBasedRenderingChanged(){const e=this._usePBR();return this._updateMaterialParameters((({material:t})=>t.setParameters({usePBR:e}))),!0}updateTransform(e,t,r,o){if(!e.fastTransformUpdatesAllowed)return!1;const a=e.fastTransformUpdatesEnabled;switch(o){case oe.EnableFastUpdates:if(a)return!0;break;case oe.DisableFastUpdates:if(!a)return!0;break;default:if(!a)return!!this.updateTransform(e,t,r,oe.EnableFastUpdates)&&(e.autoDisableFastTransformUpdates((()=>this.updateTransform(e,t,r,oe.DisableFastUpdates))),!0)}const n=this._context.renderCoordsHelper.spatialReference,s=ut,{origin:i,transform:l}=r;if(!E(t,d(nt,i.x,i.y,i.z??0),s,n))return!1;switch(o){case oe.EnableFastUpdates:this._fastUpdateProcessor.enable(e,this._materialInfoCache,this._context);break;case oe.DisableFastUpdates:this._fastUpdateProcessor.disable(e,this._materialInfoCache);break;case oe.UpdateFastLocalOrigin:e.updateFastLocalOrigin(s,l,this._context.localOriginFactory)}const{elevationContext:c}=e;c.centerPointInElevationSR=this._getCenterPointInElevationSR(s);const{elevationProvider:u,renderCoordsHelper:m}=this._context,f=(e,t)=>me(e,u,c,m,t);return e.alignedSampledElevation=ce(e,c,u.spatialReference,f,m,s),e.updateTransform(s,l,this._context.isAsync),e.updateAutoDisableFastTransformUpdates((()=>this.updateTransform(e,t,r,oe.DisableFastUpdates))),!0}computeComplexity(){if(!this._textures||0===this._textures.size)return super.computeComplexity();let e=0;for(const o of this._textures.values())e+=o.usedMemory;const t={...le(this.symbol,this.symbolLayer),resourceBytes:e},r=_e(this.symbolLayer)?2:0;return new xe({drawCallsPerFeature:r,memory:t})}_requiresSymbolVertexColors(){return this._drivenProperties.color||this._drivenProperties.opacity}_materialPropertiesDefault(e,t){const r=this._requiresSymbolVertexColors(),o=!!e.vertexAttributes.color,a=!!e.vertexAttributes.tangent;return{hasSymbolVertexColors:r,hasVertexColors:o,hasVertexTangents:a,uid:`vc:${o},vt:${a},vct${t},svc:${r}`}}_materialProperties(e,t,r){const o=this._materialPropertiesDefault(e,r);if(!t.material)return o;const{color:a,colorTexture:n,colorTextureTransform:s,normalTexture:i,normalTextureTransform:l,doubleSided:c,alphaCutoff:u,alphaMode:m}=t.material,f=Xe(a),p=Xe(n),h=et(s),d=Xe(i),g=et(l);if(o.color=a,o.colorTexture=n,o.normalTexture=i,o.uid=`${o.uid},cmuid:${f},ctmuid:${p},cttuid:${h},ntmuid:${d},nttuid:${g},ds:${c},ac:${u},am:${m}`,t.material instanceof G){const{metallic:e,roughness:r,metallicRoughnessTexture:a,metallicRoughnessTextureTransform:n,emissiveColor:i,emissiveTexture:c,emissiveTextureTransform:u,occlusionTexture:m,occlusionTextureTransform:f}=t.material,p=Xe(a),h=et(n),d=Xe(i),g=Xe(c),x=et(u),_=Xe(m),y=et(f);o.metallic=e,o.roughness=r,o.metallicRoughnessTexture=a,o.emissiveColor=i,o.emissiveTexture=c,o.occlusionTexture=m,o.colorTextureTransform=We(s),o.normalTextureTransform=We(l),o.emissiveTextureTransform=We(u),o.occlusionTextureTransform=We(f),o.metallicRoughnessTextureTransform=We(n),o.uid=`${o.uid},mrm:${e},mrr:${r},mrt:${p},mrtt:${h},emuid:${d},etmuid:${g},ett:${x},otmuid:${_},ott:${y}`}return o}_getInternalTexture(e,t=!1,a=Me.Opaque){const n=Qe(e);if(!n)return null;const s=`${e.contentHash}/${a}`;let i=this._textures.get(s);if(i){const e=this._context.stage.renderView.textures;let t=null;const a=e.acquire(i.id);return null==a||o(a)||(i.events.on("unloaded",(()=>t=r(t))),t=a),i}let l=null;const c=this._context.stage.renderView.renderingContext.parameters.maxMaxAnisotropy,u={wrap:Ye(e.wrap),noUnpackFlip:!0,maxAnisotropy:c,mipmap:c>1};return se(n)?(l=n.data,u.preMultiplyAlpha=!1,u.encoding=n.encoding):(l=n,u.preMultiplyAlpha=a!==Me.Opaque,u.compressionHandle=t?this._context.compressionHandle:void 0,u.compressionCallback=t?()=>this.updateComplexity():void 0),i=new Ae(l,u),this._textures.set(s,i),i.events.on("loaded",(()=>this.updateComplexity())),i.load(this._context.stage.renderView.renderingContext),this._context.stage.add(i),i.events.on("unloaded",(()=>{this._textures.delete(s)})),i}_setInternalMaterialTextureParameters(t,r){if(null!=t.colorTexture){const e=r.textureAlphaMode!==Me.Opaque,o=this._getInternalTexture(t.colorTexture,e,r.textureAlphaMode);o?(r.textureId=o.id,r.textureAlphaPremultiplied=!!o.parameters.preMultiplyAlpha):r.textureId=void 0}t.normalTexture&&(r.normalTextureId=this._getInternalTexture(t.normalTexture)?.id),t.emissiveColor&&(r.emissiveBaseColor=e.toUnitRGB(t.emissiveColor)),t.emissiveTexture&&(r.emissiveTextureId=this._getInternalTexture(t.emissiveTexture)?.id),t.occlusionTexture&&(r.occlusionTextureId=this._getInternalTexture(t.occlusionTexture,!0)?.id),t.metallicRoughnessTexture&&(r.metallicRoughnessTextureId=this._getInternalTexture(t.metallicRoughnessTexture,!0)?.id)}_setInternalMaterialParameters(e,t,r){null!=e.color&&Ke(e.color,t,r),this._setInternalMaterialTextureParameters(e,t),t.colorTextureTransformMatrix=ie(e.colorTextureTransform),t.normalTextureTransformMatrix=ie(e.normalTextureTransform);const o=null!=e.normalTextureTransform?.scale?e.normalTextureTransform?.scale:h;t.scale=[o[0],o[1]],t.occlusionTextureTransformMatrix=ie(e.occlusionTextureTransform),t.emissiveTextureTransformMatrix=ie(e.emissiveTextureTransform),t.metallicRoughnessTextureTransformMatrix=ie(e.metallicRoughnessTextureTransform)}_setExternalMaterialParameters(t,r=this.symbolLayer?.material?.color){const o=this._drivenProperties.color;let a=this.symbolLayer.material?.colorMixMode??null;if(o)t.externalColor=A;else{const o=r??null;o?t.externalColor=e.toUnitRGBA(o):(a=null,t.externalColor=A)}a&&(t.colorMixMode=a),t.castShadows=!!this.symbolLayer.castShadows,t.emissiveStrength=this.symbolLayer?.material?.emissive?.strength??1,t.emissiveSource=ae(this.symbolLayer?.material?.emissive?.source??"emissive")}_getOrCreateMaterial(t,r){const o=r.material?.color,a=r.material?.colorTexture,n=r.material?.alphaMode,s="blend"===n,i=!("opaque"===n)&&(Je(t)||null!=o&&o.a<1||a?.transparent||s),l=this._materialProperties(t,r,i),c=this._materialInfoCache.byUid(l.uid);if(c)return this._setInternalMaterialTextureParameters(l,c.material.parameters),c.material;const u={uid:l.uid,material:null,isComponentTransparent:i,alphaMode:r.material?r.material.alphaMode:"opaque"},m=Ne({normalTexture:l.normalTexture,metallicRoughnessTexture:l.metallicRoughnessTexture,metallicFactor:l.metallic,roughnessFactor:l.roughness,emissiveTexture:l.emissiveTexture,emissiveFactor:e.toUnitRGB(l.emissiveColor),occlusionTexture:l.occlusionTexture}),f={usePBR:this._usePBR(),isSchematic:m,hasVertexColors:l.hasVertexColors,hasSymbolColors:l.hasSymbolVertexColors,hasVertexTangents:l.hasVertexTangents,ambient:R,diffuse:C,opacity:1,doubleSided:!0,doubleSidedType:"winding-order",cullFace:Re.None,layerOpacity:this._getLayerOpacity(),hasSlicePlane:this._context.slicePlaneEnabled,drivenOpacity:this.needsDrivenTransparentPass||u.isComponentTransparent};f.mrrFactors=m?Se:[l.metallic,l.roughness,Ie[2]],r.material&&(f.doubleSided=r.material.doubleSided,f.cullFace=r.material.doubleSided?Re.None:Re.Back,f.textureAlphaCutoff=r.material.alphaCutoff),this._setExternalMaterialParameters(f),this._setMaterialTextureAlphaMode(f,u),this._setInternalMaterialParameters(l,f,u);const p=new Oe(f,this._context);return u.material=p,this._materialInfoCache.set(l.uid,u),p}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchColor(e,t)}_preparePatchColor(e,t){if(!t.material||"partial"!==t.material.type)return;const r=t.material.diff;if(!r.color||"complete"!==r.color.type||null==r.color.newValue||null==r.color.oldValue)return;const o=r.color.newValue;delete r.color,e.symbolLayerStatePatches.push((()=>{this._updateMaterialParameters((e=>{const t=e.material.parameters;this._setExternalMaterialParameters(t,o),this._setMaterialTextureAlphaMode(t,e),e.material.setParameters({externalColor:t.externalColor})}))}))}_usePBR(){return this._context.physicalBasedRenderingEnabled}_setMaterialTextureAlphaMode(e,t){if("auto"===t.alphaMode){const r=this.needsDrivenTransparentPass||t.isComponentTransparent||(e.layerOpacity??1)<1||(e.opacity??1)<1||(e.externalColor?.[3]??1)<1;e.textureAlphaMode=r?Me.MaskBlend:Me.Opaque}else e.textureAlphaMode="opaque"===t.alphaMode?Me.Opaque:"mask"===t.alphaMode?Me.Mask:Me.Blend}_createFaceDebugNormals(e,t){const r=t.length,o=e.spatialReference.isGeographic?20015077/180:1,n=.1*Math.max(e.extent.width*o,e.extent.height*o,e.extent.zmax-e.extent.zmin),i=[],l=[],c=t[0].transformation,u=a(s(),c);for(let a=0;a<r;a++){const e=t[a].attributes.get(Pe.POSITION);if(!e)continue;const r=e.data,o=e.indices;for(let t=0;t<o.length;t+=3)ze(r,o,t,lt),qe(r,o,t,nt,st,it),g(nt,nt,st),g(nt,nt,it),x(nt,nt,1/3),_(nt,nt,c),i.push(...nt),y(lt,lt,u),b(lt,lt),T(nt,nt,lt,n),i.push(...nt),l.push(l.length),l.push(l.length)}return i.length?new Ce(this._debugFaceNormalMaterial,[[Pe.POSITION,new we(i,l,3,!0)]],null,Be.Line):null}_createPerVertexDebugVectors(e,t,r,o,i){const l=t.length,c=e.spatialReference.isGeographic?20015077/180:1,u=.1*i*Math.max(e.extent.width*c,e.extent.height*c,e.extent.zmax-e.extent.zmin),m=[],f=[],p=t[0].transformation,h=a(s(),p);r===Pe.TANGENT&&n(h,p);for(let a=0;a<l;a++){const e=t[a],o=e.attributes.get(Pe.POSITION),n=e.attributes.get(r);if(!o||!n)continue;const s=o.data,i=o.indices,l=n.data,c=n.indices;for(let t=0;t<i.length;t++){const e=3*i[t],r=c[t]*n.stride;d(nt,s[e+0],s[e+1],s[e+2]),_(nt,nt,p),m.push(...nt),d(st,l[r+0],l[r+1],l[r+2]),y(st,st,h),b(st,st),T(nt,nt,st,u),m.push(...nt),f.push(f.length),f.push(f.length)}}return m.length?new Ce(o,[[Pe.POSITION,new we(m,f,3,!0)]],null,Be.Line):null}_createAs3DShape(e,t,r,o){const a=e.geometry;if("mesh"!==a.type)return null;const n=this._createGeometryInfo(a,t,o);if(null==n)return null;const{geometries:s,objectTransformation:i}=n;if(ve.DRAW_MESH_GEOMETRY_NORMALS){const e=this._createPerVertexDebugVectors(a,s,Pe.NORMAL,this._debugVertexNormalMaterial,1),t=this._createPerVertexDebugVectors(a,s,Pe.TANGENT,this._debugTangentNormalMaterial,.5),r=this._createFaceDebugNormals(a,s);e&&s.push(e),t&&s.push(t),r&&s.push(r)}const l=this._context.layerViewUid,c=new je({geometries:s,layerViewUid:l,graphicUid:o,isElevationSource:!0});c.transformation=i;const u=ye(this.symbolLayer,{opacity:this._getLayerOpacity()}),m=u?new pe(s[0].material,u,this._context.slicePlaneEnabled):null,f=new fe(this,c,null,ce,r,m);this._fastUpdateProcessor.onAddGraphic(),f.needsElevationUpdates=ue(r.mode),f.useObjectOriginAsAttachmentOrigin=!0,f.fastTransformUpdatesAllowed=this._fastTransformUpdatesAllowed(a),r.centerPointInElevationSR=this._getCenterPointInElevationSR(c.transformation);const{elevationProvider:p,renderCoordsHelper:h}=this._context,d=(e,t)=>me(e,p,r,h,t);return f.alignedSampledElevation=ce(f,r,p.spatialReference,d,h),f}_fastTransformUpdatesAllowed(e){const{vertexSpace:t,spatialReference:r}=e;if(!H(t))return!1;const{type:o}=t,{view:a}=this._context.graphicsCoreOwner,{viewingMode:n}=a.state,s=a.spatialReference;return n===ne.Global&&"local"===o||n===ne.Local&&q(s,r)&&"georeferenced"===o&&!r.isGeographic}_getCenterPointInElevationSR(e){const t=re(0,0,0,this._context.elevationProvider.spatialReference??null);return I([e[12],e[13],e[14]],this._context.renderCoordsHelper.spatialReference,t),t}_passthroughReprojectionInfo(e){return e.reprojection===pt.NONE&&!!e.objectTransformation}_createPositionBuffer(e,t){const r=e.vertexAttributes.position;let o,a=r;if(t.reprojection===pt.NONE)return{position:a,georeferencedPositionBuffer:o};const n=t.reprojection===pt.RENDER?t.transformBeforeProject:null;n&&(a=W(new Float64Array(a.length),a,n));const{normal:s,tangent:i}=e.vertexAttributes;this._passthroughReprojectionInfo(t)||!s&&!i||(o=a);const l=a===r||a===o?new Float64Array(a.length):a;return N(a,e.spatialReference,0,l,this._context.renderCoordsHelper.spatialReference,0),{position:l,georeferencedPositionBuffer:o}}_createNormalBuffer(e,t,r,o){const a=e.vertexAttributes.normal;if(null==a)return null;let n=a;const s=o.reprojection===pt.RENDER?o.transformBeforeProject:null;s&&(n=Y(n,new Float32Array(n.length),s));const i=this._context.graphicsCoreOwner.view.viewingMode;if(o.reprojection===pt.NONE)return n;if("local"===i){if(!z(this._context.renderCoordsHelper.spatialReference))return n;if(null==r)return null;if(e.spatialReference.isGeographic){const e=n===a?new Float32Array(n.length):n;return Z(n,J.NORMAL,r,e)}if(e.spatialReference.isWebMercator){const e=n===a?new Float32Array(n.length):n;return K(n,J.NORMAL,r,e)}return n}if(null==r)return null;const l=n===a?new Float32Array(n.length):n,c=this._context.renderCoordsHelper.spatialReference;return Q(n,r,e.spatialReference,t,c,l)}_createTangentBuffer(e,t,r,o){const a=e.vertexAttributes.tangent;if(null==a)return null;let n=a;const s=o.reprojection===pt.RENDER?o.transformBeforeProject:null;s&&(n=X(n,new Float32Array(n.length),s));const i=this._context.graphicsCoreOwner.view.viewingMode;if(o.reprojection===pt.NONE)return n;if("local"===i){if(!z(this._context.renderCoordsHelper.spatialReference))return n;if(null==r)return null;if(e.spatialReference.isGeographic){const e=n===a?new Float32Array(n.length):n;return Z(n,J.TANGENT,r,e)}if(e.spatialReference.isWebMercator){const e=n===a?new Float32Array(n.length):n;return K(n,J.TANGENT,r,e)}return n}if(null==r)return null;const l=n===a?new Float32Array(n.length):n,c=this._context.renderCoordsHelper.spatialReference;return ee(n,r,e.spatialReference,t,c,l)}_createSymbolColorBuffer(e){if(this._requiresSymbolVertexColors()){const t=this._getVertexOpacityAndColor(e,this._getFallbackOpacityAndColor()),r=be(this.symbolLayer?.material?.colorMixMode),o=new Uint8Array(4);return Te(t,r,o),o}return null}_createBuffers(e,t){const r=e.vertexAttributes&&e.vertexAttributes.position;if(!r)return this.logger.warn("Mesh geometry must contain position vertex attributes"),null;const o=e.vertexAttributes.normal,a=e.vertexAttributes.uv,n=e.vertexAttributes.tangent;if(o&&o.length!==r.length)return this.logger.warn("Mesh normal vertex buffer must contain the same number of elements as the position buffer"),null;if(n&&n.length/4!=r.length/3)return this.logger.warn("Mesh tangent vertex buffer must contain the same number of elements as the position buffer"),null;if(a&&a.length/2!=r.length/3)return this.logger.warn("Mesh uv vertex buffer must contain the same number of elements as the position buffer"),null;const s=this._computeReprojectionInfo(e),{position:i,georeferencedPositionBuffer:l}=this._createPositionBuffer(e,s),c=tt(e),u=this._createSymbolColorBuffer(t),f=this._createNormalBuffer(e,i,l,s),p=this._createTangentBuffer(e,i,l,s),h=a,{transformation:d,position:g,normal:x,tangent:_}=this._passthroughReprojectionInfo(s)?{transformation:s.objectTransformation,position:i,normal:f,tangent:p}:this._transformOriginLocal(e,i,f,p);return{positionBuffer:g,normalBuffer:x,tangentBuffer:_,uvBuffer:h,colorBuffer:c,symbolColorBuffer:u,objectTransformation:d,geometryTransformation:s.reprojection===pt.NONE&&s.geometryTransformation?s.geometryTransformation:m()}}_computeReprojectionInfo(e){const{vertexSpace:t}=e,r="georeferenced"===t.type?q(this._context.renderCoordsHelper.spatialReference,e.spatialReference)?pt.NONE:pt.RENDER:pt.NONE;if(k(t))return{reprojection:r};const o=t.origin,a=m(),n=e.transform?.localMatrix??f;if(r===pt.NONE){E(e.spatialReference,o,a,this._context.renderCoordsHelper.spatialReference);return{reprojection:r,objectTransformation:a,geometryTransformation:p(n)}}const s=i(m(),o);return l(s,s,n),{reprojection:r,transformBeforeProject:s}}_transformOriginLocal(e,t,r,o){const a=this._context.renderCoordsHelper.spatialReference,n=e.origin;at[0]=n.x,at[1]=n.y,at[2]=n.z??0;const s=m();E(e.spatialReference,at,s,a),c(ct,s);const{position:i,normal:l,tangent:u}=e.vertexAttributes,f=t===i?new Float64Array(t.length):t;W(f,t,ct);const p=r?r===l?new Float32Array(r.length):r:null,h=o?o===u?new Float32Array(o.length):o:null;return r&&p&&Y(r,p,ct),o&&h&&X(o,h,ct),{transformation:s,position:f,normal:p,tangent:h}}_validateFaces(e,t){const r=e.vertexAttributes.position.length/3,o=t.faces;if(o){let e=-1;for(let t=0;t<o.length;t++){const r=o[t];r>e&&(e=r)}if(r<=e)return this.logger.warn(`Vertex index ${e} is out of bounds of the mesh position buffer`),!1}else if(r%3!=0)return this.logger.warn("Mesh position buffer length must be a multiple of 9 if no component faces are defined (3 values per vertex * 3 vertices per triangle)"),!1;return!0}_isOutsideClippingArea(e){if(!this._context.clippingExtent)return!1;const t=e.vertexAttributes?.position;if(!t)return!1;const r=this._context.elevationProvider.spatialReference,o=te(e,r??e.spatialReference);return!!o&&(U(o,mt),!B(mt,this._context.clippingExtent))}_createGeometryInfo(e,t,r){if(!O(e.spatialReference,this._context.renderCoordsHelper.spatialReference))return this.logger.warn("Geometry spatial reference is not compatible with the view"),null;if(!this._validateVertexSpace(e))return null;if(this._isOutsideClippingArea(e))return null;const o=this._createBuffers(e,t);if(null==o)return null;const{positionBuffer:a,uvBuffer:n,colorBuffer:s,symbolColorBuffer:i,normalBuffer:l,tangentBuffer:c,objectTransformation:m,geometryTransformation:f}=o,p=e.components??ft,h=new Array;let d=!1;const g=u(nt,m),x=this._context.localOriginFactory.getOrigin(g);for(const u of p){if(!this._validateFaces(e,u))return null;const t=De(e,u);if(0===t.length)continue;const o=Ge(a,l,u,t);o.didFlipNormals&&(d=!0);const m=[[Pe.POSITION,new we(a,t,3,!0)],[Pe.NORMAL,new we(o.normals,o.indices,3,!0)]];s&&m.push([Pe.COLOR,new we(s,t,4,!0)]),i&&m.push([Pe.SYMBOLCOLOR,new we(i,V(t.length),4,!0)]),n&&m.push([Pe.UV0,new we(n,t,2,!0)]),c&&m.push([Pe.TANGENT,new we(c,t,4,!0)]);const p=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:r,layerViewUid:this._context.layerViewUid}),g=this._getOrCreateMaterial(e,u),_=new Ce(g,m,null,Be.Mesh,p);_.transformation=f,_.localOrigin=x,h.push(_)}return d&&this.logger.warn("Normals have been automatically flipped to be consistent with the counter clock wise face winding order. It is better to generate mesh geometries that have consistent normals."),{geometries:h,objectTransformation:m}}_updateMaterialParameters(e){this._materialInfoCache.forEachMaterialInfo(e),this._fastUpdateProcessor.forEachMaterialInfo(e),this._fastUpdateProcessor.forEachClonedMaterial(((e,t)=>{t.setParameters(e.parameters)}))}_validateVertexSpace(e){const{_context:{graphicsCoreOwner:{view:{state:{viewingMode:t}}}}}=this,{vertexSpace:r}=e;return t!==ne.Local||"local"!==r.type||(this.logger.warn("Displaying a mesh with a local vertex space in a view in local viewing mode is not supported."),!1)}test(){return{...super.test(),materials:this._materialInfoCache.materials}}_getFallbackOpacityAndColor(){const t=this.symbolLayer?.material?.color;return e.toUnitRGBA(t)??P}}class Le{constructor(e,t,r){this.normals=e,this.indices=t,this.didFlipNormals=r}}function De(e,t){return t.faces??L(e.vertexAttributes.position.length/3)}function Ge(e,t,r,o){switch(r.shading||"flat"){default:case"source":return He(e,t,r,o);case"flat":return $e(e,o);case"smooth":return ke(e,o)}}function $e(e,t){const r=F(t.length),o=new Array(3*t.length);for(let a=0;a<t.length;a+=3){const n=ze(e,t,a,lt);for(let e=0;e<3;e++)r[a+e]=n[e],o[a+e]=a/3}return new Le(r,o,!1)}function He(e,t,r,o){if(null==t)return $e(e,o);let a=!1;if(!r.trustSourceNormals)for(let n=0;n<o.length;n+=3){ze(e,o,n,lt);for(let e=0;e<3;e++){const r=3*o[n+e];nt[0]=t[r],nt[1]=t[r+1],nt[2]=t[r+2],v(lt,nt)<0&&(t[r]=-t[r],t[r+1]=-t[r+1],t[r+2]=-t[r+2],a=!0)}}return new Le(t,o,a)}function ke(e,t){const r={};for(let n=0;n<t.length;n+=3){const o=ze(e,t,n,lt);for(let e=0;e<3;e++){const a=t[n+e];let s=r[a];s||(s={normal:j(),count:0},r[a]=s),g(s.normal,s.normal,o),s.count++}}const o=F(3*t.length),a=new Array(3*t.length);for(let n=0;n<t.length;n++){const e=r[t[n]];1!==e.count&&(b(e.normal,e.normal),e.count=1);for(let t=0;t<3;t++)o[3*n+t]=e.normal[t];a[n]=n}return new Le(o,a,!1)}function qe(e,t,r,o,a,n){const s=3*t[r],i=3*t[r+1],l=3*t[r+2];o[0]=e[s],o[1]=e[s+1],o[2]=e[s+2],a[0]=e[i],a[1]=e[i+1],a[2]=e[i+2],n[0]=e[l],n[1]=e[l+1],n[2]=e[l+2]}function ze(e,t,r,o){return qe(e,t,r,nt,st,it),w(st,st,nt),w(it,it,nt),M(nt,st,it),b(o,nt),o}function We(e){if(!e)return null;const{scale:r,offset:o,rotation:a}=e;return{scale:r,offset:o,rotation:t(a)}}function Ye(e="repeat"){if("string"==typeof e){const t=Ze(e);return{s:t,t}}return{s:Ze(e.horizontal),t:Ze(e.vertical)}}function Ze(e){switch(e){case"clamp":return Ue.CLAMP_TO_EDGE;case"mirror":return Ue.MIRRORED_REPEAT;default:return Ue.REPEAT}}function Je(e){const t=e.vertexAttributes.color;if(null==t)return!1;for(let r=3;r<t.length;r+=4)if(255!==t[r])return!0;return!1}function Ke(t,r,o){r.diffuse=e.toUnitRGB(t),r.opacity="opaque"===o.alphaMode?1:t.a}function Qe(e){return e.data??e.url}function Xe(t){return null==t?"-":t instanceof e?t.toHex():t.contentHash}function et(e){const{offset:t,scale:r,rotation:o}=e??ot;return`${t[0]},${t[1]},${o},${r[0]},${r[1]}`}function tt(e){return e.vertexAttributes.color}function rt(e){return 1===(e.material?.color?.a??1)}const ot=new $,at=j(),nt=j(),st=j(),it=j(),lt=j(),ct=m(),ut=m(),mt=S(),ft=[new D];var pt;!function(e){e[e.NONE=0]="NONE",e[e.RENDER=1]="RENDER"}(pt||(pt={}));export{Ve as Graphics3DMeshFillSymbolLayer};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{c as e,t,g as i}from"../../../../chunks/vec32.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{setMin as a,setMax as n,create as r,isPoint as o,empty as l,center as c,offset as g}from"../../../../geometry/support/aaBoundingBox.js";import{a as h}from"../../../../chunks/sphere.js";import{evaluateElevationInfoAtPoint as d}from"./elevationAlignmentUtils.js";import{setContextFeature as
|
|
5
|
+
import{c as e,t,g as i}from"../../../../chunks/vec32.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{setMin as a,setMax as n,create as r,isPoint as o,empty as l,center as c,offset as g}from"../../../../geometry/support/aaBoundingBox.js";import{a as h}from"../../../../chunks/sphere.js";import{evaluateElevationInfoAtPoint as d}from"./elevationAlignmentUtils.js";import{setContextFeature as b}from"./featureExpressionInfoUtils.js";import{demResolutionForBoundingBox as u}from"./graphicUtils.js";import{Object3DState as O}from"../../webgl-engine/lib/basicInterfaces.js";import{Transparency as j}from"../../webgl-engine/lib/edgeRendering/interfaces.js";class m{constructor(e,t,i){this.baseMaterial=e,this.edgeMaterial=t,this.hasSlicePlane=i}}class p{get isElevationSource(){return!!this.stageObject.lastValidElevationBB}constructor(e,t,i,s,a,n=null){this.graphics3DSymbolLayer=e,this.stageObject=t,this._sharedResource=i,this.elevationAligner=s,this.elevationContext=a,this._edgeState=n,this.type="object3d",this._stageLayer=null,this._visible=!1,this._addedToStage=!1,this.alignedSampledElevation=0,this.needsElevationUpdates=!1,this.useObjectOriginAsAttachmentOrigin=!1}initialize(e){this._stageLayer=e;e.stage.add(this.stageObject)}destroy(){if(!this._stageLayer)return;const e=this._stageLayer.stage;e.remove(this.stageObject),this._addedToStage&&(this._stageLayer.remove(this.stageObject),this._addedToStage=!1),e.renderer.edgeView?.removeObject(this.stageObject),this.stageObject.dispose(),this._sharedResource?.release(),this._visible=!1,this._stageLayer=null}get usedMemory(){return this.graphics3DSymbolLayer.usedMemory}layerOpacityChanged(e,t){const{stageObject:i,_edgeState:s,_stageLayer:a}=this;if(null==s)return;const n=v(s.baseMaterial);s.edgeMaterial.objectTransparency!==n&&(s.edgeMaterial.objectTransparency=n,this.resetEdgeObject(t)),a.stage.renderer.withEdgeView((t=>t.updateAllComponentOpacities(i,[e])))}updateHighlights(e){}slicePlaneEnabledChanged(e,t){const{stageObject:i,_edgeState:s,_stageLayer:a}=this;null!=s&&a.stage.renderer.withEdgeView((a=>{a.updateAllComponentMaterials(i,s.edgeMaterial,e,!t),s.hasSlicePlane=e}))}setVisibility(e){const{_edgeState:t,stageObject:i,_stageLayer:s}=this;null!=s&&this.visible!==e&&(this._visible=e,i.visible=e,e&&!this._addedToStage&&(s.add(i),this._addedToStage=!0),null!=t&&s.stage.renderer.withEdgeView((s=>{s.hasObject(i)?s.updateObjectVisibility(i,e):e&&this._addOrUpdateEdgeObject(t,s,!1)})))}get visible(){return this._visible}alignWithElevation(e,t,i,s){if(null==this.elevationAligner)return;null!=i&&b(this.elevationContext.featureExpressionInfoContext,i);const a=(i,s)=>d(i,e,this.elevationContext,t,s);this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,e.spatialReference,a,t),this.resetEdgeObject(s)}alignWithAbsoluteElevation(e,t,i){const s=(t,i)=>{i.sampledElevation=e,i.verticalDistanceToGround=0,i.z=e};this.alignedSampledElevation=this.elevationAligner(this,this.elevationContext,null,s,t),this.resetEdgeObject(i)}getCenterObjectSpace(t=s()){return e(t,h(this.stageObject.boundingVolumeObjectSpace.bounds))}getBoundingBoxObjectSpace(e=r()){const t=this.stageObject.boundingVolumeObjectSpace;return a(e,t.min),n(e,t.max),e}computeAttachmentOrigin(e){const s=this.stageObject.effectiveTransformation;if(this.useObjectOriginAsAttachmentOrigin)e.render.origin[0]+=s[12],e.render.origin[1]+=s[13],e.render.origin[2]+=s[14],e.render.num++;else for(const a of this.stageObject.geometries)a.computeAttachmentOrigin(S)&&(t(S,S,s),i(e.render.origin,e.render.origin,S),e.render.num++)}async getProjectedBoundingBox(e,i,s,a,n){const r=this.getBoundingBoxObjectSpace(n),h=_,d=o(r)?1:h.length;for(let o=0;o<d;o++){const e=h[o];y[0]=r[e[0]],y[1]=r[e[1]],y[2]=r[e[2]],t(y,y,this.stageObject.transformation),f[3*o]=y[0],f[3*o+1]=y[1],f[3*o+2]=y[2]}if(!e(f,0,d))return null;l(r);let b=null;this.calculateRelativeScreenBounds&&(b=this.calculateRelativeScreenBounds());for(let t=0;t<3*d;t+=3){for(let e=0;e<3;e++)r[e]=Math.min(r[e],f[t+e]),r[e+3]=Math.max(r[e+3],f[t+e]);b&&s.push({location:f.slice(t,t+3),screenSpaceBoundingRect:b})}if(i?.service&&"absolute-height"!==this.elevationContext.mode){c(r,S);const e="relative-to-scene"===this.elevationContext.mode?"scene":"ground";let t=0;if(i.useViewElevation)t=i.service.getElevation(S[0],S[1],e)??0;else try{const s=u(r,i.service.spatialReference,i);t=await i.service.queryElevation(S[0],S[1],a,s,e)??0}catch(O){}g(r,0,0,-this.alignedSampledElevation+t)}return r}addObjectState(e){e.stateType===O.Highlight&&e.addObject(this.stageObject,this.stageObject.highlight(e.highlightName)),e.stateType===O.MaskOccludee&&e.addObject(this.stageObject,this.stageObject.maskOccludee())}removeObjectState(e){e.removeByObject(this.stageObject)}resetEdgeObject(e){const{_edgeState:t,stageObject:i,_stageLayer:s,_visible:a}=this;null!=t&&s.stage.renderer.withEdgeView((s=>{a?this._addOrUpdateEdgeObject(t,s,e):s.removeObject(i)}))}_addOrUpdateEdgeObject(e,t,i){const s=v(e.baseMaterial);e.edgeMaterial.objectTransparency=s,t.addOrUpdateObject3D(this.stageObject,e.edgeMaterial,e.hasSlicePlane,!i).then((()=>this._stageLayer?.sync()))}}function v(e){return e.transparent?j.TRANSPARENT:j.OPAQUE}const f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],y=s(),S=s(),_=[[0,1,2],[3,1,2],[0,4,2],[3,4,2],[0,1,5],[3,1,5],[0,4,5],[3,4,5]];export{p as Graphics3DObject3DGraphicLayer,m as Object3DEdgeState};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../../Color.js";import{throwIfAborted as t}from"../../../../core/promiseUtils.js";import{pt2px as s}from"../../../../core/screenUtils.js";import{identity as r,scale as i,translate as o,copy as a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{l,v as c,c as h,C as d,g as m,i as p}from"../../../../chunks/vec32.js";import{fromArray as u,ONES as f,ZEROS as y,fromValues as _,create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as b,ZEROS as x,create as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{computeTranslationToOriginAndRotation as R}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectPointToVector as v}from"../../../../geometry/projection/projectPointToVector.js";import{create as L,size as S,containsPoint as C,center as w}from"../../../../geometry/support/aaBoundingBox.js";import{EmissiveSourceMode as U,getEmissiveMode as j}from"../../../../symbols/support/materialUtils.js";import{defaultPrimitive as O}from"../../../../symbols/support/ObjectSymbol3DLayerResource.js";import{objectSymbolLayerPrimitiveBoundingBox as E,objectSymbolLayerSizeWithResourceSize as T}from"../../../../symbols/support/symbolLayerUtils3D.js";import{estimateNumVerticesForLods as B,defaultSymbolLayerMemoryComplexity as G}from"./defaultSymbolComplexity.js";import{perLodInstanceElevationAligner as I}from"./ElevationAligners.js";import{needsElevationUpdates3D as D,evaluateElevationInfoAtPoint as F,SampleElevationInfo as A}from"./elevationAlignmentUtils.js";import{Graphics3DLodInstanceGraphicLayer as z}from"./Graphics3DLodInstanceGraphicLayer.js";import{Graphics3DSymbolLayer as V}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as M,computeObjectScale as k,computeObjectRotation as H}from"./graphicUtils.js";import{ApplyRendererDiffResult as W}from"./interfaces.js";import{LoadStatus as q}from"./Loadable.js";import{makeLodResources as N}from"./lodResourceUtils.js";import{fetch as $}from"./objectResourceUtils.js";import{placePointOnGeometry as Z,extendPointGraphicElevationContext as J}from"./pointUtils.js";import{isValidPrimitive as K,primitiveLodResources as Q}from"./primitiveObjectSymbolUtils.js";import{SymbolComplexity as X}from"./SymbolComplexity.js";import{getResourceUrlFromSymbolStyle as Y}from"./webStyleUtils.js";import{initFastSymbolUpdatesState as ee,updateFastSymbolUpdatesState as te,ConvertOptions as se,evaluateModelTransform as re,evaluateModelTransformScale as ie}from"../support/FastSymbolUpdates.js";import{olidEnabled as oe}from"../../webgl-engine/effects/geometry/olidUtils.js";import{CullFaceOptions as ae}from"../../webgl-engine/lib/basicInterfaces.js";import{VertexAttribute as ne}from"../../webgl-engine/lib/VertexAttribute.js";import{LodRenderer as le}from"../../webgl-engine/lib/lodRendering/LodRenderer.js";import{DefaultMaterial as ce}from"../../webgl-engine/materials/DefaultMaterial.js";import{schematicMRRFactors as he}from"../../webgl-engine/materials/pbrUtils.js";class de{constructor(e,t,s,r,i,o,a,n,l,c,h=null){this.lodResources=e,this.lodRenderer=t,this.stageResources=s,this.resourceSize=r,this.isEsriSymbolResource=i,this.isWosr=o,this.resourceBoundingBox=a,this.symbolSize=n,this.extentPadding=l,this.physicalBasedRenderingEnabled=c,this.pivotOffset=h}}class me extends V{getCachedSize(){const[e,t,s]=null!=this._resources?this._resources.symbolSize:[1,1,1];return{width:e,depth:t,height:s}}constructor(e,t,s,r){super(e,t,s,r,fe(t)),this._resources=null,this._optionalFields=new Array,this._instanceIndexToGraphicUid=new Map,this._hasLoadedPBRTextures=!1,this._disposeResourceHandles=new Array,this.skipHighSymbolLodsChanged=!1,this.ensureDrapedStatus(!1),this._hasLoadedPBRTextures=s.physicalBasedRenderingEnabled}async doLoad(e){if(!this._drivenProperties.size){const e=M(this.symbolLayer);if(e)throw new Error(e)}if(this._isPrimitive){const t=this.symbolLayer.resource,s=t&&K(t?.primitive)?t.primitive:O;this._resources=await this._createResourcesForPrimitive(s,e)}else{const t=await Y(this.symbol.styleOrigin),s=t?.href??this.symbolLayer.resource?.href;this._resources=await this._createResourcesForUrl(s,e)}this.layerOpacityChanged(),this.slicePlaneEnabledChanged(),this.physicalBasedRenderingChanged(),this.updateComplexity()}get extentPadding(){return null!=this._resources?this._resources.extentPadding:0}get _isPrimitive(){return null!=this._primitive}get lodRenderer(){return this._resources?.lodRenderer}get materials(){return this._resources?.stageResources.materials??[]}async _createResourcesForPrimitive(t,r){const i=this.symbolLayer,o=L(E(t)),a=u(S(o)),n=u(T(a,i)),c=l(n),h=!1,d=!1,m=i?.material,p={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,mrrFactors:he,ambient:f,diffuse:f,opacity:1,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:i.castShadows,emissiveStrength:m?.emissive?.strength??0,emissiveSource:U.Color,offsetTransparentBackfaces:!1,drivenOpacity:this.needsDrivenTransparentPass},y=!!p.usePBR,_=m?.color,g=this.symbol;if("point-3d"===g.type&&g.verticalOffset){const{screenLength:e,minWorldLength:t,maxWorldLength:r}=g.verticalOffset;p.verticalOffset={screenLength:s(e),minWorldLength:t||0,maxWorldLength:null!=r?r:1/0},p.castShadows=!1}if(this._context.screenSizePerspectiveEnabled&&(p.screenSizePerspective=this._context.sharedResources.screenSizePerspectiveSettings),this._drivenProperties.color)p.externalColor=b;else{const t=null!=_?e.toUnitRGBA(_):this._drivenProperties.opacity?b:x;p.externalColor=t}this._fastUpdates=ee(this._context.renderer,this._fastVisualVariableConvertOptions(o,n,a,null)),p.isInstanced=!0,this._fastUpdates?(Object.assign(p,this._fastUpdates.materialParameters),this._optionalFields.push(ne.FEATUREATTRIBUTE)):this._hasPerInstanceColor()&&(p.hasInstancedColor=!0,this._optionalFields.push(ne.COLOR)),oe()&&this._optionalFields.push(ne.OLIDCOLOR);const P=new ce(p,this._context);P.setParameters({cullFace:ye(P.transparent)});const R=Q(t,P);if(!R)throw new Error(`Unknown object symbol primitive: ${t}`);const v=await this._createStageResources(R,y,r),C=await this._createLodRenderer(R,r);return new de(R,C,v,a,h,d,o,n,c,y)}async _createResourcesForUrl(e,t){const r={isInstanced:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:this.symbolLayer.castShadows},i={spherical:this._context.spherical,materialParameters:r,streamDataRequester:this._context.streamDataRequester,cache:this._context.sharedResources.objectResourceCache,compressionHandle:this._context.compressionHandle,compressionCallback:()=>this.updateComplexity()};this._fastUpdates=ee(this._context.renderer,this._fastVisualVariableConvertOptions(null,null,null,null)),this._fastUpdates?(Object.assign(i.materialParameters,this._fastUpdates.materialParameters),this._optionalFields.push(ne.FEATUREATTRIBUTE)):this._hasPerInstanceColor()&&(i.materialParameters.hasInstancedColor=!0,this._optionalFields.push(ne.COLOR)),oe()&&this._optionalFields.push(ne.OLIDCOLOR);const o=this.symbol;if("point-3d"===o.type&&o.verticalOffset){const{screenLength:e,minWorldLength:t,maxWorldLength:r}=o.verticalOffset;i.materialParameters.verticalOffset={screenLength:s(e),minWorldLength:t||0,maxWorldLength:null!=r?r:1/0},i.materialParameters.castShadows=!1}const a=this._context.physicalBasedRenderingEnabled;i.signal=t,i.usePBR=a,i.skipHighLods=this._context.skipHighSymbolLods;const n=await $(e,i),c=n.isEsriSymbolResource,h=n.isWosr,d=N(n.lods),m=this._context,p=this.symbolLayer.material,f=this._getExternalColorParameters(p),y=this.needsDrivenTransparentPass,_=d.getMaterials();_.forEach((e=>{e.setParameters({...f,drivenOpacity:y}),m.screenSizePerspectiveEnabled&&e.setParameters({screenSizePerspective:m.sharedResources.screenSizePerspectiveSettings})}));const g=n.referenceBoundingBox,b=u(S(g)),x=u(d.levels[0].pivotOffset),P=u(T(b,this.symbolLayer)),R=l(P),v=this._fastUpdates;te(v,this._context.renderer,this._fastVisualVariableConvertOptions(g,P,b,x))&&_.forEach((e=>e.setParameters(v.materialParameters)));const L=await this._createStageResources(d,a,t),C=await this._createLodRenderer(d,t);return new de(d,C,L,b,c,h,g,P,R,a,x)}_addDisposeResource(e){this._disposeResourceHandles.push(e)}async _createStageResources(e,s,r){const i=this._context.stage,o=e.getMaterials();s!==this._context.physicalBasedRenderingEnabled&&this.physicalBasedRenderingChanged(),i.addMany(o),this._addDisposeResource((()=>i.removeMany(o)));const a=e.getTextures();i.addMany(a),this._addDisposeResource((()=>{a.forEach((e=>e.unload())),i.removeMany(a)})),await Promise.all(a.map((e=>this._context.stage.schedule((()=>e.load(i.renderView.renderingContext)),r)))),t(r);const n=e.getEngineGeometries();return i.addMany(n),this._addDisposeResource((()=>i.removeMany(n))),{materials:o,textures:a,geometries:n}}async _createLodRenderer(e,t){const s=this._context.stage,r={layerViewUid:this._context.layerViewUid,graphicUid:e=>this._instanceIndexToGraphicUid.get(e),notifyGraphicGeometryChanged:e=>this._context.notifyGraphicGeometryChanged(this._instanceIndexToGraphicUid.get(e)),notifyGraphicVisibilityChanged:e=>this._context.notifyGraphicVisibilityChanged(this._instanceIndexToGraphicUid.get(e))},i=this._fastUpdates,o=i?{applyTransform:(e,t,s)=>{e.getFeatureAttribute(t,xe),a(s,re(i.materialParameters,xe,s))},scaleFactor:(e,t,s)=>{t.getFeatureAttribute(s,xe),ie(e,i.materialParameters,xe)}}:null,n=new le({symbol:e,optionalFields:this._optionalFields,metadata:r,shaderTransformation:o},this._context.scheduler);return n.slicePlaneEnabled=this._context.slicePlaneEnabled,this._addDisposeResource((()=>{s.removeRenderPlugin(n),n.destroy()})),await s.addRenderPlugin(n,t),n}_getExternalColorParameters(t){const s={};return this._drivenProperties.color?s.externalColor=b:null!=t?.color?s.externalColor=e.toUnitRGBA(t.color):(s.externalColor=b,s.colorMixMode="ignore"),s.emissiveStrength=t?.emissive?.strength??1,s.emissiveSource=j(t?.emissive?.source??"emissive"),s}destroy(){super.destroy(),this._cleanupResources()}_cleanupResources(){this._disposeResourceHandles.forEach((e=>e())),this._disposeResourceHandles.length=0,this._resources=null}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry))return null;const s=Z(t.geometry);if(null==s)return this.logger.warn(`unsupported geometry type for object symbol: ${t.geometry.type}`),null;const r=this.setGraphicElevationContext(t),i=e.renderingInfo;return this._createAs3DShape(t,s,i,r,t.uid)}notifyDestroyGraphicLayer(e){this._instanceIndexToGraphicUid.delete(e.instanceIndex)}graphicLayerToGraphicId(){return 0}layerOpacityChanged(){if(null==this._resources)return;const e=this._getLayerOpacity(),t=this._resources.stageResources.materials;for(let s=0;s<t.length;s++){const r=t[s];r.setParameters({layerOpacity:e}),this._isPrimitive&&r.setParameters({cullFace:ye(r.transparent)})}}layerElevationInfoChanged(e,t){return this.updateGraphics3DGraphicElevationInfo(e,t,D)}slicePlaneEnabledChanged(){if(null==this._resources)return!0;this._resources.lodRenderer.slicePlaneEnabled=this._context.slicePlaneEnabled;for(const e of this._resources.stageResources.materials)e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled});return!0}physicalBasedRenderingChanged(){if(null==this._resources)return!0;const{stageResources:e,isWosr:t}=this._resources;for(const s of e.materials)this._isPrimitive?s.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0}):t||s.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!1});return!1!==this._hasLoadedPBRTextures||!0!==this._context.physicalBasedRenderingEnabled||(this._hasLoadedPBRTextures=!0,!1)}applyRendererDiff(e,t){if(null==this._resources)return W.RecreateSymbol;const{stageResources:{materials:s},lodRenderer:r,resourceBoundingBox:i,symbolSize:o,resourceSize:a,pivotOffset:n}=this._resources;for(const l in e.diff){if("visualVariables"!==l)return W.RecreateSymbol;if(!te(this._fastUpdates,t,this._fastVisualVariableConvertOptions(i,o,a,n)))return W.RecreateSymbol;for(const e of s)e.setParameters(this._fastUpdates.materialParameters);r.notifyShaderTransformationChanged()}return W.FastUpdate}computeComplexity(){if(null==this._resources)return super.computeComplexity();const e=this._resources.lodResources,t=B(e.levels),s=e.computeUsedMemory(),r={...G(this.symbol,this.symbolLayer),resourceBytes:s};return new X({verticesPerFeature:t,memory:r})}_hasLodRenderer(){return null!=this._resources}_createAs3DShape(e,t,s,r,i){if(!this._hasLodRenderer()||null==this._resources)return null;const o=this.getFastUpdateAttrValues(e),a=this._context.clippingExtent;if(v(t,_e,this._context.elevationProvider.spatialReference),null!=a&&!C(a,_e))return null;const n=ue(r),l=this._computeGlobalTransform(t,r,be,Pe),c=this._computeLocalTransform(this._resources,this.symbolLayer,s,ge),h=this._resources.lodRenderer.instanceData,d=h.addInstance();if(this._instanceIndexToGraphicUid.set(d,i),h.setLocalTransform(d,c,!1),h.setGlobalTransform(d,l),o&&h.setFeatureAttribute(d,o),null==this._fastUpdates&&this._hasPerInstanceColor()){const e=this._getVertexOpacityAndColor(s,this._getFallbackOpacityAndColor(),255);h.setColor(d,e)}const m=this._context.stage.renderView.olidRenderHelper;if(m){const e=m.getObjectAndLayerIdColor({graphicUid:i,layerViewUid:this._context.layerViewUid});h.setObjectAndLayerIdColor(d,e)}const p=new z(this,d,I,r,this._context.stage.view.state.highlightOrderMap);return n&&(p.alignedSampledElevation=Pe.sampledElevation),p.needsElevationUpdates=D(r.mode),J(p,t,this._context.elevationProvider),p}_computeGlobalTransform(e,t,s,r){return F(e,this._context.elevationProvider,t,this._context.renderCoordsHelper,r),_e[0]=e.x,_e[1]=e.y,_e[2]=r.z,R(e.spatialReference,_e,s,this._context.renderCoordsHelper.spatialReference),s}_computeLocalTransform(e,t,s,i){return r(i),this._applyObjectRotation(s,!1,i),this._applyObjectRotation(t,!0,i),this._applyObjectScale(e,s,i),this._applyAnchor(e,t,i),i}_applyObjectScale(e,t,s){if(this._fastUpdates?.requiresShaderTransformation)return;const r=this._drivenProperties.size&&t.size?t.size:e.symbolSize,o=k(r,e.symbolSize,e.resourceSize,this._context.renderCoordsHelper.unitInMeters);1===o[0]&&1===o[1]&&1===o[2]||i(s,s,o)}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchTransform(e,t),this._preparePatchColor(e,t)}updateGeometry(e,t){if(null==this._resources)return!0;const s=t&&Z(t);if(null==s)return!1;const r=this.getGeometryElevationMode(t);return e.elevationContext.mode===r&&(this._computeGlobalTransform(s,e.elevationContext,be,Pe),ue(e.elevationContext)&&(e.alignedSampledElevation=Pe.sampledElevation),this._resources.lodRenderer.instanceData.setGlobalTransform(e.instanceIndex,be,!0),J(e,s,this._context.elevationProvider),!0)}_preparePatchTransform(e,t){if(!(t.heading||t.tilt||t.roll||t.width||t.height||t.depth||t.anchor||t.anchorPosition))return;if(null==this._resources)return;const s=(e,t,s)=>(null!=e&&"complete"===e.type?e.newValue:t)??s,r=s(t.heading,this.symbolLayer.heading,0),i=s(t.tilt,this.symbolLayer.tilt,0),o=s(t.roll,this.symbolLayer.roll,0),a=s(t.width,this.symbolLayer.width,void 0),n=s(t.height,this.symbolLayer.height,void 0),l=s(t.depth,this.symbolLayer.depth,void 0),c=s(t.anchor,this.symbolLayer.anchor,void 0),h=s(t.anchorPosition,this.symbolLayer.anchorPosition,void 0);delete t.heading,delete t.tilt,delete t.roll,delete t.width,delete t.height,delete t.depth,delete t.anchor,delete t.anchorPosition;const d={heading:r,tilt:i,roll:o,anchor:c,anchorPosition:h},m=this._resources;this.loadStatus===q.LOADED&&e.symbolLayerStatePatches.push((()=>{m.symbolSize=u(T(m.resourceSize,{width:a,height:n,depth:l,isPrimitive:this._isPrimitive}))})),e.graphics3DGraphicPatches.push((({instanceIndex:e},t)=>{const s=this._computeLocalTransform(m,d,t,ge);m.lodRenderer.instanceData.setLocalTransform(e,s,!0)}))}_preparePatchColor(t,s){if(!s.material||"partial"!==s.material.type)return;const r=s.material.diff;if(!r.color||"complete"!==r.color.type||null==r.color.newValue||null==r.color.oldValue)return;const i=r.color.newValue,o=null!=i?e.toUnitRGBA(i):b;delete r.color;const a=this._resources;if(null==a)return;const n=this._isPrimitive;t.graphics3DGraphicPatches.push((({instanceIndex:e})=>{if(this._hasPerInstanceColor())a.lodRenderer.instanceData.setColor(e,o);else{const e={externalColor:o};for(const t of a.stageResources.materials)t.setParameters(e),n&&t.setParameters({cullFace:ye(t.transparent)})}}))}_applyObjectRotation(e,t,s){if(!this._fastUpdates?.requiresShaderTransformation||!t)return H(e.heading,e.tilt,e.roll,s)}_applyAnchor(e,t,s){if(this._fastUpdates?.requiresShaderTransformation)return;const r=pe(e.resourceBoundingBox,e.pivotOffset,t);r&&o(s,s,r)}_hasPerInstanceColor(){return this._drivenProperties.color||this._drivenProperties.opacity}_fastVisualVariableConvertOptions(e,t,s,r){const i=null!=e?u(S(e)):f,o=null!=e?pe(e,r,this.symbolLayer):y,a=this._context.renderCoordsHelper.unitInMeters,n=k(null!=t?t:void 0,t,s,a),l=_(this.symbolLayer.tilt||0,this.symbolLayer.roll||0,this.symbolLayer.heading||0);return new se({supports:{size:!0,color:!0,rotation:!0,opacity:!1},modelSize:i,symbolSize:t??f,unitInMeters:a,anchor:o,scale:n,rotation:l,fallbackColor:this._getFallbackOpacityAndColor(),fallbackSize:n})}get _primitive(){const{resource:e}=this.symbolLayer;return null!=e?.href?null:e?.primitive??O}_getFallbackOpacityAndColor(){const t=this.symbolLayer.material?.color;if(null==t){return null==this._primitive?b:x}return e.toUnitRGBA(t)}}function pe(e,t,s){const r=g();switch(s.anchor){case"center":h(r,w(e)),c(r,r);break;case"top":{const t=w(e);p(r,-t[0],-t[1],-e[5]);break}case"bottom":{const t=w(e);p(r,-t[0],-t[1],-e[2]);break}case"relative":{const t=w(e),i=S(e),o=s.anchorPosition,a=o?_(o.x,o.y,o.z):y;d(r,i,a),m(r,r,t),c(r,r);break}default:null!=t?c(r,t):h(r,y)}return r}function ue(e){return"absolute-height"!==e.mode}function fe(e){return 1===(e.material?.color?.a??1)&&null==e.resource?.href}function ye(e){return e?ae.None:ae.Back}const _e=g(),ge=n(),be=n(),xe=P(),Pe=new A;export{me as Graphics3DObjectSymbolLayer};
|
|
5
|
+
import e from"../../../../Color.js";import{throwIfAborted as t}from"../../../../core/promiseUtils.js";import{pt2px as s}from"../../../../core/screenUtils.js";import{identity as r,scale as i,translate as o,copy as a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{l,v as c,c as h,C as d,g as m,i as p}from"../../../../chunks/vec32.js";import{fromArray as u,ONES as f,ZEROS as y,fromValues as _,create as g}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{ONES as b,ZEROS as x,create as P}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{computeTranslationToOriginAndRotation as R}from"../../../../geometry/projection/computeTranslationToOriginAndRotation.js";import{projectPointToVector as v}from"../../../../geometry/projection/projectPointToVector.js";import{create as L,size as S,containsPoint as C,center as w}from"../../../../geometry/support/aaBoundingBox.js";import{EmissiveSourceMode as U,getEmissiveMode as j}from"../../../../symbols/support/materialUtils.js";import{defaultPrimitive as O}from"../../../../symbols/support/ObjectSymbol3DLayerResource.js";import{objectSymbolLayerPrimitiveBoundingBox as E,objectSymbolLayerSizeWithResourceSize as T}from"../../../../symbols/support/symbolLayerUtils3D.js";import{estimateNumVerticesForLods as B,defaultSymbolLayerMemoryComplexity as G}from"./defaultSymbolComplexity.js";import{perLodInstanceElevationAligner as I}from"./ElevationAligners.js";import{needsElevationUpdates3D as F,evaluateElevationInfoAtPoint as A,SampleElevationInfo as D}from"./elevationAlignmentUtils.js";import{Graphics3DLodInstanceGraphicLayer as z}from"./Graphics3DLodInstanceGraphicLayer.js";import{Graphics3DSymbolLayer as V}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as k,computeObjectScale as H,computeObjectRotation as M}from"./graphicUtils.js";import{ApplyRendererDiffResult as W}from"./interfaces.js";import{LoadStatus as q}from"./Loadable.js";import{makeLodResources as N}from"./lodResourceUtils.js";import{fetch as $}from"./objectResourceUtils.js";import{placePointOnGeometry as Z,extendPointGraphicElevationContext as J}from"./pointUtils.js";import{isValidPrimitive as K,primitiveLodResources as Q}from"./primitiveObjectSymbolUtils.js";import{SymbolComplexity as X}from"./SymbolComplexity.js";import{getResourceUrlFromSymbolStyle as Y}from"./webStyleUtils.js";import{initFastSymbolUpdatesState as ee,updateFastSymbolUpdatesState as te,ConvertOptions as se,evaluateModelTransform as re,evaluateModelTransformScale as ie}from"../support/FastSymbolUpdates.js";import{olidEnabled as oe}from"../../webgl-engine/effects/geometry/olidUtils.js";import{CullFaceOptions as ae}from"../../webgl-engine/lib/basicInterfaces.js";import{VertexAttribute as ne}from"../../webgl-engine/lib/VertexAttribute.js";import{LodRenderer as le}from"../../webgl-engine/lib/lodRendering/LodRenderer.js";import{DefaultMaterial as ce}from"../../webgl-engine/materials/DefaultMaterial.js";import{schematicMRRFactors as he}from"../../webgl-engine/materials/pbrUtils.js";class de{constructor(e,t,s,r,i,o,a,n,l,c,h=null){this.lodResources=e,this.lodRenderer=t,this.stageResources=s,this.resourceSize=r,this.isEsriSymbolResource=i,this.isWosr=o,this.resourceBoundingBox=a,this.symbolSize=n,this.extentPadding=l,this.physicalBasedRenderingEnabled=c,this.pivotOffset=h}}class me extends V{getCachedSize(){const[e,t,s]=null!=this._resources?this._resources.symbolSize:[1,1,1];return{width:e,depth:t,height:s}}constructor(e,t,s,r){super(e,t,s,r,fe(t)),this._resources=null,this._optionalFields=new Array,this._instanceIndexToGraphicUid=new Map,this._hasLoadedPBRTextures=!1,this._disposeResourceHandles=new Array,this.skipHighSymbolLodsChanged=!1,this.ensureDrapedStatus(!1),this._hasLoadedPBRTextures=s.physicalBasedRenderingEnabled}async doLoad(e){if(!this._drivenProperties.size){const e=k(this.symbolLayer);if(e)throw new Error(e)}if(this._isPrimitive){const t=this.symbolLayer.resource,s=t&&K(t?.primitive)?t.primitive:O;this._resources=await this._createResourcesForPrimitive(s,e)}else{const t=await Y(this.symbol.styleOrigin),s=t?.href??this.symbolLayer.resource?.href;this._resources=await this._createResourcesForUrl(s,e)}this.layerOpacityChanged(),this.slicePlaneEnabledChanged(),this.physicalBasedRenderingChanged(),this.updateComplexity()}get extentPadding(){return null!=this._resources?this._resources.extentPadding:0}get _isPrimitive(){return null!=this._primitive}get lodRenderer(){return this._resources?.lodRenderer}get materials(){return this._resources?.stageResources.materials??[]}async _createResourcesForPrimitive(t,r){const i=this.symbolLayer,o=L(E(t)),a=u(S(o)),n=u(T(a,i)),c=l(n),h=!1,d=!1,m=i?.material,p={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,mrrFactors:he,ambient:f,diffuse:f,opacity:1,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:i.castShadows,emissiveStrength:m?.emissive?.strength??0,emissiveSource:U.Color,offsetTransparentBackfaces:!1,drivenOpacity:this.needsDrivenTransparentPass},y=!!p.usePBR,_=m?.color,g=this.symbol;if("point-3d"===g.type&&g.verticalOffset){const{screenLength:e,minWorldLength:t,maxWorldLength:r}=g.verticalOffset;p.verticalOffset={screenLength:s(e),minWorldLength:t||0,maxWorldLength:null!=r?r:1/0},p.castShadows=!1}if(this._context.screenSizePerspectiveEnabled&&(p.screenSizePerspective=this._context.sharedResources.screenSizePerspectiveSettings),this._drivenProperties.color)p.externalColor=b;else{const t=null!=_?e.toUnitRGBA(_):this._drivenProperties.opacity?b:x;p.externalColor=t}this._fastUpdates=ee(this._context.renderer,this._fastVisualVariableConvertOptions(o,n,a,null)),p.isInstanced=!0,this._fastUpdates?(Object.assign(p,this._fastUpdates.materialParameters),this._optionalFields.push(ne.FEATUREATTRIBUTE)):this._hasPerInstanceColor()&&(p.hasInstancedColor=!0,this._optionalFields.push(ne.COLOR)),oe()&&this._optionalFields.push(ne.OLIDCOLOR);const P=new ce(p,this._context);P.setParameters({cullFace:ye(P.transparent)});const R=Q(t,P);if(!R)throw new Error(`Unknown object symbol primitive: ${t}`);const v=await this._createStageResources(R,y,r),C=await this._createLodRenderer(R,r);return new de(R,C,v,a,h,d,o,n,c,y)}async _createResourcesForUrl(e,t){const r={isInstanced:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:this.symbolLayer.castShadows},i={spherical:this._context.spherical,materialParameters:r,streamDataRequester:this._context.streamDataRequester,cache:this._context.sharedResources.objectResourceCache,compressionHandle:this._context.compressionHandle,compressionCallback:()=>this.updateComplexity()};this._fastUpdates=ee(this._context.renderer,this._fastVisualVariableConvertOptions(null,null,null,null)),this._fastUpdates?(Object.assign(i.materialParameters,this._fastUpdates.materialParameters),this._optionalFields.push(ne.FEATUREATTRIBUTE)):this._hasPerInstanceColor()&&(i.materialParameters.hasInstancedColor=!0,this._optionalFields.push(ne.COLOR)),oe()&&this._optionalFields.push(ne.OLIDCOLOR);const o=this.symbol;if("point-3d"===o.type&&o.verticalOffset){const{screenLength:e,minWorldLength:t,maxWorldLength:r}=o.verticalOffset;i.materialParameters.verticalOffset={screenLength:s(e),minWorldLength:t||0,maxWorldLength:null!=r?r:1/0},i.materialParameters.castShadows=!1}const a=this._context.physicalBasedRenderingEnabled;i.signal=t,i.usePBR=a,i.skipHighLods=this._context.skipHighSymbolLods;const n=await $(e,i),c=n.isEsriSymbolResource,h=n.isWosr,d=N(n.lods),m=this._context,p=this.symbolLayer.material,f=this._getExternalColorParameters(p),y=this.needsDrivenTransparentPass,_=d.getMaterials();_.forEach((e=>{e.setParameters({...f,drivenOpacity:y}),m.screenSizePerspectiveEnabled&&e.setParameters({screenSizePerspective:m.sharedResources.screenSizePerspectiveSettings})}));const g=n.referenceBoundingBox,b=u(S(g)),x=u(d.levels[0].pivotOffset),P=u(T(b,this.symbolLayer)),R=l(P),v=this._fastUpdates;te(v,this._context.renderer,this._fastVisualVariableConvertOptions(g,P,b,x))&&_.forEach((e=>e.setParameters(v.materialParameters)));const L=await this._createStageResources(d,a,t),C=await this._createLodRenderer(d,t);return new de(d,C,L,b,c,h,g,P,R,a,x)}_addDisposeResource(e){this._disposeResourceHandles.push(e)}async _createStageResources(e,s,r){const i=this._context.stage,o=e.getMaterials();s!==this._context.physicalBasedRenderingEnabled&&this.physicalBasedRenderingChanged();const a=e.getTextures();i.addMany(a),this._addDisposeResource((()=>{a.forEach((e=>e.unload())),i.removeMany(a)})),await Promise.all(a.map((e=>this._context.stage.schedule((()=>e.load(i.renderView.renderingContext)),r)))),t(r);const n=e.getEngineGeometries();return{materials:o,textures:a,geometries:n}}async _createLodRenderer(e,t){const s=this._context.stage,r={layerViewUid:this._context.layerViewUid,graphicUid:e=>this._instanceIndexToGraphicUid.get(e),notifyGraphicGeometryChanged:e=>this._context.notifyGraphicGeometryChanged(this._instanceIndexToGraphicUid.get(e)),notifyGraphicVisibilityChanged:e=>this._context.notifyGraphicVisibilityChanged(this._instanceIndexToGraphicUid.get(e))},i=this._fastUpdates,o=i?{applyTransform:(e,t,s)=>{e.getFeatureAttribute(t,xe),a(s,re(i.materialParameters,xe,s))},scaleFactor:(e,t,s)=>{t.getFeatureAttribute(s,xe),ie(e,i.materialParameters,xe)}}:null,n=new le({symbol:e,optionalFields:this._optionalFields,metadata:r,shaderTransformation:o},this._context.scheduler);return n.slicePlaneEnabled=this._context.slicePlaneEnabled,this._addDisposeResource((()=>{s.removeRenderPlugin(n),n.destroy()})),await s.addRenderPlugin(n,t),n}_getExternalColorParameters(t){const s={};return this._drivenProperties.color?s.externalColor=b:null!=t?.color?s.externalColor=e.toUnitRGBA(t.color):(s.externalColor=b,s.colorMixMode="ignore"),s.emissiveStrength=t?.emissive?.strength??1,s.emissiveSource=j(t?.emissive?.source??"emissive"),s}destroy(){super.destroy(),this._cleanupResources()}_cleanupResources(){this._disposeResourceHandles.forEach((e=>e())),this._disposeResourceHandles.length=0,this._resources=null}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry))return null;const s=Z(t.geometry);if(null==s)return this.logger.warn(`unsupported geometry type for object symbol: ${t.geometry.type}`),null;const r=this.setGraphicElevationContext(t),i=e.renderingInfo;return this._createAs3DShape(t,s,i,r,t.uid)}notifyDestroyGraphicLayer(e){this._instanceIndexToGraphicUid.delete(e.instanceIndex)}graphicLayerToGraphicId(){return 0}layerOpacityChanged(){if(null==this._resources)return;const e=this._getLayerOpacity(),t=this._resources.stageResources.materials;for(let s=0;s<t.length;s++){const r=t[s];r.setParameters({layerOpacity:e}),this._isPrimitive&&r.setParameters({cullFace:ye(r.transparent)})}}layerElevationInfoChanged(e,t){return this.updateGraphics3DGraphicElevationInfo(e,t,F)}slicePlaneEnabledChanged(){if(null==this._resources)return!0;this._resources.lodRenderer.slicePlaneEnabled=this._context.slicePlaneEnabled;for(const e of this._resources.stageResources.materials)e.setParameters({hasSlicePlane:this._context.slicePlaneEnabled});return!0}physicalBasedRenderingChanged(){if(null==this._resources)return!0;const{stageResources:e,isWosr:t}=this._resources;for(const s of e.materials)this._isPrimitive?s.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0}):t||s.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!1});return!1!==this._hasLoadedPBRTextures||!0!==this._context.physicalBasedRenderingEnabled||(this._hasLoadedPBRTextures=!0,!1)}applyRendererDiff(e,t){if(null==this._resources)return W.RecreateSymbol;const{stageResources:{materials:s},lodRenderer:r,resourceBoundingBox:i,symbolSize:o,resourceSize:a,pivotOffset:n}=this._resources;for(const l in e.diff){if("visualVariables"!==l)return W.RecreateSymbol;if(!te(this._fastUpdates,t,this._fastVisualVariableConvertOptions(i,o,a,n)))return W.RecreateSymbol;for(const e of s)e.setParameters(this._fastUpdates.materialParameters);r.notifyShaderTransformationChanged()}return W.FastUpdate}computeComplexity(){if(null==this._resources)return super.computeComplexity();const e=this._resources.lodResources,t=B(e.levels),s=e.computeUsedMemory(),r={...G(this.symbol,this.symbolLayer),resourceBytes:s};return new X({verticesPerFeature:t,memory:r})}_hasLodRenderer(){return null!=this._resources}_createAs3DShape(e,t,s,r,i){if(!this._hasLodRenderer()||null==this._resources)return null;const o=this.getFastUpdateAttrValues(e),a=this._context.clippingExtent;if(v(t,_e,this._context.elevationProvider.spatialReference),null!=a&&!C(a,_e))return null;const n=ue(r),l=this._computeGlobalTransform(t,r,be,Pe),c=this._computeLocalTransform(this._resources,this.symbolLayer,s,ge),h=this._resources.lodRenderer.instanceData,d=h.addInstance();if(this._instanceIndexToGraphicUid.set(d,i),h.setLocalTransform(d,c,!1),h.setGlobalTransform(d,l),o&&h.setFeatureAttribute(d,o),null==this._fastUpdates&&this._hasPerInstanceColor()){const e=this._getVertexOpacityAndColor(s,this._getFallbackOpacityAndColor(),255);h.setColor(d,e)}const m=this._context.stage.renderView.olidRenderHelper;if(m){const e=m.getObjectAndLayerIdColor({graphicUid:i,layerViewUid:this._context.layerViewUid});h.setObjectAndLayerIdColor(d,e)}const p=new z(this,d,I,r,this._context.stage.view.state.highlightOrderMap);return n&&(p.alignedSampledElevation=Pe.sampledElevation),p.needsElevationUpdates=F(r.mode),J(p,t,this._context.elevationProvider),p}_computeGlobalTransform(e,t,s,r){return A(e,this._context.elevationProvider,t,this._context.renderCoordsHelper,r),_e[0]=e.x,_e[1]=e.y,_e[2]=r.z,R(e.spatialReference,_e,s,this._context.renderCoordsHelper.spatialReference),s}_computeLocalTransform(e,t,s,i){return r(i),this._applyObjectRotation(s,!1,i),this._applyObjectRotation(t,!0,i),this._applyObjectScale(e,s,i),this._applyAnchor(e,t,i),i}_applyObjectScale(e,t,s){if(this._fastUpdates?.requiresShaderTransformation)return;const r=this._drivenProperties.size&&t.size?t.size:e.symbolSize,o=H(r,e.symbolSize,e.resourceSize,this._context.renderCoordsHelper.unitInMeters);1===o[0]&&1===o[1]&&1===o[2]||i(s,s,o)}prepareSymbolLayerPatch(e){if("partial"!==e.diff.type)return;const t=e.diff.diff;this._preparePatchTransform(e,t),this._preparePatchColor(e,t)}updateGeometry(e,t){if(null==this._resources)return!0;const s=t&&Z(t);if(null==s)return!1;const r=this.getGeometryElevationMode(t);return e.elevationContext.mode===r&&(this._computeGlobalTransform(s,e.elevationContext,be,Pe),ue(e.elevationContext)&&(e.alignedSampledElevation=Pe.sampledElevation),this._resources.lodRenderer.instanceData.setGlobalTransform(e.instanceIndex,be,!0),J(e,s,this._context.elevationProvider),!0)}_preparePatchTransform(e,t){if(!(t.heading||t.tilt||t.roll||t.width||t.height||t.depth||t.anchor||t.anchorPosition))return;if(null==this._resources)return;const s=(e,t,s)=>(null!=e&&"complete"===e.type?e.newValue:t)??s,r=s(t.heading,this.symbolLayer.heading,0),i=s(t.tilt,this.symbolLayer.tilt,0),o=s(t.roll,this.symbolLayer.roll,0),a=s(t.width,this.symbolLayer.width,void 0),n=s(t.height,this.symbolLayer.height,void 0),l=s(t.depth,this.symbolLayer.depth,void 0),c=s(t.anchor,this.symbolLayer.anchor,void 0),h=s(t.anchorPosition,this.symbolLayer.anchorPosition,void 0);delete t.heading,delete t.tilt,delete t.roll,delete t.width,delete t.height,delete t.depth,delete t.anchor,delete t.anchorPosition;const d={heading:r,tilt:i,roll:o,anchor:c,anchorPosition:h},m=this._resources;this.loadStatus===q.LOADED&&e.symbolLayerStatePatches.push((()=>{m.symbolSize=u(T(m.resourceSize,{width:a,height:n,depth:l,isPrimitive:this._isPrimitive}))})),e.graphics3DGraphicPatches.push((({instanceIndex:e},t)=>{const s=this._computeLocalTransform(m,d,t,ge);m.lodRenderer.instanceData.setLocalTransform(e,s,!0)}))}_preparePatchColor(t,s){if(!s.material||"partial"!==s.material.type)return;const r=s.material.diff;if(!r.color||"complete"!==r.color.type||null==r.color.newValue||null==r.color.oldValue)return;const i=r.color.newValue,o=null!=i?e.toUnitRGBA(i):b;delete r.color;const a=this._resources;if(null==a)return;const n=this._isPrimitive;t.graphics3DGraphicPatches.push((({instanceIndex:e})=>{if(this._hasPerInstanceColor())a.lodRenderer.instanceData.setColor(e,o);else{const e={externalColor:o};for(const t of a.stageResources.materials)t.setParameters(e),n&&t.setParameters({cullFace:ye(t.transparent)})}}))}_applyObjectRotation(e,t,s){if(!this._fastUpdates?.requiresShaderTransformation||!t)return M(e.heading,e.tilt,e.roll,s)}_applyAnchor(e,t,s){if(this._fastUpdates?.requiresShaderTransformation)return;const r=pe(e.resourceBoundingBox,e.pivotOffset,t);r&&o(s,s,r)}_hasPerInstanceColor(){return this._drivenProperties.color||this._drivenProperties.opacity}_fastVisualVariableConvertOptions(e,t,s,r){const i=null!=e?u(S(e)):f,o=null!=e?pe(e,r,this.symbolLayer):y,a=this._context.renderCoordsHelper.unitInMeters,n=H(null!=t?t:void 0,t,s,a),l=_(this.symbolLayer.tilt||0,this.symbolLayer.roll||0,this.symbolLayer.heading||0);return new se({supports:{size:!0,color:!0,rotation:!0,opacity:!1},modelSize:i,symbolSize:t??f,unitInMeters:a,anchor:o,scale:n,rotation:l,fallbackColor:this._getFallbackOpacityAndColor(),fallbackSize:n})}get _primitive(){const{resource:e}=this.symbolLayer;return null!=e?.href?null:e?.primitive??O}_getFallbackOpacityAndColor(){const t=this.symbolLayer.material?.color;if(null==t){return null==this._primitive?b:x}return e.toUnitRGBA(t)}}function pe(e,t,s){const r=g();switch(s.anchor){case"center":h(r,w(e)),c(r,r);break;case"top":{const t=w(e);p(r,-t[0],-t[1],-e[5]);break}case"bottom":{const t=w(e);p(r,-t[0],-t[1],-e[2]);break}case"relative":{const t=w(e),i=S(e),o=s.anchorPosition,a=o?_(o.x,o.y,o.z):y;d(r,i,a),m(r,r,t),c(r,r);break}default:null!=t?c(r,t):h(r,y)}return r}function ue(e){return"absolute-height"!==e.mode}function fe(e){return 1===(e.material?.color?.a??1)&&null==e.resource?.href}function ye(e){return e?ae.None:ae.Back}const _e=g(),ge=n(),be=n(),xe=P(),Pe=new D;export{me as Graphics3DObjectSymbolLayer};
|