@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 9.11 kB
JavaScript
import"../../../../core/has.js";import{isSome as e,isNone as t,unwrapOr as r,toNullable as s}from"../../../../core/maybe.js";import{c as i,b as n,k as a,o}from"../../../../chunks/vec3.js";import{c as l,f as h}from"../../../../chunks/vec3f64.js";import{g as d,c as _}from"../../../../chunks/vec4.js";import{f as c,c as p}from"../../../../chunks/vec4f32.js";import{create as u,fromRay as f,getStart as m,getEnd as y}from"../../../../geometry/support/clipRay.js";import{intersectClipRay as g}from"../../../../geometry/support/frustum.js";import{create as b,fromPoints as D,pointAt as O}from"../../../../geometry/support/lineSegment.js";import{create as w,fromPoints as E}from"../../../../geometry/support/ray.js";import{EngineVisualElement as R}from"./EngineVisualElement.js";import{LaserlineVisualElement as j}from"./LaserlineVisualElement.js";import{DRAPED_Z as A}from"../../terrain/OverlayRenderer.js";import{createPolylineGeometry as C}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as G}from"../../webgl-engine/lib/Material.js";import{RenderGeometry as x}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as P}from"../../webgl-engine/lib/VertexAttribute.js";import{RibbonLineMaterial as S}from"../../webgl-engine/materials/RibbonLineMaterial.js";class v extends R{constructor(e){super(e),this._ray=w(),this._isWorldDown=!1,this._start=l(),this._end=h(1,0,0),this._width=1,this._color=c(1,0,1,1),this._polygonOffset=!1,this._writeDepthEnabled=!0,this._innerWidth=0,this._innerColor=c(1,1,1,1),this._stipplePattern=null,this._stippleOffColor=null,this._stipplePreferContinuous=!0,this._falloff=0,this._extensionType=W.LINE,this._laserlineStyle=null,this._laserlineEnabled=!1,this._renderOccluded=G.OccludeAndTransparent,this._fadedExtensions=F,this._laserline=new j({view:this.view}),this.applyProps(e)}destroy(){this._laserline.destroy(),super.destroy()}createObject3DResourceFactory(e){return{view:e,createResources:e=>this._createObject3DResources(e),destroyResources:e=>this._destroyExternalResources(e),recreateGeometry:(e,t)=>this._recreateObject3DGeometry(e,t),cameraChanged:()=>this._updateGeometry()}}createDrapedResourceFactory(e){return{view:e,createResources:()=>this._createDrapedResources(),destroyResources:e=>this._destroyExternalResources(e),recreateGeometry:e=>this._recreateDrapedGeometry(e)}}updateVisibility(e){super.updateVisibility(e),this._laserline.visible=e}onAttachedChange(){this._laserline.attached=this._laserlineAttached}setStartEndFromWorldDownAtLocation(e){this._isWorldDown=!0,i(this._start,e),this.view.renderCoordsHelper.worldUpAtPosition(e,this._end),n(this._end,e,this._end),E(this._start,this._end,this._ray),this._updateGeometry()}get start(){return this._start}set start(e){this._isWorldDown=!1,a(this._start,e)||(i(this._start,e),E(this._start,this._end,this._ray),this._updateGeometry())}get end(){return this._end}set end(e){this._isWorldDown=!1,a(this._end,e)||(i(this._end,e),E(this._start,this._end,this._ray),this._updateGeometry())}get width(){return this._width}set width(e){e!==this._width&&(this._width=e,this._updateMaterial())}get color(){return this._color}set color(e){d(e,this._color)||(_(this._color,e),this._updateMaterial())}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){e!==this._polygonOffset&&(this._polygonOffset=e,this._updateMaterial())}get writeDepthEnabled(){return this._writeDepthEnabled}set writeDepthEnabled(e){this._writeDepthEnabled!==e&&(this._writeDepthEnabled=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){d(e,this._innerColor)||(_(this._innerColor,e),this._updateMaterial())}get stipplePattern(){return this._stipplePattern}set stipplePattern(t){const r=e(t)!==e(this._stipplePattern);this._stipplePattern=t,r?this.recreate():this._updateMaterial()}get stippleOffColor(){return this._stippleOffColor}set stippleOffColor(r){(t(r)||t(this._stippleOffColor)||!d(r,this._stippleOffColor))&&(this._stippleOffColor=e(r)?p(r):null,this._updateMaterial())}get stipplePreferContinuous(){return this._stipplePreferContinuous}set stipplePreferContinuous(e){e!==this._stipplePreferContinuous&&(this._stipplePreferContinuous=e,this._updateMaterial())}get falloff(){return this._falloff}set falloff(e){e!==this._falloff&&(this._falloff=e,this._updateMaterial())}get extensionType(){return this._extensionType}set extensionType(e){e!==this._extensionType&&(this._extensionType=e,this.recreateGeometry())}get _laserlineAttached(){return this._laserlineEnabled&&e(this._laserlineStyle)&&this.attached&&!this.isDraped}get laserlineStyle(){return this._laserlineStyle}set laserlineStyle(t){this._laserlineStyle=t,this._laserline.attached=this._laserlineAttached,e(t)&&(this._laserline.style=t)}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 _normalizedRenderOccluded(){return this.isDraped&&this._renderOccluded===G.OccludeAndTransparentStencil?G.OccludeAndTransparent:this._renderOccluded}get fadedExtensions(){return this._fadedExtensions}set fadedExtensions(e){this._fadedExtensions=r(e,F),this.recreateGeometry()}_updateMaterial(){const{materialParameters:e}=this;s(this.object3dResources.resources)?.material.setParameters(e),s(this.drapedResources.resources)?.material.setParameters(e)}get materialParameters(){return{width:this._width,color:this._color,stippleOffColor:this._stippleOffColor,stipplePattern:this._stipplePattern,stipplePreferContinuous:this._stipplePreferContinuous,innerWidth:this._innerWidth,innerColor:this._innerColor,falloff:this._falloff,hasPolygonOffset:this._polygonOffset,renderOccluded:this._normalizedRenderOccluded,writeDepth:this._writeDepthEnabled}}_createObject3DResources(e){const t=new S(this.materialParameters),r=new Array;return this._createObject3DGeometry(t,e,r),{material:t,geometries:r,forEach:e=>{e(t),r.forEach(e)}}}_destroyExternalResources(e){e.geometries=[],e.material.dispose()}_recreateObject3DGeometry(e,t){e.geometries.length=0,this._createObject3DGeometry(e.material,t,e.geometries)}_createObject3DGeometry(e,t,r){const s=this._createGeometry(e);r.push(s),t.addGeometry(s),this._updateVerticesObject3D(t)}_createDrapedResources(){const e=new S(this.materialParameters);return{material:e,geometries:[this._createDrapedGeometry(e)]}}_recreateDrapedGeometry(e){e.geometries=[this._createDrapedGeometry(e.material)]}_createDrapedGeometry(e){const t=this._createGeometry(e);this._updateVerticesDraped(t);const r=new x(t,{boundingInfo:t.boundingInfo});return r.computeBoundingSphere(r.transformation,r.boundingSphere),r}_createGeometry(e){const t=this.extensionType===W.FADED,r=t?[l(),l(),l(),l()]:[l(),l()];return C(e,r,null,t?[1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0]:null)}_updateGeometry(){if(this.isDraped)this.drapedResources.recreateGeometry();else{const e=s(this.object3dResources.object);e&&this._updateVerticesObject3D(e)}}_updateVerticesObject3D(e){const t=this._lineSegment;this._updateVertexAttributesObject3D(e,t),this._laserline.intersectsLine=t}_updateVerticesDraped(e){this._updateVertexAttributesDraped(e,this._lineSegment)}get _lineSegment(){return this._extensionType===W.FADED?this._updateLineSegmentFinite(L):this._updateLineSegmentInfinite(this._extensionType,L)}_updateLineSegmentFinite(e){return D(this._start,this._end,e)}_updateLineSegmentInfinite(e,t){const s=this.view.state.camera;switch(f(this._ray,V),e){case W.LINE:V.c0=-Number.MAX_VALUE;break;case W.RAY:case W.GROUND_RAY:{const e=this._ray.origin,t=r(this.view.elevationProvider.getElevation(e[0],e[1],e[2],this.view.renderCoordsHelper.spatialReference,"ground"),0),s=this.view.renderCoordsHelper.getAltitude(e);this._isWorldDown&&s<t&&o(V.ray.direction,V.ray.direction),this._extensionType===W.GROUND_RAY&&null!=t&&(V.c1=Math.abs(s-t));break}}if(!g(s.frustum,V))return this._updateLineSegmentFinite(t);const i=m(V,M),n=y(V,T);return D(i,n,t)}_updateVertexAttributesObject3D(e,t){const r=e.geometries[0].getMutableAttribute(P.POSITION)?.data;if(!r)return;let s=0;for(const i of this._lineVertices(t))r[s++]=i[0],r[s++]=i[1],r[s++]=i[2];e.geometryVertexAttrsUpdated(e.geometries[0])}_updateVertexAttributesDraped(e,t){const r=e.getMutableAttribute(P.POSITION)?.data;if(!r)return;let s=0;for(const i of this._lineVertices(t))r[s++]=i[0],r[s++]=i[1],r[s++]=A;e.invalidateBoundingInfo()}*_lineVertices(e){this.extensionType===W.FADED?(yield O(e,-this.fadedExtensions.start,M),yield O(e,0,M),yield O(e,1,M),yield O(e,1+this.fadedExtensions.end,M)):(yield O(e,0,M),yield O(e,1,M))}}const V=u(),M=l(),T=l(),L=b();var W;!function(e){e[e.LINE=0]="LINE",e[e.RAY=1]="RAY",e[e.GROUND_RAY=2]="GROUND_RAY",e[e.FADED=3]="FADED"}(W||(W={}));const I=1/3,F={start:I,end:I};export{v as ExtendedLineVisualElement,W as ExtensionType};