@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 7.75 kB
JavaScript
import e from"../../../../core/Evented.js";import{isSome as t,toNullable as r,isNone as i}from"../../../../core/maybe.js";import{s,a,g as n}from"../../../../chunks/vec3.js";import{c as o}from"../../../../chunks/vec3f64.js";import{g as l,c as h,s as c}from"../../../../chunks/vec4.js";import{f as d,c as p}from"../../../../chunks/vec4f32.js";import{projectBuffer as m}from"../../../../geometry/projection.js";import{create as u,empty as _,expandWithBuffer as f}from"../../../../geometry/support/aaBoundingBox.js";import{makeDehydratedPoint as g}from"../../../../layers/graphics/dehydratedFeatures.js";import{getGeometryEffectiveElevationMode as y}from"../../../../support/elevationInfoUtils.js";import O from"../../../../symbols/support/ElevationInfo.js";import{EngineVisualElement as b}from"./EngineVisualElement.js";import{LaserlineVisualElement as v}from"./LaserlineVisualElement.js";import{ElevationContext as R}from"../../layers/graphics/ElevationContext.js";import{createGeometry as C}from"../../support/engineContent/line.js";import{geometryToRenderInfoDraped as w,geometryToRenderInfo as j}from"../../support/renderInfoUtils/line.js";import{newDoubleArray as P}from"../../webgl-engine/lib/DoubleArray.js";import{RenderOccludedFlag as E}from"../../webgl-engine/lib/Material.js";import{RenderGeometry as D}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as A}from"../../webgl-engine/lib/VertexAttribute.js";import{RibbonLineMaterial as G}from"../../webgl-engine/materials/RibbonLineMaterial.js";class I extends b{constructor(t){super(t),this._attachmentOrigin=g(0,0,0,null),this._attachmentOriginDirty=!0,this.events=new e,this._geometry=null,this._width=1,this._color=d(1,0,1,1),this._innerWidth=0,this._innerColor=d(1,1,1,1),this._stipplePattern=null,this._stippleOffColor=null,this._falloff=0,this._elevationInfo=null,this._laserlineStyle=null,this._laserlineEnabled=!1,this._renderOccluded=E.OccludeAndTransparentStencil,this._attachmentOrigin.spatialReference=t.view.spatialReference,this._laserline=new v({view:t.view}),this.applyProps(t),this.attached=t.attached??!0}destroy(){this._laserline.destroy(),super.destroy()}createObject3DResourceFactory(e){return{view:e,createResources:e=>this._createObject3DResources(e),destroyResources:e=>this._destroyExternalResources(e),recreateGeometry:(e,t)=>{e.geometries.length=0,this._recreateGeometry(t,e.material,e.geometries)}}}createDrapedResourceFactory(e){return{view:e,createResources:()=>this._createDrapedResources(),destroyResources:e=>this._destroyExternalResources(e),recreateGeometry:e=>{e.geometries=this._createRenderGeometriesDraped(e.material),this._attachmentOriginChanged()}}}get _laserlineAttached(){return this.attached&&this.visible&&t(this._laserlineStyle)&&!this.isDraped&&this.laserlineEnabled}onAttachedChange(e){this._laserline.attached=this._laserlineAttached,e&&this._attachmentOriginChanged()}get geometry(){return this._geometry}set geometry(e){this._geometry=e,this.recreateGeometry()}get width(){return this._width}set width(e){e!==this._width&&(this._width=e,this._updateMaterial())}get color(){return this._color}set color(e){l(e,this._color)||(h(this._color,e),this._updateMaterial())}get innerWidth(){return this._innerWidth}set innerWidth(e){e!==this._innerWidth&&(this._innerWidth=e,this._updateMaterial())}get innerColor(){return this._innerColor}set innerColor(e){l(e,this._innerColor)||(h(this._innerColor,e),this._updateMaterial())}get stipplePattern(){return this._stipplePattern}set stipplePattern(e){const r=t(e)!==t(this._stipplePattern);this._stipplePattern=e,r?this.recreate():this._updateMaterial()}get stippleOffColor(){return this._stippleOffColor}set stippleOffColor(e){e&&this._stippleOffColor&&l(e,this._stippleOffColor)||(this._stippleOffColor=e?p(e):null,this._updateMaterial())}get falloff(){return this._falloff}set falloff(e){e!==this._falloff&&(this._falloff=e,this._updateMaterial())}get elevationInfo(){return this._elevationInfo}set elevationInfo(e){this._elevationInfo=e,this.recreateGeometry()}get laserlineStyle(){return this._laserlineStyle}set laserlineStyle(e){this._laserlineStyle=e,this._laserline.attached=this._laserlineAttached,t(e)&&(this._laserline.style=e)}get laserlineEnabled(){return this._laserlineEnabled}set laserlineEnabled(e){this._laserlineEnabled!==e&&(this._laserlineEnabled=e,this._laserline.attached=this._laserlineAttached)}get renderOccluded(){return this._renderOccluded}set renderOccluded(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._updateMaterial())}get attachmentOrigin(){if(!this._attachmentOriginDirty)return this._attachmentOrigin;const e=r(this.object3dResources.resources)?.geometries;if(!e||0===e.length)return null;s(x,0,0,0);let t=0;for(const r of e)r.computeAttachmentOrigin(S)&&(a(x,x,S),t++);return 0===t?null:(n(x,x,1/t),this.view.renderCoordsHelper.fromRenderCoords(x,this._attachmentOrigin),this._attachmentOriginDirty=!1,this._attachmentOrigin)}_updateMaterial(){t(this.object3dResources.resources)&&this.object3dResources.resources.material.setParameters(this._materialParameters),t(this.drapedResources.resources)&&this.drapedResources.resources.material.setParameters(this._materialParameters)}get _isClosed(){return t(this.geometry)&&"polygon"===this.geometry.type}get _materialParameters(){return{width:this._width,color:this._color,stippleOffColor:this._stippleOffColor,stipplePattern:this._stipplePattern,stipplePreferContinuous:!1,isClosed:this._isClosed,falloff:this._falloff,innerColor:this._innerColor,innerWidth:this._innerWidth,join:"round",hasPolygonOffset:!0,renderOccluded:this._normalizedRenderOccluded}}get _normalizedRenderOccluded(){return this.isDraped&&this._renderOccluded===E.OccludeAndTransparentStencil?E.OccludeAndTransparent:this._renderOccluded}_recreateGeometry(e,t,r){this._createRenderGeometries(t,r);for(const i of r)e.addGeometry(i);this._attachmentOriginChanged()}_attachmentOriginChanged(){this._attachmentOriginDirty=!0,this.events.emit("attachment-origin-changed")}_destroyExternalResources(e){e.geometries=[],e.material.dispose()}_createObject3DResources(e){const t=new G(this._materialParameters),r=new Array;return this._recreateGeometry(e,t,r),{material:t,geometries:r,forEach:e=>{e(t),r.forEach(e)}}}_createDrapedResources(){const e=new G(this._materialParameters);return{material:e,geometries:this._createRenderGeometriesDraped(e)}}_createRenderGeometriesDraped(e){const t=this.geometry;if(i(t)||i(this.view.basemapTerrain.spatialReference))return[];const r=w(t,this.view.basemapTerrain.spatialReference),s=[];for(const{position:i}of r.lines){const t={overlayInfo:{spatialReference:this.view.basemapTerrain.spatialReference,renderCoordsHelper:this.view.renderCoordsHelper},attributeData:{position:i},removeDuplicateStartEnd:this._isClosed},r=new D(C(e,t)),a=_(M);f(a,i),c(r.boundingSphere,.5*(a[0]+a[3]),.5*(a[1]+a[4]),0,.5*Math.sqrt((a[3]-a[0])*(a[3]-a[0])+(a[4]-a[1])*(a[4]-a[1]))),s.push(r)}return s}calculateMapBounds(e){if(i(this.object3dResources.resources))return!1;const t=this.view.renderCoordsHelper;for(const r of this.object3dResources.resources.geometries){const i=r.vertexAttributes.get(A.POSITION),s=P(i.data.length);m(i.data,t.spatialReference,0,s,this.view.spatialReference,0,i.data.length/3),f(e,s)}return!0}_createRenderGeometries(e,t){const r=this.geometry;if(i(r))return;const s=j(r,this.view.elevationProvider,this.view.renderCoordsHelper,R.fromElevationInfo(this.elevationInfo??new O({mode:y(r,null)}))),a=new Array;for(const{position:i,mapPositions:n}of s.lines){const r={mapPositions:n,attributeData:{position:i},removeDuplicateStartEnd:this._isClosed};t.push(C(e,r)),a.push(i)}this._laserline.pathVerticalPlane=a}}const M=u(),S=o(),x=o();export{I as OutlineVisualElement};