@jdultra/threedtiles 13.2.5 → 13.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ Example:
26
26
  * @author Kirk Qi
27
27
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
28
28
  * @license MIT License
29
- */class kt extends Lc{constructor(t=[],a){super(a);yt(this,"_elements",[]);yt(this,"_DEFAULT_COMPARATOR",(t,a)=>{if(typeof t=="object"||typeof a=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t>a?1:t<a?-1:0});yt(this,"_comparator",this._DEFAULT_COMPARATOR);if(a){const{comparator:n}=a;n&&(this._comparator=n)}this.addMany(t)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){return this.elements[this.size-1]??void 0}static heapify(t,a){return new kt(t,a)}add(t){return this._elements.push(t),this._bubbleUp(this.elements.length-1)}addMany(t){const a=[];for(const n of t)this._toElementFn?a.push(this.add(this._toElementFn(n))):a.push(this.add(n));return a}poll(){if(this.elements.length===0)return;const t=this.elements[0],a=this.elements.pop();return this.elements.length&&(this.elements[0]=a,this._sinkDown(0,this.elements.length>>1)),t}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(t){return this._elements=t,this.fix()}has(t){return this.elements.includes(t)}delete(t){const a=this.elements.indexOf(t);return!(a<0)&&(a===0?this.poll():a===this.elements.length-1?this.elements.pop():(this.elements.splice(a,1,this.elements.pop()),this._bubbleUp(a),this._sinkDown(a,this.elements.length>>1)),!0)}dfs(t="PRE"){const a=[],n=i=>{const o=2*i+1,s=o+1;i<this.size&&(t==="IN"?(n(o),a.push(this.elements[i]),n(s)):t==="PRE"?(a.push(this.elements[i]),n(o),n(s)):t==="POST"&&(n(o),n(s),a.push(this.elements[i])))};return n(0),a}clone(){return new kt(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){const t=[],a=new kt(this,{comparator:this.comparator});for(;a.size!==0;){const n=a.poll();n!==void 0&&t.push(n)}return t}fix(){const t=[];for(let a=Math.floor(this.size/2);a>=0;a--)t.push(this._sinkDown(a,this.elements.length>>1));return t}filter(t,a){const n=new kt([],{toElementFn:this.toElementFn,comparator:this.comparator});let i=0;for(const o of this)t.call(a,o,i,this)&&n.add(o),i++;return n}map(t,a,n,i){const o=new kt([],{comparator:a,toElementFn:n});let s=0;for(const A of this)o.add(t.call(i,A,s,this)),s++;return o}get comparator(){return this._comparator}*_getIterator(){for(const t of this.elements)yield t}_bubbleUp(t){const a=this.elements[t];for(;t>0;){const n=t-1>>1,i=this.elements[n];if(this.comparator(i,a)<=0)break;this.elements[t]=i,t=n}return this.elements[t]=a,!0}_sinkDown(t,a){const n=this.elements[t];for(;t<a;){let i=t<<1|1;const o=i+1;let s=this.elements[i];if(o<this.elements.length&&this.comparator(s,this.elements[o])>0&&(i=o,s=this.elements[o]),this.comparator(s,n)>=0)break;this.elements[t]=s,t=i}return this.elements[t]=n,!0}}(function(r){r[r.VISIT=0]="VISIT",r[r.PROCESS=1]="PROCESS"})(kn||(kn={}));class ea extends kt{constructor(e=[],t){super(e,t)}clone(){return new ea(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(e,t){const a=new ea([],{toElementFn:this.toElementFn,comparator:this.comparator});let n=0;for(const i of this)e.call(t,i,n,this)&&a.add(i),n++;return a}map(e,t,a,n){const i=new ea([],{comparator:t,toElementFn:a});let o=0;for(const s of this)i.add(e.call(n,s,o,this)),o++;return i}}class ta extends ea{constructor(e=[],t){super(e,t)}clone(){return new ta(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(e,t){const a=new ta([],{toElementFn:this.toElementFn,comparator:this.comparator});let n=0;for(const i of this)e.call(t,i,n,this)&&a.add(i),n++;return a}map(e,t,a,n){const i=new ta([],{comparator:t,toElementFn:a});let o=0;for(const s of this)i.add(e.call(n,s,o,this)),o++;return i}}function Gc(r){return new Worker(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/PointsManager.worker-dH1fNyu8.js").href:new URL("assets/PointsManager.worker-dH1fNyu8.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:r==null?void 0:r.name})}new E.Box3,new E.Vector3,new E.Vector3,new E.Vector3,new E.Vector3;const ua=new E.Vector3,_c=new E.Vector3,qi=new E.Matrix3;qi.set(1,0,0,0,0,1,0,-1,0);const Hc=new E.Matrix4().set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);function ar(r,e){return(E.DataUtils.toHalfFloat(r)|E.DataUtils.toHalfFloat(e)<<16)>>>0}class Oc extends E.Mesh{constructor(e,t,a){const i=Math.min(Math.ceil(1)*1024,Math.pow(1024,2));let o=1*Math.pow(1024,2);o=Math.floor(o/i)*i;const s=new E.WebGL3DRenderTarget(1024,1024,1,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,anisotropy:0,depthBuffer:!1,resolveDepthBuffer:!1});s.texture.type=E.UnsignedIntType,s.texture.format=E.RGBAIntegerFormat,s.texture.internalFormat="RGBA32UI",e.initRenderTarget(s);const A=new E.WebGL3DRenderTarget(1024,1024,1,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,anisotropy:0,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,depthBuffer:!1,resolveDepthBuffer:!1});A.texture.type=E.UnsignedIntType,A.texture.format=E.RGBAIntegerFormat,A.texture.internalFormat="RGBA32UI",e.initRenderTarget(A);const u=new E.ShaderMaterial({glslVersion:E.GLSL3,uniforms:{textureSize:{value:1024},numSlices:{value:1},covarianceTexture:{value:A.texture},positionColorTexture:{value:s.texture},zUpToYUpMatrix3x3:{value:qi},sizeMultiplier:{value:1},cropRadius:{value:Number.MAX_VALUE},cameraNear:{value:.01},cameraFar:{value:10},computeLinearDepth:{value:!0},viewportPixelSize:{value:new E.Vector2},k:{value:2},beta_k:{value:2},minSplatPixelSize:{value:0},minOpacity:{value:.01},culling:{value:!0}},vertexShader:Ji(),fragmentShader:a||Ki(),transparent:!0,side:E.FrontSide,depthTest:!1,depthWrite:!1}),c=new E.InstancedBufferGeometry,d=new Float32Array([-.5,.5,0,.5,.5,0,-.5,-.5,0,.5,-.5,0]);c.setIndex([0,2,1,2,3,1]),c.setAttribute("position",new E.BufferAttribute(d,3));const l=new Uint32Array(o),h=new E.InstancedBufferAttribute(l,1,!1);h.needsUpdate=!0,h.setUsage(E.DynamicDrawUsage),c.setAttribute("order",h),c.instanceCount=0,super(c,u),this.matrixAutoUpdate=!1,this.numBatches=0,this.numVisibleBatches=0,this.orderAttribute=h,this.textureSize=1024,this.numTextures=1,this.batchSize=i,this.maxSplats=o,this.numSplatsRendered=0,this.positionColorRenderTarget=s,this.covarianceRenderTarget=A,this.renderer=e,this.sortID=0,this.freeAddresses=new ta;for(let g=0;g<this.maxSplats;g+=i)this.freeAddresses.add(g);this.worker=new Gc({}),this.sortListeners=[],this.worker.onmessage=g=>{const f=new Uint32Array(g.data.order);if(this.numSplatsRendered=f.length,f.length>this.orderAttribute.count){const m=new E.InstancedBufferGeometry,p=new Float32Array([-.5,.5,0,.5,.5,0,-.5,-.5,0,.5,-.5,0]),C=[0,2,1,2,3,1];m.setIndex(C),m.setAttribute("position",new E.BufferAttribute(p,3));const I=new Uint32Array(this.maxSplats),x=new E.InstancedBufferAttribute(I,1,!1);x.needsUpdate=!0,x.setUsage(E.DynamicDrawUsage),m.setAttribute("order",x),m.instanceCount=0,this.geometry.dispose(),this.geometry=m,this.orderAttribute=x}this.orderAttribute.clearUpdateRanges(),this.orderAttribute.set(f),this.orderAttribute.addUpdateRange(0,f.length),this.orderAttribute.needsUpdate=!0,this.geometry.instanceCount=g.data.count,this.geometry.needsUpdate=!0;for(let m=this.sortListeners.length-1;m>=0;m--)this.sortListeners[m](g.data.id)&&this.sortListeners.splice(m,1)},this.cameraPosition=new E.Vector3(0,0,0),this.viewProjModel,this.rotateOnAxis(new E.Vector3(1,0,0),.5*Math.PI),this.frustumCulled=!1,this.copyMaterial2D=new E.ShaderMaterial({glslVersion:E.GLSL3,uniforms:{sourceTexture:{}},vertexShader:Un(),fragmentShader:`
29
+ */class kt extends Lc{constructor(t=[],a){super(a);yt(this,"_elements",[]);yt(this,"_DEFAULT_COMPARATOR",(t,a)=>{if(typeof t=="object"||typeof a=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t>a?1:t<a?-1:0});yt(this,"_comparator",this._DEFAULT_COMPARATOR);if(a){const{comparator:n}=a;n&&(this._comparator=n)}this.addMany(t)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){return this.elements[this.size-1]??void 0}static heapify(t,a){return new kt(t,a)}add(t){return this._elements.push(t),this._bubbleUp(this.elements.length-1)}addMany(t){const a=[];for(const n of t)this._toElementFn?a.push(this.add(this._toElementFn(n))):a.push(this.add(n));return a}poll(){if(this.elements.length===0)return;const t=this.elements[0],a=this.elements.pop();return this.elements.length&&(this.elements[0]=a,this._sinkDown(0,this.elements.length>>1)),t}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(t){return this._elements=t,this.fix()}has(t){return this.elements.includes(t)}delete(t){const a=this.elements.indexOf(t);return!(a<0)&&(a===0?this.poll():a===this.elements.length-1?this.elements.pop():(this.elements.splice(a,1,this.elements.pop()),this._bubbleUp(a),this._sinkDown(a,this.elements.length>>1)),!0)}dfs(t="PRE"){const a=[],n=i=>{const o=2*i+1,s=o+1;i<this.size&&(t==="IN"?(n(o),a.push(this.elements[i]),n(s)):t==="PRE"?(a.push(this.elements[i]),n(o),n(s)):t==="POST"&&(n(o),n(s),a.push(this.elements[i])))};return n(0),a}clone(){return new kt(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){const t=[],a=new kt(this,{comparator:this.comparator});for(;a.size!==0;){const n=a.poll();n!==void 0&&t.push(n)}return t}fix(){const t=[];for(let a=Math.floor(this.size/2);a>=0;a--)t.push(this._sinkDown(a,this.elements.length>>1));return t}filter(t,a){const n=new kt([],{toElementFn:this.toElementFn,comparator:this.comparator});let i=0;for(const o of this)t.call(a,o,i,this)&&n.add(o),i++;return n}map(t,a,n,i){const o=new kt([],{comparator:a,toElementFn:n});let s=0;for(const A of this)o.add(t.call(i,A,s,this)),s++;return o}get comparator(){return this._comparator}*_getIterator(){for(const t of this.elements)yield t}_bubbleUp(t){const a=this.elements[t];for(;t>0;){const n=t-1>>1,i=this.elements[n];if(this.comparator(i,a)<=0)break;this.elements[t]=i,t=n}return this.elements[t]=a,!0}_sinkDown(t,a){const n=this.elements[t];for(;t<a;){let i=t<<1|1;const o=i+1;let s=this.elements[i];if(o<this.elements.length&&this.comparator(s,this.elements[o])>0&&(i=o,s=this.elements[o]),this.comparator(s,n)>=0)break;this.elements[t]=s,t=i}return this.elements[t]=n,!0}}(function(r){r[r.VISIT=0]="VISIT",r[r.PROCESS=1]="PROCESS"})(kn||(kn={}));class ea extends kt{constructor(e=[],t){super(e,t)}clone(){return new ea(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(e,t){const a=new ea([],{toElementFn:this.toElementFn,comparator:this.comparator});let n=0;for(const i of this)e.call(t,i,n,this)&&a.add(i),n++;return a}map(e,t,a,n){const i=new ea([],{comparator:t,toElementFn:a});let o=0;for(const s of this)i.add(e.call(n,s,o,this)),o++;return i}}class ta extends ea{constructor(e=[],t){super(e,t)}clone(){return new ta(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(e,t){const a=new ta([],{toElementFn:this.toElementFn,comparator:this.comparator});let n=0;for(const i of this)e.call(t,i,n,this)&&a.add(i),n++;return a}map(e,t,a,n){const i=new ta([],{comparator:t,toElementFn:a});let o=0;for(const s of this)i.add(e.call(n,s,o,this)),o++;return i}}function Gc(r){return new Worker(""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/assets/PointsManager.worker-dH1fNyu8.js").href:new URL("assets/PointsManager.worker-dH1fNyu8.js",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),{type:"module",name:r==null?void 0:r.name})}new E.Box3,new E.Vector3,new E.Vector3,new E.Vector3,new E.Vector3;const ua=new E.Vector3,_c=new E.Vector3,qi=new E.Matrix3;qi.set(1,0,0,0,0,1,0,-1,0);const Hc=new E.Matrix4().set(1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1);function ar(r,e){return(E.DataUtils.toHalfFloat(r)|E.DataUtils.toHalfFloat(e)<<16)>>>0}class Oc extends E.Mesh{constructor(e,t,a){const i=Math.min(Math.ceil(1)*1024,Math.pow(1024,2));let o=1*Math.pow(1024,2);o=Math.floor(o/i)*i;const s=new E.WebGL3DRenderTarget(1024,1024,1,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,anisotropy:0,depthBuffer:!1,resolveDepthBuffer:!1});s.texture.type=E.UnsignedIntType,s.texture.format=E.RGBAIntegerFormat,s.texture.internalFormat="RGBA32UI",e.initRenderTarget(s);const A=new E.WebGL3DRenderTarget(1024,1024,1,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,anisotropy:0,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,depthBuffer:!1,resolveDepthBuffer:!1});A.texture.type=E.UnsignedIntType,A.texture.format=E.RGBAIntegerFormat,A.texture.internalFormat="RGBA32UI",e.initRenderTarget(A);const u=new E.ShaderMaterial({glslVersion:E.GLSL3,uniforms:{textureSize:{value:1024},numSlices:{value:1},covarianceTexture:{value:A.texture},positionColorTexture:{value:s.texture},zUpToYUpMatrix3x3:{value:qi},sizeMultiplier:{value:1},cropRadius:{value:Number.MAX_VALUE},cameraNear:{value:.01},cameraFar:{value:10},computeLinearDepth:{value:!0},viewportPixelSize:{value:new E.Vector2},k:{value:2},beta_k:{value:2},minSplatPixelSize:{value:0},minOpacity:{value:.01},culling:{value:!0},antialiasingFactor:{value:2}},vertexShader:Ji(),fragmentShader:a||Ki(),transparent:!0,side:E.FrontSide,depthTest:!1,depthWrite:!1}),c=new E.InstancedBufferGeometry,d=new Float32Array([-.5,.5,0,.5,.5,0,-.5,-.5,0,.5,-.5,0]);c.setIndex([0,2,1,2,3,1]),c.setAttribute("position",new E.BufferAttribute(d,3));const l=new Uint32Array(o),h=new E.InstancedBufferAttribute(l,1,!1);h.needsUpdate=!0,h.setUsage(E.DynamicDrawUsage),c.setAttribute("order",h),c.instanceCount=0,super(c,u),this.matrixAutoUpdate=!1,this.numBatches=0,this.numVisibleBatches=0,this.orderAttribute=h,this.textureSize=1024,this.numTextures=1,this.batchSize=i,this.maxSplats=o,this.numSplatsRendered=0,this.positionColorRenderTarget=s,this.covarianceRenderTarget=A,this.renderer=e,this.sortID=0,this.freeAddresses=new ta;for(let g=0;g<this.maxSplats;g+=i)this.freeAddresses.add(g);this.worker=new Gc({}),this.sortListeners=[],this.worker.onmessage=g=>{const f=new Uint32Array(g.data.order);if(this.numSplatsRendered=f.length,f.length>this.orderAttribute.count){const m=new E.InstancedBufferGeometry,p=new Float32Array([-.5,.5,0,.5,.5,0,-.5,-.5,0,.5,-.5,0]),C=[0,2,1,2,3,1];m.setIndex(C),m.setAttribute("position",new E.BufferAttribute(p,3));const I=new Uint32Array(this.maxSplats),x=new E.InstancedBufferAttribute(I,1,!1);x.needsUpdate=!0,x.setUsage(E.DynamicDrawUsage),m.setAttribute("order",x),m.instanceCount=0,this.geometry.dispose(),this.geometry=m,this.orderAttribute=x}this.orderAttribute.clearUpdateRanges(),this.orderAttribute.set(f),this.orderAttribute.addUpdateRange(0,f.length),this.orderAttribute.needsUpdate=!0,this.geometry.instanceCount=g.data.count,this.geometry.needsUpdate=!0;for(let m=this.sortListeners.length-1;m>=0;m--)this.sortListeners[m](g.data.id)&&this.sortListeners.splice(m,1)},this.cameraPosition=new E.Vector3(0,0,0),this.viewProjModel,this.rotateOnAxis(new E.Vector3(1,0,0),.5*Math.PI),this.frustumCulled=!1,this.copyMaterial2D=new E.ShaderMaterial({glslVersion:E.GLSL3,uniforms:{sourceTexture:{}},vertexShader:Un(),fragmentShader:`
30
30
  precision highp float;
31
31
  layout(location = 0) out uvec4 fragColor;
32
32
  uniform highp usampler2D sourceTexture;
@@ -45,7 +45,7 @@ in vec2 vUv;
45
45
 
46
46
  void main() {
47
47
  fragColor = texture( sourceTexture, vec3(vUv, w) );
48
- }`,transparent:!1,side:E.FrontSide,depthTest:!1,depthWrite:!1}),this.copyCamera=new E.OrthographicCamera(-.5,.5,.5,-.5,.1,10),this.copyCamera.position.z=1,this.copyScene=new E.Scene;const b=new E.PlaneGeometry(1,1);this.copyQuad=new E.Mesh(b,this.copyMaterial2D),this.copyScene.add(this.copyQuad),this.copyScene.matrixAutoUpdate=!1,this.copyQuad.matrixAutoUpdate=!1}setQuality(e){const t=2+2*(e=Math.max(0,Math.min(1,1-e)));this.material.uniforms.k.value=t,this.material.uniforms.beta_k.value=Math.pow(4*Uc(2/t)/t,t/2),this.material.uniforms.minSplatPixelSize.value=5*e,this.material.uniforms.minOpacity.value=.01}setSplatsCPUCulling(e){this.splatsCPUCuling=e,this.material.uniforms.culling.value=!e}updateShaderParams(e){e.projectionMatrix.elements,this.renderer.getSize(this.material.uniforms.viewportPixelSize.value),this.material.uniforms.viewportPixelSize.value.multiplyScalar(this.renderer.getPixelRatio())}dispose(){this.material.dispose(),this.copyMaterial2D.dispose(),this.copyMaterial3D.dispose(),this.covarianceRenderTarget.dispose(),this.positionColorRenderTarget.dispose(),this.worker.terminate(),this.worker=null,this.orderAttribute.array=void 0,this.geometry.dispose()}copyTex2D(e,t,a,n){this.copyMaterial2D.uniforms.sourceTexture.value=e;const i=this.renderer.autoClear,o=this.renderer.getRenderTarget();this.renderer.autoClear=!1;const s=a[2]-a[0],A=a[3]-a[1];t.viewport.set(a[0],a[1],s,A),this.renderer.setRenderTarget(t,n),this.renderer.render(this.copyScene,this.copyCamera),this.renderer.setRenderTarget(o),this.renderer.autoClear=i}copyTex3D(e,t,a){this.copyMaterial3D.uniforms.sourceTexture.value=e;const n=this.renderer.autoClear,i=this.renderer.getRenderTarget();this.renderer.autoClear=!1,this.copyQuad.material=this.copyMaterial3D;for(let o=0;o<a;o++)this.renderer.setRenderTarget(t,o),this.copyMaterial3D.uniforms.w.value=(o+.5)/a,this.renderer.render(this.copyScene,this.copyCamera);this.copyQuad.material=this.copyMaterial2D,this.renderer.setRenderTarget(i),this.renderer.autoClear=n}setSplatsSizeMultiplier(e){this.material.uniforms.sizeMultiplier.value=e}setSplatsCropRadius(e){this.material.uniforms.cropRadius.value=e}sort(e,t){this.worker&&(e?this.cameraPosition&&e.equals(this.cameraPosition)||(this.cameraPosition.copy(e),t?(this.viewProjModel||(this.viewProjModel=new E.Matrix4),this.viewProjModel.copy(t),this.viewProjModel.multiply(Hc)):this.viewProjModel=void 0,this.worker.postMessage({method:"sort",xyz:[this.cameraPosition.x,this.cameraPosition.z,-this.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:this.sortID++})):this.worker.postMessage({method:"sort",xyz:[this.cameraPosition.x,this.cameraPosition.z,-this.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:this.sortID++}))}raycast(e,t){}addSplatsTile(e,t,a,n){if(!this.worker)return;const i=this,o=e.data?e.data.array:e.array,s=e.data&&e.data.isInterleavedBuffer?e.data.stride:3,A=e.data&&e.data.isInterleavedBuffer?e.offset:0,u=Math.ceil(o.length/(this.batchSize*s)),c=[],d=[];let l=()=>{};const h=new Float32Array(o.length/s*3),b=new Uint32Array(h.buffer,h.byteOffset,h.length);for(let f=0;f<o.length/3;f++)h[3*f]=o[f*s+A],h[3*f+1]=o[f*s+A+1],h[3*f+2]=o[f*s+A+2];l=(f,m,p)=>{const C=p*p;for(let I=0;I<h.length;I+=3){ua.set(h[I],-h[I+2],h[I+1]);const x=_c.copy(ua).sub(f.origin).dot(f.direction);x>0&&f.distanceSqToPoint(ua)<C&&m.push({distance:x,point:ua.clone(),type:"splat"})}},u>this.freeAddresses.size&&this.growTextures();for(let f=0;f<u;f++){const m=this.freeAddresses.poll();isNaN(m)&&console.log("insuficient texture size to store splats info"),c.push(m),d.push(3*m);const p=f*this.batchSize;this.addSplatsBatch(p,m,b,t,a,n)}i.worker.postMessage({method:"addBatches",insertionIndexes:d,positions:o.buffer,offset:A,stride:s,batchSize:i.batchSize},[o.buffer]);let g=!1;return{hide:()=>{g==1&&i.worker&&(i.numVisibleBatches--,g=!1,i.worker.postMessage({method:"hideBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++}))},show:f=>{if(g==0&&i.worker){i.numVisibleBatches--,g=!0;const m=i.sortID,p=C=>C>=m&&(f(),!0);i.sortListeners.push(p),i.worker.postMessage({method:"showBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++})}},remove:()=>{i.worker&&(l=void 0,i.worker.postMessage({method:"removeBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++}),c.forEach(f=>i.freeAddresses.add(f)))},sort:this.sort,raycast:l,isSplatsBatch:!0}}addSplatsBatch(e,t,a,n,i,o){const s=new Uint32Array(4*this.batchSize),A=new Uint32Array(4*this.batchSize);for(let b=t;b<t+this.batchSize;b++){const g=b-t,f=4*g,m=e+g,p=3*(e+g);if(m>=a.count)break;s[f]=a[p],s[f+1]=a[p+1],s[f+2]=a[p+2];const C=0|Math.floor(255*n.getX(m)+.5),I=0|Math.floor(255*n.getY(m)+.5),x=0|Math.floor(255*n.getZ(m)+.5),y=0|Math.floor(255*n.getW(m)+.5);s[f+3]=C|I<<8|x<<16|y<<24,A[f]=ar(i.getX(m),i.getY(m)),A[f+1]=ar(i.getZ(m),o.getX(m)),A[f+2]=ar(o.getY(m),o.getZ(m))}const u=Math.floor(t/Math.pow(this.textureSize,2)),c=Math.ceil(this.batchSize/this.textureSize),d=[0,t/this.textureSize-u*this.textureSize,this.textureSize];d.push(d[1]+c);const l=new E.DataTexture(s,this.textureSize,c,E.RGBAIntegerFormat,E.UnsignedIntType);l.internalFormat="RGBA32UI",l.generateMipmaps=!1,l.magFilter=E.NearestFilter,l.minFilter=E.NearestFilter,l.anisotropy=0,l.needsUpdate=!0,this.renderer.initTexture(l),this.copyTex2D(l,this.positionColorRenderTarget,d,u),l.dispose();const h=new E.DataTexture(A,this.textureSize,c,E.RGBAIntegerFormat,E.UnsignedIntType);h.internalFormat="RGBA32UI",h.generateMipmaps=!1,h.magFilter=E.NearestFilter,h.minFilter=E.NearestFilter,h.anisotropy=0,h.needsUpdate=!0,this.renderer.initTexture(h),this.copyTex2D(h,this.covarianceRenderTarget,d,u),h.dispose()}growTextures(){for(let n=this.maxSplats;n<this.maxSplats+this.textureSize*this.textureSize;n+=this.batchSize)this.freeAddresses.add(n);this.maxSplats+=this.textureSize*this.textureSize;const e=this.numTextures+1,t=new E.WebGL3DRenderTarget(this.textureSize,this.textureSize,e,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,anisotropy:0,depthBuffer:!1,resolveDepthBuffer:!1});t.texture.type=E.UnsignedIntType,t.texture.internalFormat="RGBA32UI",t.texture.format=E.RGBAIntegerFormat,this.renderer.initRenderTarget(t),this.copyTex3D(this.positionColorRenderTarget.texture,t,this.numTextures),this.positionColorRenderTarget.dispose(),this.positionColorRenderTarget=t,this.material.uniforms.positionColorTexture.value=this.positionColorRenderTarget.texture;const a=new E.WebGL3DRenderTarget(this.textureSize,this.textureSize,e,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,anisotropy:0,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,depthBuffer:!1,resolveDepthBuffer:!1});a.texture.type=E.UnsignedIntType,a.texture.internalFormat="RGBA32UI",a.texture.format=E.RGBAIntegerFormat,this.renderer.initRenderTarget(a),this.copyTex3D(this.covarianceRenderTarget.texture,a,this.numTextures),this.covarianceRenderTarget.dispose(),this.covarianceRenderTarget=a,this.material.uniforms.covarianceTexture.value=this.covarianceRenderTarget.texture,this.numTextures=e,this.material.uniforms.numSlices.value=this.numTextures}}function Ji(){return`
48
+ }`,transparent:!1,side:E.FrontSide,depthTest:!1,depthWrite:!1}),this.copyCamera=new E.OrthographicCamera(-.5,.5,.5,-.5,.1,10),this.copyCamera.position.z=1,this.copyScene=new E.Scene;const b=new E.PlaneGeometry(1,1);this.copyQuad=new E.Mesh(b,this.copyMaterial2D),this.copyScene.add(this.copyQuad),this.copyScene.matrixAutoUpdate=!1,this.copyQuad.matrixAutoUpdate=!1}setQuality(e){const t=2+2*(e=Math.max(0,Math.min(1,1-e)));this.material.uniforms.k.value=t,this.material.uniforms.beta_k.value=Math.pow(4*Uc(2/t)/t,t/2),this.material.uniforms.minSplatPixelSize.value=5*e,this.material.uniforms.minOpacity.value=.01}setSplatsCPUCulling(e){this.splatsCPUCuling=e,this.material.uniforms.culling.value=!e}updateShaderParams(e){e.projectionMatrix.elements,this.renderer.getSize(this.material.uniforms.viewportPixelSize.value);const t=this.renderer.getPixelRatio();this.material.uniforms.viewportPixelSize.value.multiplyScalar(t),this.material.uniforms.antialiasingFactor.value=t<1?2/t:2}dispose(){this.material.dispose(),this.copyMaterial2D.dispose(),this.copyMaterial3D.dispose(),this.covarianceRenderTarget.dispose(),this.positionColorRenderTarget.dispose(),this.worker.terminate(),this.worker=null,this.orderAttribute.array=void 0,this.geometry.dispose()}copyTex2D(e,t,a,n){this.copyMaterial2D.uniforms.sourceTexture.value=e;const i=this.renderer.autoClear,o=this.renderer.getRenderTarget();this.renderer.autoClear=!1;const s=a[2]-a[0],A=a[3]-a[1];t.viewport.set(a[0],a[1],s,A),this.renderer.setRenderTarget(t,n),this.renderer.render(this.copyScene,this.copyCamera),this.renderer.setRenderTarget(o),this.renderer.autoClear=i}copyTex3D(e,t,a){this.copyMaterial3D.uniforms.sourceTexture.value=e;const n=this.renderer.autoClear,i=this.renderer.getRenderTarget();this.renderer.autoClear=!1,this.copyQuad.material=this.copyMaterial3D;for(let o=0;o<a;o++)this.renderer.setRenderTarget(t,o),this.copyMaterial3D.uniforms.w.value=(o+.5)/a,this.renderer.render(this.copyScene,this.copyCamera);this.copyQuad.material=this.copyMaterial2D,this.renderer.setRenderTarget(i),this.renderer.autoClear=n}setSplatsSizeMultiplier(e){this.material.uniforms.sizeMultiplier.value=e}setSplatsCropRadius(e){this.material.uniforms.cropRadius.value=e}sort(e,t){this.worker&&(e?this.cameraPosition&&e.equals(this.cameraPosition)||(this.cameraPosition.copy(e),t?(this.viewProjModel||(this.viewProjModel=new E.Matrix4),this.viewProjModel.copy(t),this.viewProjModel.multiply(Hc)):this.viewProjModel=void 0,this.worker.postMessage({method:"sort",xyz:[this.cameraPosition.x,this.cameraPosition.z,-this.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:this.sortID++})):this.worker.postMessage({method:"sort",xyz:[this.cameraPosition.x,this.cameraPosition.z,-this.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:this.sortID++}))}raycast(e,t){}addSplatsTile(e,t,a,n){if(!this.worker)return;const i=this,o=e.data?e.data.array:e.array,s=e.data&&e.data.isInterleavedBuffer?e.data.stride:3,A=e.data&&e.data.isInterleavedBuffer?e.offset:0,u=Math.ceil(o.length/(this.batchSize*s)),c=[],d=[];let l=()=>{};const h=new Float32Array(o.length/s*3),b=new Uint32Array(h.buffer,h.byteOffset,h.length);for(let f=0;f<o.length/3;f++)h[3*f]=o[f*s+A],h[3*f+1]=o[f*s+A+1],h[3*f+2]=o[f*s+A+2];l=(f,m,p)=>{const C=p*p;for(let I=0;I<h.length;I+=3){ua.set(h[I],-h[I+2],h[I+1]);const x=_c.copy(ua).sub(f.origin).dot(f.direction);x>0&&f.distanceSqToPoint(ua)<C&&m.push({distance:x,point:ua.clone(),type:"splat"})}},u>this.freeAddresses.size&&this.growTextures();for(let f=0;f<u;f++){const m=this.freeAddresses.poll();isNaN(m)&&console.log("insuficient texture size to store splats info"),c.push(m),d.push(3*m);const p=f*this.batchSize;this.addSplatsBatch(p,m,b,t,a,n)}i.worker.postMessage({method:"addBatches",insertionIndexes:d,positions:o.buffer,offset:A,stride:s,batchSize:i.batchSize},[o.buffer]);let g=!1;return{hide:()=>{g==1&&i.worker&&(i.numVisibleBatches--,g=!1,i.worker.postMessage({method:"hideBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++}))},show:f=>{if(g==0&&i.worker){i.numVisibleBatches--,g=!0;const m=i.sortID,p=C=>C>=m&&(f(),!0);i.sortListeners.push(p),i.worker.postMessage({method:"showBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++})}},remove:()=>{i.worker&&(l=void 0,i.worker.postMessage({method:"removeBatches",insertionIndexes:d,xyz:[i.cameraPosition.x,i.cameraPosition.z,-i.cameraPosition.y],vpm:this.viewProjModel&&this.splatsCPUCuling?this.viewProjModel.toArray():void 0,id:i.sortID++}),c.forEach(f=>i.freeAddresses.add(f)))},sort:this.sort,raycast:l,isSplatsBatch:!0}}addSplatsBatch(e,t,a,n,i,o){const s=new Uint32Array(4*this.batchSize),A=new Uint32Array(4*this.batchSize);for(let b=t;b<t+this.batchSize;b++){const g=b-t,f=4*g,m=e+g,p=3*(e+g);if(m>=a.count)break;s[f]=a[p],s[f+1]=a[p+1],s[f+2]=a[p+2];const C=0|Math.floor(255*n.getX(m)+.5),I=0|Math.floor(255*n.getY(m)+.5),x=0|Math.floor(255*n.getZ(m)+.5),y=0|Math.floor(255*n.getW(m)+.5);s[f+3]=C|I<<8|x<<16|y<<24,A[f]=ar(i.getX(m),i.getY(m)),A[f+1]=ar(i.getZ(m),o.getX(m)),A[f+2]=ar(o.getY(m),o.getZ(m))}const u=Math.floor(t/Math.pow(this.textureSize,2)),c=Math.ceil(this.batchSize/this.textureSize),d=[0,t/this.textureSize-u*this.textureSize,this.textureSize];d.push(d[1]+c);const l=new E.DataTexture(s,this.textureSize,c,E.RGBAIntegerFormat,E.UnsignedIntType);l.internalFormat="RGBA32UI",l.generateMipmaps=!1,l.magFilter=E.NearestFilter,l.minFilter=E.NearestFilter,l.anisotropy=0,l.needsUpdate=!0,this.renderer.initTexture(l),this.copyTex2D(l,this.positionColorRenderTarget,d,u),l.dispose();const h=new E.DataTexture(A,this.textureSize,c,E.RGBAIntegerFormat,E.UnsignedIntType);h.internalFormat="RGBA32UI",h.generateMipmaps=!1,h.magFilter=E.NearestFilter,h.minFilter=E.NearestFilter,h.anisotropy=0,h.needsUpdate=!0,this.renderer.initTexture(h),this.copyTex2D(h,this.covarianceRenderTarget,d,u),h.dispose()}growTextures(){for(let n=this.maxSplats;n<this.maxSplats+this.textureSize*this.textureSize;n+=this.batchSize)this.freeAddresses.add(n);this.maxSplats+=this.textureSize*this.textureSize;const e=this.numTextures+1,t=new E.WebGL3DRenderTarget(this.textureSize,this.textureSize,e,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,anisotropy:0,depthBuffer:!1,resolveDepthBuffer:!1});t.texture.type=E.UnsignedIntType,t.texture.internalFormat="RGBA32UI",t.texture.format=E.RGBAIntegerFormat,this.renderer.initRenderTarget(t),this.copyTex3D(this.positionColorRenderTarget.texture,t,this.numTextures),this.positionColorRenderTarget.dispose(),this.positionColorRenderTarget=t,this.material.uniforms.positionColorTexture.value=this.positionColorRenderTarget.texture;const a=new E.WebGL3DRenderTarget(this.textureSize,this.textureSize,e,{magFilter:E.NearestFilter,minFilter:E.NearestFilter,anisotropy:0,type:E.UnsignedIntType,format:E.RGBAIntegerFormat,depthBuffer:!1,resolveDepthBuffer:!1});a.texture.type=E.UnsignedIntType,a.texture.internalFormat="RGBA32UI",a.texture.format=E.RGBAIntegerFormat,this.renderer.initRenderTarget(a),this.copyTex3D(this.covarianceRenderTarget.texture,a,this.numTextures),this.covarianceRenderTarget.dispose(),this.covarianceRenderTarget=a,this.material.uniforms.covarianceTexture.value=this.covarianceRenderTarget.texture,this.numTextures=e,this.material.uniforms.numSlices.value=this.numTextures}}function Ji(){return`
49
49
  precision highp float;
50
50
  precision highp int;
51
51
 
@@ -76,6 +76,7 @@ uniform float beta_k; // pow((4.0 * gamma(2.0/k)) /k, k/2)
76
76
  uniform float minSplatPixelSize;
77
77
  uniform float minOpacity;
78
78
  uniform bool culling;
79
+ uniform float antialiasingFactor;
79
80
 
80
81
 
81
82
  void getVertexData(out vec3 position, out mat3 covariance) {
@@ -153,7 +154,15 @@ bool modelTransform(in vec3 splatWorld, in mat3 covariance, inout vec3 vertexPos
153
154
  float a = dot(j0W, tmp0);
154
155
  float b = dot(j0W, tmp1);
155
156
  float c = dot(j1W, tmp1);
156
-
157
+ float sigmaNDC = (antialiasingFactor / viewportPixelSize.x) * 2.0;
158
+ float k2 = sigmaNDC * sigmaNDC;
159
+ float detOrig = a * c - b * b;
160
+ a += k2;
161
+ c += k2;
162
+ float detBlur = a * c - b * b;
163
+ color.a *= sqrt(detOrig / detBlur);
164
+ if(color.a < 0.01) return false;
165
+ //color.a = 1.0;
157
166
  float halfTrace = 0.5 * (a + c);
158
167
  float rootTerm = sqrt(max(halfTrace * halfTrace - (a * c - b * b), 0.0));
159
168
  float lambda1 = halfTrace + rootTerm;
@@ -227,13 +236,7 @@ void main() {
227
236
 
228
237
  vec4 outPosition = projectionMatrix * viewMatrix * vec4(offsetWorld+splatPositionWorld,1.0);
229
238
 
230
- vec3 glPosNDC = outPosition.xyz / outPosition.w;
231
- vec3 splatPosNDC = splatPositionProjected.xyz / splatPositionProjected.w;
232
- vec2 pixelOffset = abs((glPosNDC - splatPosNDC).xy)*viewportPixelSize;
233
-
234
- if((pixelOffset.x < minSplatPixelSize && pixelOffset.y < minSplatPixelSize)/* || (pixelOffset.x < 2.0 || pixelOffset.y < 2.0) */){
235
- return;
236
- }
239
+
237
240
 
238
241
  gl_Position = outPosition;
239
242
  /* if(computeLinearDepth){