@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 12.6 kB
JavaScript
import has from"../../../../core/has.js";import{clamp as e}from"../../../../core/mathUtils.js";import{isSome as t,unwrapOr as r}from"../../../../core/maybe.js";import{f as s}from"../../../../chunks/mat3.js";import{c as i}from"../../../../chunks/mat3f64.js";import{a}from"../../../../chunks/mat4.js";import{c as n}from"../../../../chunks/mat4f64.js";import{c as o}from"../../../../chunks/vec2.js";import{a as c,f as l}from"../../../../chunks/vec2f64.js";import{s as f,m as u,n as h,b as p,g as m,c as d,l as g,i as O,t as S,e as v,a as A}from"../../../../chunks/vec3.js";import{c as b,f as P}from"../../../../chunks/vec3f64.js";import{c as x,f as _}from"../../../../chunks/vec4f64.js";import{isMat4 as y}from"../../../../core/libs/gl-matrix-2/types/mat4.js";import{create as I}from"../../../../geometry/support/aaBoundingRect.js";import{BufferViewVec4u8 as T}from"../../../../geometry/support/buffer/BufferView.js";import C from"../../support/debugFlags.js";import{newLayout as j}from"../../support/buffer/InterleavedLayout.js";import{ShaderOutput as z}from"../core/shaderLibrary/ShaderOutput.js";import{HUDSpace as L}from"../core/shaderLibrary/hud/HUD.glsl.js";import{GLTextureMaterial as M,GLTextureMaterialBindParameters as E}from"../lib/GLTextureMaterial.js";import{Material as U,RenderOccludedFlag as R}from"../lib/Material.js";import{RenderSlot as D}from"../lib/RenderSlot.js";import{applyScaleFactor as w,applyPrecomputedScaleFactor as V,precomputeScaleFactor as N}from"../lib/screenSizePerspectiveUtils.js";import{assert as B}from"../lib/Util.js";import{VertexAttribute as X}from"../lib/VertexAttribute.js";import{ScaleInfo as H}from"./ScaleInfo.js";import{writePosition as F,writeNormal as G,writeColor as k,writeBufferVec4 as W,writeBufferVec4Zeros as q,writeObjectAndLayerIdColor as Z}from"./internal/bufferWriterUtils.js";import{verticalOffsetAtDistance as J}from"./internal/MaterialUtil.js";import{c as Y}from"../../../../chunks/HUDMaterial.glsl.js";import{HUDMaterialTechnique as K}from"../shaders/HUDMaterialTechnique.js";import{HUDMaterialTechniqueConfiguration as Q}from"../shaders/HUDMaterialTechniqueConfiguration.js";class $ extends U{constructor(e){super(e,new be),this._configuration=new Q}getConfiguration(e,t){return this._configuration.output=e,this._configuration.hasSlicePlane=this.parameters.hasSlicePlane,this._configuration.hasVerticalOffset=!!this.parameters.verticalOffset,this._configuration.hasScreenSizePerspective=!!this.parameters.screenSizePerspective,this._configuration.screenCenterOffsetUnitsEnabled="screen"===this.parameters.centerOffsetUnits?L.Screen:L.World,this._configuration.hasPolygonOffset=this.parameters.polygonOffset,this._configuration.isDraped=this.parameters.isDraped,this._configuration.occlusionTestEnabled=this.parameters.occlusionTest,this._configuration.pixelSnappingEnabled=this.parameters.pixelSnappingEnabled,this._configuration.signedDistanceFieldEnabled=this.parameters.textureIsSignedDistanceField,this._configuration.vvSize=!!this.parameters.vvSizeEnabled,this._configuration.vvColor=!!this.parameters.vvColorEnabled,this._configuration.occlusionPass=t.slot===D.OCCLUSION_PIXELS&&this.parameters.occlusionTest&&(e===z.Color||e===z.Alpha),e===z.Color&&(this._configuration.debugDrawLabelBorder=!!C.LABELS_SHOW_BORDER),e===z.Highlight&&(this._configuration.binaryHighlightOcclusionEnabled=this.parameters.binaryHighlightOcclusion),this._configuration.depthEnabled=this.parameters.depthEnabled,this._configuration.transparencyPassType=t.transparencyPassType,this._configuration.hasMultipassGeometry=t.multipassGeometry.enabled,this._configuration.hasMultipassTerrain=t.multipassTerrain.enabled,this._configuration.cullAboveGround=t.multipassTerrain.cullAboveGround,this._configuration}intersect(e,r,i,n,o,c){if(!i.options.selectionMode||!i.options.hud||!e.visible)return;const l=this.parameters;let S=1,v=1;if(s(ue,r),t(e.shaderTransformer)){const t=e.shaderTransformer(ge);S=t[0],v=t[5],re(ue)}const A=e.vertexAttributes.get(X.POSITION),P=e.vertexAttributes.get(X.SIZE),x=e.vertexAttributes.get(X.NORMAL),_=e.vertexAttributes.get(X.AUXPOS1);B(A.size>=3);const y=i.point,I=i.camera,T=Y(l);S*=I.pixelRatio,v*=I.pixelRatio;const C="screen"===this.parameters.centerOffsetUnits;for(let t=0;t<A.data.length/A.size;t++){const e=t*A.size;f(ne,A.data[e],A.data[e+1],A.data[e+2]),u(ne,ne,r);const s=t*P.size;ve[0]=P.data[s]*S,ve[1]=P.data[s+1]*v,u(ne,ne,I.viewMatrix);const n=t*_.size;if(f(me,_.data[n+0],_.data[n+1],_.data[n+2]),!C&&(ne[0]+=me[0],ne[1]+=me[1],0!==me[2])){const e=me[2];h(me,ne),p(ne,ne,m(me,me,e))}const o=t*x.size;if(f(oe,x.data[o],x.data[o+1],x.data[o+2]),this._normalAndViewAngle(oe,ue,I,de),this._applyVerticalOffsetTransformationView(ne,de,I,ie),I.applyProjection(ne,ce),ce[0]>-1){ce[0]=Math.floor(ce[0]),ce[1]=Math.floor(ce[1]),C&&(me[0]||me[1])&&(ce[0]+=me[0],0!==me[1]&&(ce[1]+=w(me[1],ie.factorAlignment)),I.unapplyProjection(ce,ne)),ce[0]+=this.parameters.screenOffset[0],ce[1]+=this.parameters.screenOffset[1],V(ve,ie.factor,ve);const e=Oe*I.pixelRatio;let t=0;if(l.textureIsSignedDistanceField&&(t=l.outlineSize*I.pixelRatio/2),y&&se(y,ce[0],ce[1],ve,e,t,l,T)){const e=i.ray;if(u(fe,ne,a(pe,I.viewMatrix)),ce[0]=y[0],ce[1]=y[1],I.unprojectFromRenderScreen(ce,ne)){const t=b();d(t,e.direction);const r=1/g(t);m(t,t,r);c(O(e.origin,ne)*r,t,-1,!0,1,fe)}}}}}intersectDraped(e,r,s,i,a,n){const o=e.vertexAttributes.get(X.POSITION),c=e.vertexAttributes.get(X.SIZE),l=this.parameters,f=Y(l);let u=1,h=1;if(t(e.shaderTransformer)){const t=e.shaderTransformer(ge);u=t[0],h=t[5]}u*=e.screenToWorldRatio,h*=e.screenToWorldRatio;const p=Se*e.screenToWorldRatio;for(let t=0;t<o.data.length/o.size;t++){const r=t*o.size,s=o.data[r],m=o.data[r+1],d=t*c.size;ve[0]=c.data[d]*u,ve[1]=c.data[d+1]*h;let g=0;l.textureIsSignedDistanceField&&(g=l.outlineSize*e.screenToWorldRatio/2),se(i,s,m,ve,p,g,l,f)&&a(n.dist,n.normal,-1,!1)}}createBufferWriter(){return new _e(this)}_normalAndViewAngle(e,t,r,i){return y(t)&&(t=s(he,t)),S(i.normal,e,t),u(i.normal,i.normal,r.viewInverseTransposeMatrix),i.cosAngle=v(le,Ae),i}_updateScaleInfo(e,r,s){const i=this.parameters;t(i.screenSizePerspective)?N(s,r,i.screenSizePerspective,e.factor):(e.factor.scale=1,e.factor.factor=0,e.factor.minPixelSize=0,e.factor.paddingPixels=0),t(i.screenSizePerspectiveAlignment)?N(s,r,i.screenSizePerspectiveAlignment,e.factorAlignment):(e.factorAlignment.factor=e.factor.factor,e.factorAlignment.scale=e.factor.scale,e.factorAlignment.minPixelSize=e.factor.minPixelSize,e.factorAlignment.paddingPixels=e.factor.paddingPixels)}applyShaderOffsetsView(e,t,r,s,i,a,n){const o=this._normalAndViewAngle(t,r,i,de);return this._applyVerticalGroundOffsetView(e,o,i,n),this._applyVerticalOffsetTransformationView(n,o,i,a),this._applyPolygonOffsetView(n,o,s[3],i,n),this._applyCenterOffsetView(n,s,n),n}applyShaderOffsetsNDC(e,r,s,i,a){return this._applyCenterOffsetNDC(e,r,s,i),t(a)&&d(a,i),this._applyPolygonOffsetNDC(i,r,s,i),i}_applyPolygonOffsetView(t,r,s,i,a){const n=i.aboveGround?1:-1;let o=Math.sign(s);0===o&&(o=n);const c=n*o;if(this.parameters.shaderPolygonOffset<=0)return d(a,t);const l=e(Math.abs(r.cosAngle),.01,1),f=1-Math.sqrt(1-l*l)/l/i.viewport[2];return m(a,t,c>0?f:1/f),a}_applyVerticalGroundOffsetView(e,t,r,s){const i=g(e),a=r.aboveGround?1:-1,n=.5*r.computeRenderPixelSizeAtDist(i),o=m(ne,t.normal,a*n);return A(s,e,o),s}_applyVerticalOffsetTransformationView(e,t,s,i){const a=this.parameters;if(!a.verticalOffset||!a.verticalOffset.screenLength){if(a.screenSizePerspective||a.screenSizePerspectiveAlignment){const r=g(e);this._updateScaleInfo(i,r,t.cosAngle)}else i.factor.scale=1,i.factorAlignment.scale=1;return e}const n=g(e),o=r(a.screenSizePerspectiveAlignment,a.screenSizePerspective),c=J(s,n,a.verticalOffset,t.cosAngle,o);return this._updateScaleInfo(i,n,t.cosAngle),m(t.normal,t.normal,c),A(e,e,t.normal)}_applyCenterOffsetView(e,t,r){const s="screen"!==this.parameters.centerOffsetUnits;return r!==e&&d(r,e),s&&(r[0]+=t[0],r[1]+=t[1],t[2]&&(h(oe,r),A(r,r,m(oe,oe,t[2])))),r}_applyCenterOffsetNDC(e,t,r,s){const i="screen"!==this.parameters.centerOffsetUnits;return s!==e&&d(s,e),i||(s[0]+=t[0]/r.fullWidth*2,s[1]+=t[1]/r.fullHeight*2),s}_applyPolygonOffsetNDC(e,t,r,s){const i=this.parameters.shaderPolygonOffset;if(e!==s&&d(s,e),i){const e=r.aboveGround?1:-1,a=e*Math.sign(t[3]);s[2]-=(a||e)*i}return s}requiresSlot(e,t){if(t===z.Color||t===z.Alpha||t===z.Highlight||t===z.ObjectAndLayerIdColor){if(e===D.DRAPED_MATERIAL)return!0;const{drawInSecondSlot:t,occlusionTest:r}=this.parameters;return e===(t?D.LABEL_MATERIAL:D.HUD_MATERIAL)||r&&e===D.OCCLUSION_PIXELS}return!1}createGLMaterial(e){return new ee(e)}calculateRelativeScreenBounds(e,t,r=I()){return te(this.parameters,e,t,r),r[2]=r[0]+e[0],r[3]=r[1]+e[1],r}}class ee extends M{constructor(e){super({...e,...e.material.parameters})}selectProgram(e){return this.ensureTechnique(K,e)}beginSlot(e){return this.updateTexture(this._material.parameters.textureId),this._material.setParameters(this.textureBindParameters),this.selectProgram(e)}}function te(e,t,r,s=ae){return o(s,e.anchorPosition),s[0]*=-t[0],s[1]*=-t[1],s[0]+=e.screenOffset[0]*r,s[1]+=e.screenOffset[1]*r,s}function re(e){const t=e[0],r=e[1],s=e[2],i=e[3],a=e[4],n=e[5],o=e[6],c=e[7],l=e[8],f=1/Math.sqrt(t*t+r*r+s*s),u=1/Math.sqrt(i*i+a*a+n*n),h=1/Math.sqrt(o*o+c*c+l*l);return e[0]=t*f,e[1]=r*f,e[2]=s*f,e[3]=i*u,e[4]=a*u,e[5]=n*u,e[6]=o*h,e[7]=c*h,e[8]=l*h,e}function se(e,r,s,i,a,n,o,c){let l=r-a-(c[0]>0?i[0]*c[0]:0),f=l+i[0]+2*a,u=s-a-(c[1]>0?i[1]*c[1]:0),h=u+i[1]+2*a;const p=o.distanceFieldBoundingBox;return o.textureIsSignedDistanceField&&t(p)&&(l+=i[0]*p[0],u+=i[1]*p[1],f-=i[0]*(1-p[2]),h-=i[1]*(1-p[3]),l-=n,f+=n,u-=n,h+=n),e[0]>l&&e[0]<f&&e[1]>u&&e[1]<h}const ie=new H,ae=c(),ne=b(),oe=b(),ce=x(),le=b(),fe=b(),ue=i(),he=i(),pe=n(),me=b(),de={normal:le,cosAngle:0},ge=n(),Oe=1,Se=2,ve=[0,0],Ae=P(0,0,1);class be extends E{constructor(){super(...arguments),this.renderOccluded=R.Occlude,this.color=_(1,1,1,1),this.texCoordScale=[1,1],this.polygonOffset=!1,this.anchorPosition=l(.5,.5),this.screenOffset=[0,0],this.shaderPolygonOffset=1e-5,this.textureIsSignedDistanceField=!1,this.outlineColor=_(1,1,1,1),this.outlineSize=0,this.vvSizeEnabled=!1,this.vvSizeMinSize=[1,1,1],this.vvSizeMaxSize=[100,100,100],this.vvSizeOffset=[0,0,0],this.vvSizeFactor=[1,1,1],this.vvColorEnabled=!1,this.vvColorValues=[0,0,0,0,0,0,0,0],this.vvColorColors=[1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0],this.hasSlicePlane=!1,this.pixelSnappingEnabled=!0,this.occlusionTest=!0,this.binaryHighlightOcclusion=!0,this.centerOffsetUnits="world",this.drawInSecondSlot=!1,this.depthEnabled=!0,this.isDraped=!1}}const Pe=j().vec3f(X.POSITION).vec3f(X.NORMAL).vec2f(X.UV0).vec4u8(X.COLOR).vec2f(X.SIZE).vec4f(X.AUXPOS1).vec4f(X.AUXPOS2),xe=Pe.clone().vec4u8(X.OBJECTANDLAYERIDCOLOR);class _e{constructor(e){this._material=e,this.vertexBufferLayout=has("enable-feature:objectAndLayerId-rendering")?xe:Pe}allocate(e){return this.vertexBufferLayout.createBuffer(e)}elementCount(e){return 6*e.indices.get(X.POSITION).length}write(e,r,s,i,a){F(s.indices.get(X.POSITION),s.vertexAttributes.get(X.POSITION).data,e,i.position,a,6),G(s.indices.get(X.NORMAL),s.vertexAttributes.get(X.NORMAL).data,r,i.normal,a,6);const n=s.vertexAttributes.get(X.UV0).data;let o,c,l,f;if(null==n||n.length<4){const e=this._material.parameters;o=0,c=0,l=e.texCoordScale[0],f=e.texCoordScale[1]}else o=n[0],c=n[1],l=n[2],f=n[3];l=Math.min(1.99999,l+1),f=Math.min(1.99999,f+1);let u=s.indices.get(X.POSITION).length,h=a;const p=i.uv0;for(let t=0;t<u;++t)p.set(h,0,o),p.set(h,1,c),h+=1,p.set(h,0,l),p.set(h,1,c),h+=1,p.set(h,0,l),p.set(h,1,f),h+=1,p.set(h,0,l),p.set(h,1,f),h+=1,p.set(h,0,o),p.set(h,1,f),h+=1,p.set(h,0,o),p.set(h,1,c),h+=1;k(s.indices.get(X.COLOR),s.vertexAttributes.get(X.COLOR).data,4,i.color,a,6);const m=s.indices.get(X.SIZE),d=s.vertexAttributes.get(X.SIZE).data;u=m.length;const g=i.size;h=a;for(let t=0;t<u;++t){const e=d[2*m[t]],r=d[2*m[t]+1];for(let t=0;t<6;++t)g.set(h,0,e),g.set(h,1,r),h+=1}if(s.indices.get(X.AUXPOS1)&&s.vertexAttributes.get(X.AUXPOS1)?W(s.indices.get(X.AUXPOS1),s.vertexAttributes.get(X.AUXPOS1).data,i.auxpos1,a,6):q(i.auxpos1,a,6*u),s.indices.get(X.AUXPOS2)&&s.vertexAttributes.get(X.AUXPOS2)?W(s.indices.get(X.AUXPOS2),s.vertexAttributes.get(X.AUXPOS2).data,i.auxpos2,a,6):q(i.auxpos2,a,6*u),t(s.objectAndLayerIdColor)){if(s.indices.get(X.POSITION)){const e=s.indices.get(X.POSITION).length,t=i.getField(X.OBJECTANDLAYERIDCOLOR,T);Z(s.objectAndLayerIdColor,t,e,a,6)}}}}export{$ as HUDMaterial,be as Parameters};