UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

50 lines (44 loc) 5.56 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{numberMaxFloat32 as e}from"../core/mathUtils.js";import{multiply as i,fromTranslation as o}from"../core/libs/gl-matrix-2/math/mat4.js";import{create as r}from"../core/libs/gl-matrix-2/factories/mat4f64.js";import{set as t}from"../core/libs/gl-matrix-2/math/vec2.js";import{create as a}from"../core/libs/gl-matrix-2/factories/vec2f64.js";import{i as s}from"./vec32.js";import{create as n}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{create as c,positiveInfinity as l}from"../geometry/support/aaBoundingBox.js";import{isColorOrColorEmission as p}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js";import{SlicePlaneParameters as m,RejectBySlice as d}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{OutputHighlight as f}from"../views/3d/webgl-engine/core/shaderLibrary/output/OutputHighlight.glsl.js";import{RgbaFloatEncoding as g}from"../views/3d/webgl-engine/core/shaderLibrary/util/RgbaFloatEncoding.glsl.js";import{Float2DrawUniform as u}from"../views/3d/webgl-engine/core/shaderModules/Float2DrawUniform.js";import{Float2PassUniform as x}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{Float3DrawUniform as S}from"../views/3d/webgl-engine/core/shaderModules/Float3DrawUniform.js";import{glsl as w}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{Matrix4BindUniform as v}from"../views/3d/webgl-engine/core/shaderModules/Matrix4BindUniform.js";import{Matrix4DrawUniform as h}from"../views/3d/webgl-engine/core/shaderModules/Matrix4DrawUniform.js";import{VertexAttribute as z}from"../views/3d/webgl-engine/lib/VertexAttribute.js";import{NoParameters as b}from"../views/webgl/NoParameters.js";import{ShaderBuilder as M}from"../views/webgl/ShaderBuilder.js";class j extends b{constructor(){super(...arguments),this.clipBox=c(l),this.useFixedSizes=!1,this.useRealWorldSymbolSizes=!1,this.scaleFactor=1,this.minSizePx=0,this.size=0,this.sizePx=0}get fixedSize(){return this.drawScreenSpace?this.sizePx:this.size}get screenMinSize(){return this.useFixedSizes?0:this.minSizePx}get drawScreenSpace(){return this.useFixedSizes&&!this.useRealWorldSymbolSizes}}class P extends m{constructor(e,i,o){super(e),this.origin=e,this.isLeaf=i,this.splatSize=o}}function y(r){const a=new M,n=p(r.output),{vertex:c,fragment:l}=a;return a.vertex.include(d,r),a.attributes.add(z.POSITION,"vec3"),a.attributes.add(z.COLOR,"vec3"),c.uniforms.add(new h("modelView",((e,r)=>i(R,r.camera.viewMatrix,o(R,e.origin)))),new v("proj",(e=>e.camera.projectionMatrix)),new u("screenMinMaxSize",((e,i,o)=>t(F,o.useFixedSizes?0:o.minSizePx*i.camera.pixelRatio,O(e.isLeaf)*i.camera.pixelRatio))),r.useFixedSizes?new x("pointScale",((e,i)=>t(F,e.fixedSize*i.camera.pixelRatio,i.camera.fullHeight))):new u("pointScale",((e,i,o)=>t(F,e.splatSize*o.scaleFactor*i.camera.pixelRatio,i.camera.fullHeight/i.camera.pixelRatio)))),r.clippingEnabled?c.uniforms.add(new S("clipMin",((e,i,o)=>s(B,o.clipBox[0]-e.origin[0],o.clipBox[1]-e.origin[1],o.clipBox[2]-e.origin[2]))),new S("clipMax",((e,i,o)=>s(B,o.clipBox[3]-e.origin[0],o.clipBox[4]-e.origin[1],o.clipBox[5]-e.origin[2])))):(c.constants.add("clipMin","vec3",[-e,-e,-e]),c.constants.add("clipMax","vec3",[e,e,e])),n&&a.varyings.add("vColor","vec3"),c.main.add(w` // Move clipped points outside of clipspace if (position.x < clipMin.x || position.y < clipMin.y || position.z < clipMin.z || position.x > clipMax.x || position.y > clipMax.y || position.z > clipMax.z) { gl_Position = vec4(0.0,0.0,0.0,2.0); gl_PointSize = 0.0; return; } if (rejectBySlice(position)) { gl_Position = vec4(0.0, 0.0, 0.0, 2.0); gl_PointSize = 0.0; return; } // Position in camera space vec4 camera = modelView * vec4(position, 1.0); float pointSize = pointScale.x; vec4 position = proj * camera; ${r.drawScreenSize?w`float clampedScreenSize = pointSize;`:w`float pointRadius = 0.5 * pointSize; vec4 cameraOffset = camera + vec4(0.0, pointRadius, 0.0, 0.0); vec4 positionOffset = proj * cameraOffset; float radius = abs(positionOffset.y - position.y); float viewHeight = pointScale.y; // screen diameter = (2 * r / w) * (h / 2) float screenPointSize = (radius / position.w) * viewHeight; float clampedScreenSize = clamp(screenPointSize, screenMinMaxSize.x, screenMinMaxSize.y); // Shift towards camera, to move rendered point out of terrain i.e. to // the camera-facing end of the virtual point when considering it as a // 3D sphere. camera.xyz -= normalize(camera.xyz) * pointRadius * clampedScreenSize / screenPointSize; position = proj * camera;`} gl_PointSize = clampedScreenSize; gl_Position = position; ${n?w`vColor = color;`:""}`),l.include(g,r),a.include(f,r),l.main.add(w` vec2 vOffset = gl_PointCoord - vec2(0.5, 0.5); float r2 = dot(vOffset, vOffset); if (r2 > 0.25) { discard; } calculateOcclusionAndOutputHighlight(); ${n?w`fragColor = vec4(vColor, 1.0);`:""}`),a}function O(e){return e?256:64}const R=r(),B=n(),F=a(),_=Object.freeze(Object.defineProperty({__proto__:null,PointRendererDrawParameters:P,PointRendererPassParameters:j,build:y,getMaxPointSizeScreenspace:O},Symbol.toStringTag,{value:"Module"}));export{j as P,P as a,_ as b,y as c,O as g};