UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 11.1 kB
import"../../../../core/has.js";import e from"../../../../core/Error.js";import{clone as t}from"../../../../core/lang.js";import{get as r,isSome as s,isNone as n}from"../../../../core/maybe.js";import{getMetersPerVerticalUnitForSR as i}from"../../../../core/unitUtils.js";import{e as o}from"../../../../chunks/earcut.js";import{b as a}from"../../../../chunks/mat3.js";import{c as l}from"../../../../chunks/mat3f64.js";import{a as c,p as h}from"../../../../chunks/mat4.js";import{c as m}from"../../../../chunks/mat4f64.js";import{c as p,n as d,s as g,b as f,f as u,m as y}from"../../../../chunks/vec3.js";import{d as b,c as _}from"../../../../chunks/vec3f64.js";import{computeTranslationToOriginAndRotation as E}from"../../../../geometry/projection.js";import{create as x,empty as j,expandWithBuffer as w,intersectsClippingArea as S}from"../../../../geometry/support/aaBoundingBox.js";import{BufferViewVec3f64 as P}from"../../../../geometry/support/buffer/BufferView.js";import{t as v,a as L}from"../../../../chunks/vec32.js";import{makeVertexCandidate as A,makeEdgeCandidate as C}from"../../../../layers/graphics/data/SnappingCandidate.js";import{getDriverAxisSizeValue as M}from"../../../../renderers/support/renderingInfoUtils.js";import{ViewingMode as I}from"../../../ViewingMode.js";import{needsElevationUpdates3D as O,SampleElevationInfo as B}from"./elevationAlignmentUtils.js";import{ElevationContext as R}from"./ElevationContext.js";import{Graphics3DObject3DGraphicLayer as z}from"./Graphics3DObject3DGraphicLayer.js";import{Graphics3DSymbolLayer as T}from"./Graphics3DSymbolLayer.js";import{validateSymbolLayerSize as D,computeCentroid as G}from"./graphicUtils.js";import{ApplyRendererDiffResult as U}from"./interfaces.js";import{geometryAsPolygon as k}from"./polygonUtils.js";import{createMaterial as N}from"../support/edgeUtils.js";import F from"../../support/debugFlags.js";import{SamplePosition as V}from"../../support/ElevationProvider.js";import{geometryToRenderInfo as H}from"../../support/renderInfoUtils/polygon.js";import{Attribute as Y}from"../../webgl-engine/lib/Attribute.js";import{CullFaceOptions as W}from"../../webgl-engine/lib/basicInterfaces.js";import{ContentObjectType as Z}from"../../webgl-engine/lib/ContentObjectType.js";import{Geometry as q}from"../../webgl-engine/lib/Geometry.js";import{isGeometryWithMapPositions as J}from"../../webgl-engine/lib/GeometryWithMapPositions.js";import{Object3D as K}from"../../webgl-engine/lib/Object3D.js";import{VertexAttribute as Q}from"../../webgl-engine/lib/VertexAttribute.js";import{DefaultMaterial as X}from"../../webgl-engine/materials/DefaultMaterial.js";const $=["polygon","extent"];class ee extends T{constructor(e,t,r,s){super(e,t,r,s),this.ensureDrapedStatus(!1)}async doLoad(){if(!this._drivenProperties.size){const t=D(this._getSymbolSize());if(t)throw new e("graphics3dextrudesymbollayer:invalid-size",t)}const t=r(this.symbolLayer,"material","color"),s=this._getCombinedOpacityAndColor(t),n=b(s),i=s[3],o=i<1||this.needsDrivenTransparentPass,a={usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0,diffuse:n,ambient:n,opacity:i,transparent:o,cullFace:o?W.None:W.Back,hasVertexColors:!0,hasSlicePlane:this._context.slicePlaneEnabled,castShadows:this.symbolLayer.castShadows,offsetTransparentBackfaces:!0};this._material=new X(a),this._bottomMaterial=new X({...a,cullFace:W.Back}),this._context.stage.add(this._material),this._context.stage.add(this._bottomMaterial)}destroy(){super.destroy(),this._material&&(this._context.stage.remove(this._material),this._context.stage.remove(this._bottomMaterial))}createGraphics3DGraphic(e){const t=e.graphic;if(!this._validateGeometry(t.geometry,$,this.symbolLayer.type))return null;const r=this._getVertexOpacityAndColor(e.renderingInfo,255),s=this.setGraphicElevationContext(t,new R);return this._createAs3DShape(t,e.renderingInfo,r,s,t.uid)}layerOpacityChanged(e,t){const n=r(this.symbolLayer,"material","color"),i=this._getCombinedOpacity(n),o=i<1||this.needsDrivenTransparentPass;this._material.setParameters({opacity:i,transparent:o}),this._bottomMaterial.setParameters({opacity:i,transparent:o});const a=this._getLayerOpacity();e.forEach((e=>{const r=t(e);s(r)&&r.layerOpacityChanged(a,this._context.isAsync)}))}layerElevationInfoChanged(e,t){return this.updateGraphics3DGraphicElevationInfo(e,t,O)}slicePlaneEnabledChanged(e,t){return this._material.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),this._bottomMaterial.setParameters({hasSlicePlane:this._context.slicePlaneEnabled}),e.forEach((e=>{const r=t(e);s(r)&&r.slicePlaneEnabledChanged(this._context.slicePlaneEnabled,this._context.isAsync)})),!0}physicalBasedRenderingChanged(){return this._material.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0}),this._bottomMaterial.setParameters({usePBR:this._context.physicalBasedRenderingEnabled,isSchematic:!0}),!0}pixelRatioChanged(){return!0}skipHighSymbolLodsChanged(){return!0}_getExtrusionSize(e){let t;return t=e.size&&this._drivenProperties.size?M(e.size,2)??0:this._getSymbolSize(),t/=this._context.renderCoordsHelper.unitInMeters,t}applyRendererDiff(e,t){return this._drivenPropertiesChanged(t)?U.Recreate_Symbol:U.Recreate_Graphics}async queryForSnapping(e,r,s,n){const o=this._getExtrusionSize(s)*this._context.renderCoordsHelper.unitInMeters/i(r),{objectId:a,target:l}=e,c=t(l);switch(c.z=(c.z??0)+o,e.type){case"edge":{const{start:r,end:s}=e,n=t(r),i=t(s);return n.z=(n.z??0)+o,i.z=(i.z??0)+o,[C(a,c,1/0,n,i)]}case"vertex":return[A(a,c,1/0),C(a,l,1/0,l,c)];default:return[]}}_getSymbolSize(){return this.symbolLayer.size??1}_createAs3DShape(e,t,r,i,h){const p=k(e.geometry);if(n(p))return null;if(0===p.rings.length||!p.rings.some((e=>e.length>0)))return this._logGeometryValidationWarnings(p.rings,"rings","ExtrudeSymbol3DLayer"),null;const d=H(p,this._context.elevationProvider,this._context.renderCoordsHelper,i);this._logGeometryCreationWarnings(d,p.rings,"rings","ExtrudeSymbol3DLayer");const g=G(p);if(n(g))return null;const f=new Array,u=x(),y=m(),b=_(),A=this._context.renderCoordsHelper.viewingMode===I.Global;A||this._context.renderCoordsHelper.worldUpAtPosition(null,b),E(p.spatialReference,[g.x,g.y,0],y,this._context.renderCoordsHelper.spatialReference);const C=m();c(C,y);const M=l();a(M,C);const{polygons:B,mapPositions:R,position:T}=d,D=T.length/3,U=new Float64Array(3*D*6),F=new Float64Array(3*D*6),V=new Float64Array(3*D*6),Y=new Float64Array(1*D*6);let W=0;for(let s=0;s<B.length;++s){const e=B[s],n=e.count;if(this._context.clippingExtent&&(j(u),w(u,e.mapPositions),!S(u,this._context.clippingExtent)))continue;const i=o(e.mapPositions,e.holeIndices,3);if(0===i.length)continue;const a=3*n*2+i.length,l=new Array(a),c=new Array(i.length),m=6*n,p=3*U.BYTES_PER_ELEMENT,d=new P(U.buffer,W*p,p,(W+m)*p),g=3*F.BYTES_PER_ELEMENT,y=new P(F.buffer,W*g,g,(W+m)*g),_=new Float64Array(V.buffer,3*W*V.BYTES_PER_ELEMENT,3*m),E=new Float64Array(Y.buffer,1*W*Y.BYTES_PER_ELEMENT,1*m),x=this._getExtrusionSize(t);re(T,R,i,e,d.typedBuffer,_,y.typedBuffer,E,l,c,x,b,A),v(d,d,C),L(y,y,M),W+=6*n;const I=this._context.stage.renderView.getObjectAndLayerIdColor({graphicUid:h,layerUid:this._context.layer.uid}),O=new xe(d.typedBuffer,_,y.typedBuffer,E);f.push(te(this._material,l,l.length-c.length,O,r,I)),f.push(te(this._bottomMaterial,c,0,O,r,I))}if(0===f.length)return null;const Z=new K({geometries:f,metadata:{layerUid:this._context.layer.uid,graphicUid:h,isElevationSource:!0}});Z.transformation=y;const q=N(this.symbolLayer,{opacity:this._getLayerOpacity()}),J=s(q)?{baseMaterial:this._material,edgeMaterials:[q],properties:{mergeGeometries:!0,hasSlicePlane:this._context.slicePlaneEnabled}}:null,Q=new z(this,Z,f,null,null,ge,i,J);return Q.alignedSampledElevation=d.sampledElevation,Q.needsElevationUpdates=O(i.mode),Q}}function te(e,t,r,s,n,i){const o=new Array(t.length).fill(0),a=[[Q.POSITION,new Y(s.positions,3,!0)],[Q.NORMAL,new Y(s.normals,3,!0)],[Q.COLOR,new Y(n,4,!0)],[Q.SIZE,new Y(s.heights,1,!0)]],l=[[Q.POSITION,t],[Q.NORMAL,t],[Q.COLOR,o]];return new q(e,a,l,s.elevation,Z.Mesh,i,r)}function re(e,t,r,s,n,i,o,a,l,c,h,m,p){const d=r.length/3;let g=0,f=2*s.count;se(e,t,s.index,s.count,r,0,d,n,i,o,a,l,c,f,h,m,p);let u=2*s.count;f=0,oe(n,i,a,o,g,s.pathLengths[0],s.count,u,l,f,h),u+=4*s.pathLengths[0],f+=2*s.pathLengths[0],g+=s.pathLengths[0];for(let y=1;y<s.pathLengths.length;++y)oe(n,i,a,o,g,s.pathLengths[y],s.count,u,l,f,h),u+=4*s.pathLengths[y],f+=2*s.pathLengths[y],g+=s.pathLengths[y]}function se(e,t,r,s,n,i,o,a,l,c,h,m,g,f,u,y,b){p(ue,y);const _=u>0?1:-1;let E=3*r,x=0,j=3*x,w=s,S=3*w;for(let p=0;p<s;++p)b&&(ue[0]=e[E+0],ue[1]=e[E+1],ue[2]=e[E+2],d(ue,ue)),a[j+0]=e[E+0],a[j+1]=e[E+1],a[j+2]=e[E+2],l[j+0]=t[E+0],l[j+1]=t[E+1],l[j+2]=t[E+2],c[j+0]=-_*ue[0],c[j+1]=-_*ue[1],c[j+2]=-_*ue[2],h[x]=0,a[S+0]=e[E+0]+u*ue[0],a[S+1]=e[E+1]+u*ue[1],a[S+2]=e[E+2]+u*ue[2],l[S+0]=t[E+0],l[S+1]=t[E+1],l[S+2]=t[E+2],c[S+0]=_*ue[0],c[S+1]=_*ue[1],c[S+2]=_*ue[2],h[w]=u,j+=3,S+=3,E+=3,x+=1,w+=1;E=3*i,j=0,S=3*f;const P=u<0?_e:be,v=u<0?be:_e;for(let p=0;p<o;++p)g[j+0]=n[E+P[0]],g[j+1]=n[E+P[1]],g[j+2]=n[E+P[2]],m[S+0]=n[E+v[0]]+s,m[S+1]=n[E+v[1]]+s,m[S+2]=n[E+v[2]]+s,j+=3,S+=3,E+=3}function ne(e,t,r,s,n,i,o){s[i]=s[o],o*=3,e[(i*=3)+0]=e[o+0],e[i+1]=e[o+1],e[i+2]=e[o+2],t[i+0]=t[o+0],t[i+1]=t[o+1],t[i+2]=t[o+2],r[i+0]=n[0],r[i+1]=n[1],r[i+2]=n[2]}const ie=_();function oe(e,t,r,s,n,i,o,a,l,c,h){let m=n,p=n+1,d=n+o,g=n+o+1,f=a,u=a+1,y=a+2*i,b=a+2*i+1;h<0&&(m=n+o+1,g=n),c*=3;for(let _=0;_<i;++_)_===i-1&&(h>0?(p=n,g=n+o):(p=n,m=n+o)),pe(e,m,p,d,ie),ne(e,t,s,r,ie,f,m),ne(e,t,s,r,ie,u,p),ne(e,t,s,r,ie,y,d),ne(e,t,s,r,ie,b,g),l[c++]=f,l[c++]=y,l[c++]=b,l[c++]=f,l[c++]=b,l[c++]=u,m++,p++,d++,g++,f+=2,u+=2,y+=2,b+=2}const ae=_(),le=_(),ce=_(),he=_(),me=_();function pe(e,t,r,s,n){t*=3,r*=3,s*=3,g(ae,e[t++],e[t++],e[t++]),g(le,e[r++],e[r++],e[r++]),g(ce,e[s++],e[s++],e[s++]),f(he,le,ae),f(me,ce,ae),u(n,me,he),d(n,n)}const de=_();function ge(e,t,r,n,i){const o=e.stageObject,a=o.geometries,l=a.length,c="absolute-height"!==t.mode;let p=0;const d=o.transformation,f=h(m(),d);for(let h=0;h<l;h+=2){const e=a[h];if(!J(e))continue;const t=e.getMutableAttribute(Q.POSITION).data,l=e.vertexAttributes.get(Q.SIZE).data,m=new V(e.mapPositions),u=t.length/3;let b=0,_=!1,E=0;for(let o=0;o<u;o++){de[0]=t[b],de[1]=t[b+1],de[2]=t[b+2],n(m,ye),c&&(E+=ye.sampledElevation),F.TESTS_DISABLE_OPTIMIZATIONS?(g(fe,m.array[m.offset+0],m.array[m.offset+1],ye.z+l[b/3]),s(r)&&i.toRenderCoords(fe,r,fe),y(fe,fe,f)):(g(fe,t[b+0],t[b+1],t[b+2]),y(fe,fe,d),i.setAltitude(fe,ye.z+l[b/3]),y(fe,fe,f)),t[b]=fe[0],t[b+1]=fe[1],t[b+2]=fe[2];const e=Ee/i.unitInMeters;(Math.abs(de[0]-t[b])>=e||Math.abs(de[1]-t[b+1])>=e||Math.abs(de[2]-t[b+2])>=e)&&(_=!0),m.offset+=3,b+=3}_&&(e.invalidateBoundingInfo(),o.geometryVertexAttrsUpdated(a[h]),a[h+1].invalidateBoundingInfo(),o.geometryVertexAttrsUpdated(a[h+1])),p+=E/u}return p/l}const fe=_(),ue=_(),ye=new B,be=[0,2,1],_e=[0,1,2],Ee=.01;class xe{constructor(e,t,r,s){this.positions=e,this.elevation=t,this.normals=r,this.heights=s}}export{ee as Graphics3DExtrudeSymbolLayer};