@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.92 kB
JavaScript
import{toNullable as e,unwrap as t}from"../../../../core/maybe.js";import{watch as r}from"../../../../core/reactiveUtils.js";import{castScreenPointArray as s,createScreenPointArray as i}from"../../../../core/screenUtils.js";import{f as o,a,b as c,s as n,j as d}from"../../../../chunks/vec2.js";import{a as h}from"../../../../chunks/vec2f64.js";import{k as m,c as u,n as l,b as p,a as _}from"../../../../chunks/vec3.js";import{c as f,f as g}from"../../../../chunks/vec3f64.js";import{g as b,c as y}from"../../../../chunks/vec4.js";import{f as j}from"../../../../chunks/vec4f32.js";import{makeDehydratedPoint as D}from"../../../../layers/graphics/dehydratedFeatures.js";import{EngineVisualElement as O}from"./EngineVisualElement.js";import{DRAPED_Z as G}from"../../terrain/OverlayRenderer.js";import{createPolylineGeometry as R}from"../../webgl-engine/lib/GeometryUtil.js";import{RenderOccludedFlag as w}from"../../webgl-engine/lib/Material.js";import{RenderGeometry as v}from"../../webgl-engine/lib/RenderGeometry.js";import{VertexAttribute as x}from"../../webgl-engine/lib/VertexAttribute.js";import{RibbonLineMaterial as V}from"../../webgl-engine/materials/RibbonLineMaterial.js";class P extends O{constructor(e){super(e),this._location=f(),this._direction=g(1,0,0),this._width=1,this._offset=1,this._length=18,this._color=j(1,0,1,1),this._renderOccluded=w.OccludeAndTransparent,this.applyProps(e)}createObject3DResourceFactory(e){return{view:e,createResources:e=>this._createObject3DResources(e),destroyResources:e=>this._destroyObject3DResources(e),recreateGeometry:(e,t)=>this._recreateObject3DGeometry(e,t),cameraChanged:()=>this._updateGeometry()}}createDrapedResourceFactory(e){return{view:e,createResources:()=>this._createDrapedResources(),destroyResources:e=>this._destroyDrapedResources(e),recreateGeometry:e=>this._recreateDrapedGeometry(e)}}get location(){return this._location}set location(e){m(this._location,e)||(u(this._location,e),this._updateGeometry())}get direction(){return this._direction}set direction(e){m(this._direction,e)||(u(this._direction,e),this._updateGeometry())}setDirectionFromPoints(e,t){l(this._direction,p(this._direction,t,e)),this._updateGeometry()}get width(){return this._width}set width(e){e!==this._width&&(this._width=e,this._updateMaterial())}get offset(){return this._offset}set offset(e){e!==this._offset&&(this._offset=e,this._updateGeometry())}get length(){return this._length}set length(e){e!==this._length&&(this._length=e,this._updateGeometry())}get color(){return this._color}set color(e){b(e,this._color)||(y(this._color,e),this._updateMaterial())}get renderOccluded(){return this._renderOccluded}set renderOccluded(e){e!==this._renderOccluded&&(this._renderOccluded=e,this._updateMaterial())}_createObject3DResources(e){const t=new V(this.materialParameters),r=new Array;return this._createObject3DGeometry(t,e,r),{material:t,geometries:r,forEach:e=>{e(t),r.forEach(e)}}}_destroyObject3DResources(e){e.geometries.length=0,e.material.dispose()}_recreateObject3DGeometry(e,t){e.geometries.length=0,this._createObject3DGeometry(e.material,t,e.geometries)}_createObject3DGeometry(e,t,r){const[s,i]=this._createGeometries(e);t.addGeometry(s),t.addGeometry(i),r.push(s),r.push(i),this._updateVerticesObject3D(t)}_createDrapedResources(){const e=new V(this.materialParameters),t=r((()=>this.view.state.contentPixelRatio),(()=>{this.drapedResources.recreateGeometry()}));return{material:e,geometries:this._createDrapedGeometry(e),pixelRatioHandle:t}}_destroyDrapedResources(e){e.pixelRatioHandle.remove(),e.geometries=[],e.material.dispose()}_recreateDrapedGeometry(e){e.geometries=this._createDrapedGeometry(e.material)}_createDrapedGeometry(e){const t=this._createGeometries(e);this._updateVerticesDraped(t);const r=t.map((e=>new v(e,{boundingInfo:e.boundingInfo})));for(const s of r)s.computeBoundingSphere(s.transformation,s.boundingSphere);return r}_createGeometries(e){return[R(e,[f(),f()]),R(e,[f(),f()])]}_updateMaterial(){const{materialParameters:t}=this;e(this.object3dResources.resources)?.material.setParameters(t),e(this.drapedResources.resources)?.material.setParameters(t)}get materialParameters(){return{width:this._width,color:this._color,renderOccluded:this._renderOccluded}}_updateGeometry(){if(this.isDraped)this.drapedResources.recreateGeometry();else{const t=e(this.object3dResources.object);t&&this._updateVerticesObject3D(t)}}_updateVerticesObject3D(e){const t=this.view.state.camera;t.projectToScreen(this.location,k),_(A,this.location,this.direction),t.projectToScreen(A,E),o(E,a(E,E,k)),this._updateVertexAttributesObject3D(t,e,0,k,E,1),this._updateVertexAttributesObject3D(t,e,1,k,E,-1)}_updateVertexAttributesObject3D(e,t,r,i,o,a){const c=t.geometries[r],n=c.getMutableAttribute(x.POSITION)?.data;if(!n)return;const{start:d,end:h}=this._computeStartEnd(o,i,a,this.offset,this.width,this.length);e.unprojectFromScreen(s(d),A),n[0]=A[0],n[1]=A[1],n[2]=A[2],e.unprojectFromScreen(s(h),A),n[3]=A[0],n[4]=A[1],n[5]=A[2],t.geometryVertexAttrsUpdated(c)}_updateVerticesDraped(e){const{view:{basemapTerrain:{overlayManager:r},state:{contentPixelRatio:s}}}=this,{location:i,width:o,length:a,offset:c}=this,n=F;n.spatialReference=t(r.renderer.spatialReference),n.x=i[0],n.y=i[1];const d=r.overlayPixelSizeInMapUnits(n)*s,h=o*d,m=a*d,u=c*d;this._updateVertexAttributesDraped(e[0],h,m,u,-1),this._updateVertexAttributesDraped(e[1],h,m,u,1)}_updateVertexAttributesDraped(e,t,r,s,i){const o=e.getMutableAttribute(x.POSITION)?.data;if(!o)return;const{location:a,direction:c}=this,{start:n,end:d}=this._computeStartEnd(c,a,i,s,t,r);o[0]=n[0],o[1]=n[1],o[2]=G,o[3]=d[0],o[4]=d[1],o[5]=G,e.invalidateBoundingInfo()}_computeStartEnd(e,t,r,s,i,o){const a=c(S,n(S,e[1]*r,e[0]*-r),s+i/2),h=d(M,d(M,d(M,t,c(M,e,o/2)),a),a);return{start:h,end:d(I,h,c(I,e,-o))}}}const A=f(),S=h(),M=h(),I=h(),k=i(),E=i(),F=D(0,0,void 0,null);export{P as ParallelLineVisualElement};