@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 5.92 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import{watch as t}from"../../../../core/reactiveUtils.js";import{property as s,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{set as i}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{copy as r,scale as o,floor as n,subtract as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as m}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{InternalRenderCategory as p}from"../../webgl.js";import l from"../../webgl/RenderNode.js";import{G as u}from"../../../../chunks/GaussianSplat.glsl.js";import{G as c}from"../../../../chunks/GaussianSplatComposition.glsl.js";import{GaussianSplatCompositionTechnique as d}from"../shaders/GaussianSplatCompositionTechnique.js";import{G as _}from"../../../../chunks/GaussianSplatDepthComposition.glsl.js";import{GaussianSplatDepthCompositionTechnique as g}from"../shaders/GaussianSplatDepthCompositionTechnique.js";import{GaussianSplatTechnique as P}from"../shaders/GaussianSplatTechnique.js";import{GaussianSplatTechniqueConfiguration as f}from"../shaders/GaussianSplatTechniqueConfiguration.js";import{DepthStencilAttachment as b,ColorAttachment1 as C,PrimitiveType as v}from"../../../webgl/enums.js";var S;let x=class extends l{static{S=this}constructor(e){super(e),this._slicePlaneEnabled=!1,this.produces=p.GAUSSIAN_SPLAT,this.layerView=null,this._passParameters=new u,this._compositionPassParameters=new c,this._depthCompositionPassParameters=new _,this._previousCameraPosition=m(),this._previousCameraDirection=m(),this._configuration=new f(e.view.state.isGlobal)}async initialize(){this.addHandles([t(()=>this.view.state.camera,()=>this._onCameraChange())])}precompile(){this._configuration.alphaCutoff=this.view.qualitySettings.gaussianSplat.minimumOpacity,this._configuration.terrainDepthTest=this.bindParameters.terrainDepthTest,this._configuration.fadingEnabled=this._fadeHelper.fadingEnabled,this.techniques.precompile(P,this._configuration),this.techniques.precompile(d),this.techniques.precompile(g)}render(e){const t=e.find(({name:e})=>e===p.GAUSSIAN_SPLAT);if(this._handleFading(),!this._data.visibleGaussians||!this._data.orderTexture.texture||!this._data.textureAtlas.texture)return t;const s=this.techniques.get(P,this._configuration),a=this.techniques.get(d),i=this.techniques.get(g);if(!s.compiled||!i.compiled||!a.compiled)return this.requestRender(1),t;const{fullWidth:r,fullHeight:o}=this.bindParameters.camera;this._prepareParameters(o,r);const n=this.renderingContext,h=this.fboCache,m=h.acquire(r,o,"gaussian color output"),l=t.getAttachment(b);m.attachDepth(l),this._renderGaussianColorAndDepth(m,s);const u=h.acquire(r,o,this.produces);return this._depthCompositionPassParameters.splatDepth=m.getTexture(C),u.attachDepth(t.getAttachment(b)),n.bindFramebuffer(u.fbo),n.bindTechnique(i,this.bindParameters,this._depthCompositionPassParameters),n.screen.draw(),this._compositionPassParameters.color=t.getTexture(),this._compositionPassParameters.splatColor=m.getTexture(),n.bindFramebuffer(u.fbo),n.bindTechnique(a,this.bindParameters,this._compositionPassParameters),n.screen.draw(),m.release(),u}get slicePlaneEnabled(){return this._slicePlaneEnabled}set slicePlaneEnabled(e){this._slicePlaneEnabled!==e&&(this._slicePlaneEnabled=e,this.requestRender(1))}get _data(){return this.layerView.data}get _fadeHelper(){return this.layerView.fadeHelper}destroy(){super.destroy()}_onCameraChange(){const e=this.view.state.camera.eye,t=this.view.state.camera.ray.direction,s=.001;(Math.abs(e[0]-this._previousCameraPosition[0])>s||Math.abs(e[1]-this._previousCameraPosition[1])>s||Math.abs(e[2]-this._previousCameraPosition[2])>s||Math.abs(t[0]-this._previousCameraDirection[0])>s||Math.abs(t[1]-this._previousCameraDirection[1])>s||Math.abs(t[2]-this._previousCameraDirection[2])>s)&&(r(this._previousCameraPosition,e),r(this._previousCameraDirection,t),this._data.requestSort())}_prepareParameters(e,t){this._passParameters.splatOrder=this._data.orderTexture.texture,this._passParameters.splatFading=this._data.fadingTexture.texture,this._passParameters.splatAtlas=this._data.textureAtlas.texture;const s=Math.tan(.5*this.camera.fovY),a=s/e*t;i(this._passParameters.tanFov,a,s),this._passParameters.focalLength=e/(2*s);const r=this.view.qualitySettings.gaussianSplat.minimumSplatPixelRadius;this._passParameters.minSplatRadius=r*Math.sqrt(t*e)/Math.sqrt(2073600),this._prepareHighPrecisionCameraPosition()}_renderGaussianColorAndDepth(e,t){const s=this.renderingContext;e.acquireColor(C,5,"gaussian depth output"),s.bindFramebuffer(e.fbo),s.setClearColor(0,0,0,0),s.clear(16384),this.renderingContext.bindTechnique(t,this.bindParameters,this._passParameters),this.renderingContext.drawArraysInstanced(v.TRIANGLE_STRIP,0,4,this._data.visibleGaussians)}_prepareHighPrecisionCameraPosition(){o(this._passParameters.tileCameraPosition,this.camera.eye,1/S.tileSize),n(this._passParameters.tileCameraPosition,this._passParameters.tileCameraPosition),o(this._passParameters.cameraDelta,this._passParameters.tileCameraPosition,S.tileSize),h(this._passParameters.cameraDelta,this.camera.eye,this._passParameters.cameraDelta)}_handleFading(){if(0===this._fadeHelper.numFadingTiles)return void(this._previousFrameStart=null);this._previousFrameStart??=this.view.stage.renderer.renderContext.time;const e=this.view.stage?.renderer.renderContext.time-this._previousFrameStart;this._fadeHelper.updateAllTileFading(e),this._previousFrameStart=this.view.stage.renderer.renderContext.time,this._data.fadingTexture.updateTexture(this._data.textureAtlas.pageAllocator.pageCount)}static{this.tileSize=2.048}};e([s()],x.prototype,"produces",void 0),e([s({constructOnly:!0})],x.prototype,"layerView",void 0),x=S=e([a("esri.views.3d.webgl-engine.lib.GaussianSplatRenderNode")],x);export{x as GaussianSplatRenderNode};