@speridlabs/visus 1.0.2 → 1.0.3

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.
package/dist/main.umd.js CHANGED
@@ -1,5 +1,5 @@
1
- (function(I,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],P):(I=typeof globalThis<"u"?globalThis:I||self,P(I.Visus={},I.THREE))})(this,function(I,P){"use strict";var Me=Object.defineProperty;var Ae=(I,P,G)=>P in I?Me(I,P,{enumerable:!0,configurable:!0,writable:!0,value:G}):I[P]=G;var p=(I,P,G)=>Ae(I,typeof P!="symbol"?P+"":P,G);if(typeof THREE>"u")throw new Error(`Visus UMD build requires Three.js as a global "THREE".
2
- Please include <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"><\/script> before loading visus/main.umd.js`);function G(E){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(E){for(const t in E)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(E,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:()=>E[t]})}}return e.default=E,Object.freeze(e)}const i=G(P);class ee{constructor(){p(this,"min",new i.Vector3(1/0,1/0,1/0));p(this,"max",new i.Vector3(-1/0,-1/0,-1/0));p(this,"center",new i.Vector3);p(this,"halfExtents",new i.Vector3)}reset(){this.min.set(1/0,1/0,1/0),this.max.set(-1/0,-1/0,-1/0),this.center.set(0,0,0),this.halfExtents.set(0,0,0)}expandByPoint(e){this.min.x=Math.min(this.min.x,e.x),this.min.y=Math.min(this.min.y,e.y),this.min.z=Math.min(this.min.z,e.z),this.max.x=Math.max(this.max.x,e.x),this.max.y=Math.max(this.max.y,e.y),this.max.z=Math.max(this.max.z,e.z),this.updateDerived()}expandByBox(e){this.min.x=Math.min(this.min.x,e.min.x),this.min.y=Math.min(this.min.y,e.min.y),this.min.z=Math.min(this.min.z,e.min.z),this.max.x=Math.max(this.max.x,e.max.x),this.max.y=Math.max(this.max.y,e.max.y),this.max.z=Math.max(this.max.z,e.max.z),this.updateDerived()}updateDerived(){this.center.addVectors(this.min,this.max).multiplyScalar(.5),this.halfExtents.subVectors(this.max,this.min).multiplyScalar(.5)}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}toBox3(){return new i.Box3().set(this.min,this.max)}clone(){const e=new ee;return e.min.copy(this.min),e.max.copy(this.max),e.center.copy(this.center),e.halfExtents.copy(this.halfExtents),e}}class ie{constructor(e=0){p(this,"numSplats",0);p(this,"positions");p(this,"rotations");p(this,"scales");p(this,"colors");p(this,"opacities");p(this,"centers");p(this,"boundingBox",new ee);this.numSplats=e,this.allocateBuffers(e)}allocateBuffers(e){this.positions=new Float32Array(e*3),this.rotations=new Float32Array(e*4),this.scales=new Float32Array(e*3),this.colors=new Float32Array(e*3),this.opacities=new Float32Array(e),this.centers=new Float32Array(e*3)}setSplat(e,t,o,r,n,s){if(e>=this.numSplats)throw new Error(`Splat index out of bounds: ${e} >= ${this.numSplats}`);const a=e*3,c=e*4,f=e*3,m=e*3;this.positions[a]=t.x,this.positions[a+1]=t.y,this.positions[a+2]=t.z,this.rotations[c]=o.x,this.rotations[c+1]=o.y,this.rotations[c+2]=o.z,this.rotations[c+3]=o.w,this.scales[f]=r.x,this.scales[f+1]=r.y,this.scales[f+2]=r.z,this.colors[m]=n.r,this.colors[m+1]=n.g,this.colors[m+2]=n.b,this.opacities[e]=s,this.centers[a]=t.x,this.centers[a+1]=t.y,this.centers[a+2]=t.z}getSplat(e){if(e>=this.numSplats)throw new Error(`Splat index out of bounds: ${e} >= ${this.numSplats}`);const t=e*3,o=e*4,r=e*3,n=e*3;return{position:new i.Vector3(this.positions[t],this.positions[t+1],this.positions[t+2]),rotation:new i.Quaternion(this.rotations[o],this.rotations[o+1],this.rotations[o+2],this.rotations[o+3]),scale:new i.Vector3(Math.exp(this.scales[r]),Math.exp(this.scales[r+1]),Math.exp(this.scales[r+2])),color:new i.Color(this.colors[n],this.colors[n+1],this.colors[n+2]),opacity:this.opacities[e]}}calculateBoundingBox(){this.boundingBox.reset();const e=new i.Vector3;for(let t=0;t<this.numSplats;t++){const o=t*3;e.set(this.positions[o],this.positions[o+1],this.positions[o+2]),this.boundingBox.expandByPoint(e)}return this.boundingBox}createDebugGeometry(){const e=new i.BufferGeometry;e.setAttribute("position",new i.BufferAttribute(this.positions,3));const t=new Float32Array(this.numSplats*3),o=new i.Quaternion,r=new i.Euler;for(let n=0;n<this.numSplats;n++){const s=n*4,a=n*3;o.set(this.rotations[s],this.rotations[s+1],this.rotations[s+2],this.rotations[s+3]),r.setFromQuaternion(o),t[a]=r.x,t[a+1]=r.y,t[a+2]=r.z}return e.setAttribute("rotation",new i.BufferAttribute(t,3)),e.setAttribute("scale",new i.BufferAttribute(this.scales,3)),e.setAttribute("color",new i.BufferAttribute(this.colors,3)),e.setAttribute("opacity",new i.BufferAttribute(this.opacities,1)),e}}class ae extends i.EventDispatcher{constructor(){super();p(this,"worker");p(this,"centers",null);p(this,"orderTexture",null);p(this,"chunks",null);p(this,"lastCameraPosition",new i.Vector3);p(this,"lastCameraDirection",new i.Vector3);const t=this.createWorkerCode(),o=new Blob([t],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(o)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(t){if(!this.orderTexture||!this.orderTexture.image)return console.error("SplatSorter: Order texture not initialized!");const{order:o,count:r}=t.data,n=this.orderTexture.image.data;if(!(n instanceof Uint32Array))return console.error("SplatSorter: Order texture data is not a Uint32Array!");n.set(new Uint32Array(o)),this.orderTexture.needsUpdate=!0;const s=n.buffer.slice(0),a={order:s};this.worker.postMessage(a,[s]),this.dispatchEvent({type:"updated",count:r})}init(t,o,r){if(!t||!(t.image.data instanceof Uint32Array))throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");if(!o||o.length%3!==0)throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");if(t.image.data.length<o.length/3)throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");const n=o.length/3;this.orderTexture=t,this.centers=o.slice();const s=this.orderTexture.image.data;for(let x=0;x<n;x++)s[x]=x;this.orderTexture.needsUpdate=!0;const a=s.buffer.slice(0),c=this.centers.buffer.slice(0),f={order:a,centers:c},m=[a,c];if(r){this.chunks=r.slice();const x=this.chunks.buffer.slice(0);f.chunks=x,m.push(x)}this.worker.postMessage(f,m)}setMapping(t){if(!this.centers)return console.warn("SplatSorter: Cannot set mapping before initialization.");let o;const r=[];if(!t){const c=this.centers.buffer.slice(0);return o={centers:c,mapping:null},r.push(c),this.worker.postMessage(o,r)}const n=new Float32Array(t.length*3);for(let c=0;c<t.length;c++){const f=t[c];if(f*3+2>=this.centers.length){console.warn(`SplatSorter: Mapping index ${f} out of bounds.`);continue}const m=f*3,x=c*3;n[x+0]=this.centers[m+0],n[x+1]=this.centers[m+1],n[x+2]=this.centers[m+2]}const s=n.buffer.slice(0),a=t.buffer.slice(0);o={centers:s,mapping:a},r.push(s,a),this.worker.postMessage(o,r)}setCamera(t,o){const r=this.lastCameraPosition.distanceToSquared(t)>1e-7,n=this.lastCameraDirection.dot(o)<.9999;if(!r&&!n)return;this.lastCameraPosition.copy(t),this.lastCameraDirection.copy(o);const s={cameraPosition:{x:t.x,y:t.y,z:t.z},cameraDirection:{x:o.x,y:o.y,z:o.z}};this.worker.postMessage(s)}dispose(){this.worker&&this.worker.terminate(),this.orderTexture=null,this.centers=null,this.chunks=null}createWorkerCode(){return`(${(function(){let o=null,r=null,n=null,s=null,a=null,c=null,f=!1;const m={x:0,y:0,z:0},x={x:0,y:0,z:0},v={x:0,y:0,z:0},d={x:0,y:0,z:0};let S=null,u=null;const M=32,q=new Array(M).fill(0),j=new Array(M).fill(0),H=new Array(M).fill(0),L=(T,A,F)=>{for(;T<=A;){const C=A+T>>1,y=F(C);if(y>0)T=C+1;else if(y<0)A=C-1;else return C}return~T},Y=()=>{if(!o||!r||!a||!c)return;if(r.length===0){const g={order:o.buffer,count:0};self.postMessage(g,[o.buffer]),o=null;return}const T=a.x,A=a.y,F=a.z,C=c.x,y=c.y,z=c.z,_=1e-4,R=Math.abs(T-m.x)>_||Math.abs(A-m.y)>_||Math.abs(F-m.z)>_,B=Math.abs(C-x.x)>_||Math.abs(y-x.y)>_||Math.abs(z-x.z)>_;if(!f&&!R&&!B)return;f=!1,m.x=T,m.y=A,m.z=F,x.x=C,x.y=y,x.z=z;let l=1/0,h=-1/0;for(let g=0;g<8;++g){const D=g&1?v.x:d.x,O=g&2?v.y:d.y,b=g&4?v.z:d.z,k=D*C+O*y+b*z;l=Math.min(l,k),h=Math.max(h,k)}const w=r.length/3,W=h-l,U=(1<<Math.max(10,Math.min(20,Math.ceil(Math.log2(w/4)))))+1;if((!S||S.length!==w)&&(S=new Uint32Array(w)),!u||u.length!==U?u=new Uint32Array(U):u.fill(0),W<1e-7){for(let g=0;g<w;++g)S[g]=0;u[0]=w}else if(n&&n.length>0){const g=n.length/6;q.fill(0);for(let b=0;b<g;++b){const k=b*6,J=n[k+0],K=n[k+1],te=n[k+2],Z=n[k+3],X=J*C+K*y+te*z-l,re=X-Z,Q=X+Z,ne=Math.max(0,Math.floor(re*M/W)),se=Math.min(M,Math.ceil(Q*M/W));for(let $=ne;$<se;++$)q[$]++}let D=0;for(let b=0;b<M;++b)D+=q[b];H[0]=0,j[0]=0;for(let b=1;b<M;++b)H[b-1]=q[b-1]/D*U>>>0,j[b]=j[b-1]+H[b-1];H[M-1]=q[M-1]/D*U>>>0;const O=W/M;for(let b=0;b<w;++b){const k=b*3,J=r[k+0],K=r[k+1],te=r[k+2],Z=J*C+K*y+te*z,re=(h-Z)/O,Q=Math.max(0,Math.min(M-1,Math.floor(re))),ne=re-Q,se=j[Q]+H[Q]*ne>>>0,$=Math.min(se,U-1);S[b]=$,u[$]++}}else{const g=(U-1)/W;for(let D=0;D<w;++D){const O=D*3,b=r[O+0],k=r[O+1],J=r[O+2],K=b*C+k*y+J*z,Z=(h-K)*g>>>0,X=Math.min(Z,U-1);S[D]=X,u[X]++}}for(let g=1;g<U;g++)u[g]+=u[g-1];for(let g=w-1;g>=0;g--){const D=S[g],O=--u[D];o[O]=s?s[g]:g}const V=T*C+A*y+F*z,he=g=>{if(!o)return-1/0;const D=o[g],O=D;if(!r||O*3+2>=r.length)return-1/0;const b=O*3;return r[b]*C+r[b+1]*y+r[b+2]*z-V};let fe=w;if(w>0&&he(w-1)<0){const g=L(0,w-1,he);fe=g<0?~g:g}const Se={order:o.buffer,count:fe};self.postMessage(Se,[o.buffer]),o=null};self.onmessage=T=>{const A=T.data;A.order&&(o=new Uint32Array(A.order));let F=!1;if(A.centers&&(r=new Float32Array(A.centers),F=!0,f=!0),Object.prototype.hasOwnProperty.call(A,"mapping")&&(s=A.mapping?new Uint32Array(A.mapping):null,f=!0),A.chunks){if(n=new Float32Array(A.chunks),n.length>0&&n[3]>0)for(let C=0;C<n.length/6;++C){const y=C*6,z=n[y+0],_=n[y+1],R=n[y+2],B=n[y+3],l=n[y+4],h=n[y+5];n[y+0]=(z+B)*.5,n[y+1]=(_+l)*.5,n[y+2]=(R+h)*.5,n[y+3]=Math.sqrt((B-z)**2+(l-_)**2+(h-R)**2)*.5}f=!0}if(F&&r&&r.length>0){v.x=d.x=r[0],v.y=d.y=r[1],v.z=d.z=r[2];for(let C=1;C<r.length/3;C++){const y=C*3;v.x=Math.min(v.x,r[y+0]),d.x=Math.max(d.x,r[y+0]),v.y=Math.min(v.y,r[y+1]),d.y=Math.max(d.y,r[y+1]),v.z=Math.min(v.z,r[y+2]),d.z=Math.max(d.z,r[y+2])}}else F&&r&&r.length===0&&(v.x=d.x=v.y=d.y=v.z=d.z=0);A.cameraPosition&&(a=A.cameraPosition),A.cameraDirection&&(c=A.cameraDirection),Y()}}).toString()})();`}}const pe=(E,e)=>{const t=ce(E),o=ce(e);return t|o<<16};function ce(E){const e=new Float32Array([E]),o=new Int32Array(e.buffer)[0];let r=o>>16&32768,n=o>>12&2047;const s=o>>23&255;return s<103?r:s>142?(r|=31744,r|=(s===255?0:1)&&o&8388607,r):s<113?(n|=2048,r|=(n>>114-s)+(n>>113-s&1),r):(r|=s-112<<10|n>>1,r+=n&1,r)}const me=new ArrayBuffer(4),le=new DataView(me),xe=E=>(le.setUint32(0,E,!0),le.getFloat32(0,!0));class ue{constructor(e){p(this,"transformA");p(this,"transformB");p(this,"colorTexture");p(this,"orderTexture");p(this,"textureWidth");p(this,"textureHeight");const t=e.numSplats;this.textureWidth=Math.ceil(Math.sqrt(t)),this.textureHeight=Math.ceil(t/this.textureWidth),this.transformA=this.createTransformATexture(e),this.transformB=this.createTransformBTexture(e),this.colorTexture=this.createColorTexture(e),this.orderTexture=this.createOrderTexture(t)}createTransformATexture(e){const t=e.numSplats,o=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<t;n++){const s=n*4,a=n*3,c=n*4;o[s]=e.positions[a],o[s+1]=e.positions[a+1],o[s+2]=e.positions[a+2];const f=e.rotations[c+0],m=e.rotations[c+1],x=pe(f,m);o[s+3]=xe(x)}const r=new i.DataTexture(o,this.textureWidth,this.textureHeight,i.RGBAFormat,i.FloatType);return r.needsUpdate=!0,r.magFilter=i.NearestFilter,r.minFilter=i.NearestFilter,r}createTransformBTexture(e){const t=e.numSplats,o=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<t;n++){const s=n*4,a=n*3,c=n*4;o[s]=e.scales[a],o[s+1]=e.scales[a+1],o[s+2]=e.scales[a+2],o[s+3]=e.rotations[c+2]}const r=new i.DataTexture(o,this.textureWidth,this.textureHeight,i.RGBAFormat,i.FloatType);return r.needsUpdate=!0,r.magFilter=i.NearestFilter,r.minFilter=i.NearestFilter,r}createColorTexture(e){const t=e.numSplats,o=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<t;n++){const s=n*4,a=n*3;o[s]=e.colors[a],o[s+1]=e.colors[a+1],o[s+2]=e.colors[a+2],o[s+3]=e.opacities[n]}const r=new i.DataTexture(o,this.textureWidth,this.textureHeight,i.RGBAFormat,i.FloatType);return r.needsUpdate=!0,r}createOrderTexture(e){const t=new Uint32Array(this.textureWidth*this.textureHeight);for(let r=0;r<e;r++)t[r]=r;const o=new i.DataTexture(t,this.textureWidth,this.textureHeight,i.RedIntegerFormat,i.UnsignedIntType);return o.needsUpdate=!0,o}dispose(){this.transformA.dispose(),this.transformB.dispose(),this.colorTexture.dispose(),this.orderTexture.dispose()}}const ge=`
1
+ (function(z,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("three")):typeof define=="function"&&define.amd?define(["exports","three"],P):(z=typeof globalThis<"u"?globalThis:z||self,P(z.Visus={},z.THREE))})(this,function(z,P){"use strict";var St=Object.defineProperty;var Ct=(z,P,L)=>P in z?St(z,P,{enumerable:!0,configurable:!0,writable:!0,value:L}):z[P]=L;var c=(z,P,L)=>Ct(z,typeof P!="symbol"?P+"":P,L);if(typeof THREE>"u")throw new Error(`Visus UMD build requires Three.js as a global "THREE".
2
+ Please include <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"><\/script> before loading visus/main.umd.js`);function L(I){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const s in I)if(s!=="default"){const e=Object.getOwnPropertyDescriptor(I,s);Object.defineProperty(t,s,e.get?e:{enumerable:!0,get:()=>I[s]})}}return t.default=I,Object.freeze(t)}const o=L(P);class Q{constructor(){c(this,"min",new o.Vector3(1/0,1/0,1/0));c(this,"max",new o.Vector3(-1/0,-1/0,-1/0));c(this,"center",new o.Vector3);c(this,"halfExtents",new o.Vector3)}reset(){this.min.set(1/0,1/0,1/0),this.max.set(-1/0,-1/0,-1/0),this.center.set(0,0,0),this.halfExtents.set(0,0,0)}expandByPoint(t){this.min.x=Math.min(this.min.x,t.x),this.min.y=Math.min(this.min.y,t.y),this.min.z=Math.min(this.min.z,t.z),this.max.x=Math.max(this.max.x,t.x),this.max.y=Math.max(this.max.y,t.y),this.max.z=Math.max(this.max.z,t.z),this.updateDerived()}expandByBox(t){this.min.x=Math.min(this.min.x,t.min.x),this.min.y=Math.min(this.min.y,t.min.y),this.min.z=Math.min(this.min.z,t.min.z),this.max.x=Math.max(this.max.x,t.max.x),this.max.y=Math.max(this.max.y,t.max.y),this.max.z=Math.max(this.max.z,t.max.z),this.updateDerived()}updateDerived(){this.center.addVectors(this.min,this.max).multiplyScalar(.5),this.halfExtents.subVectors(this.max,this.min).multiplyScalar(.5)}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}toBox3(){return new o.Box3().set(this.min,this.max)}clone(){const t=new Q;return t.min.copy(this.min),t.max.copy(this.max),t.center.copy(this.center),t.halfExtents.copy(this.halfExtents),t}}class it{constructor(t=0){c(this,"numSplats",0);c(this,"positions");c(this,"rotations");c(this,"scales");c(this,"colors");c(this,"opacities");c(this,"centers");c(this,"boundingBox",new Q);this.numSplats=t,this.allocateBuffers(t)}allocateBuffers(t){this.positions=new Float32Array(t*3),this.rotations=new Float32Array(t*4),this.scales=new Float32Array(t*3),this.colors=new Float32Array(t*3),this.opacities=new Float32Array(t),this.centers=new Float32Array(t*3)}setSplat(t,s,e,r,n,i){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const a=t*3,d=t*4,p=t*3,v=t*3;this.positions[a]=s.x,this.positions[a+1]=s.y,this.positions[a+2]=s.z,this.rotations[d]=e.x,this.rotations[d+1]=e.y,this.rotations[d+2]=e.z,this.rotations[d+3]=e.w,this.scales[p]=r.x,this.scales[p+1]=r.y,this.scales[p+2]=r.z,this.colors[v]=n.r,this.colors[v+1]=n.g,this.colors[v+2]=n.b,this.opacities[t]=i,this.centers[a]=s.x,this.centers[a+1]=s.y,this.centers[a+2]=s.z}getSplat(t){if(t>=this.numSplats)throw new Error(`Splat index out of bounds: ${t} >= ${this.numSplats}`);const s=t*3,e=t*4,r=t*3,n=t*3;return{position:new o.Vector3(this.positions[s],this.positions[s+1],this.positions[s+2]),rotation:new o.Quaternion(this.rotations[e],this.rotations[e+1],this.rotations[e+2],this.rotations[e+3]),scale:new o.Vector3(Math.exp(this.scales[r]),Math.exp(this.scales[r+1]),Math.exp(this.scales[r+2])),color:new o.Color(this.colors[n],this.colors[n+1],this.colors[n+2]),opacity:this.opacities[t]}}calculateBoundingBox(){this.boundingBox.reset();const t=new o.Vector3;for(let s=0;s<this.numSplats;s++){const e=s*3;t.set(this.positions[e],this.positions[e+1],this.positions[e+2]),this.boundingBox.expandByPoint(t)}return this.boundingBox}createDebugGeometry(){const t=new o.BufferGeometry;t.setAttribute("position",new o.BufferAttribute(this.positions,3));const s=new Float32Array(this.numSplats*3),e=new o.Quaternion,r=new o.Euler;for(let n=0;n<this.numSplats;n++){const i=n*4,a=n*3;e.set(this.rotations[i],this.rotations[i+1],this.rotations[i+2],this.rotations[i+3]),r.setFromQuaternion(e),s[a]=r.x,s[a+1]=r.y,s[a+2]=r.z}return t.setAttribute("rotation",new o.BufferAttribute(s,3)),t.setAttribute("scale",new o.BufferAttribute(this.scales,3)),t.setAttribute("color",new o.BufferAttribute(this.colors,3)),t.setAttribute("opacity",new o.BufferAttribute(this.opacities,1)),t}}class at extends o.EventDispatcher{constructor(){super();c(this,"worker");c(this,"centers",null);c(this,"orderTexture",null);c(this,"chunks",null);c(this,"lastCameraPosition",new o.Vector3);c(this,"lastCameraDirection",new o.Vector3);const s=this.createWorkerCode(),e=new Blob([s],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(e)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(s){if(!this.orderTexture||!this.orderTexture.image)return console.error("SplatSorter: Order texture not initialized!");const{order:e,count:r}=s.data,n=this.orderTexture.image.data;if(!(n instanceof Uint32Array))return console.error("SplatSorter: Order texture data is not a Uint32Array!");n.set(new Uint32Array(e)),this.orderTexture.needsUpdate=!0;const i=n.buffer.slice(0),a={order:i};this.worker.postMessage(a,[i]),this.dispatchEvent({type:"updated",count:r})}init(s,e,r){if(!s||!(s.image.data instanceof Uint32Array))throw new Error("SplatSorter: Invalid orderTexture provided. Must be DataTexture with Uint32Array data.");if(!e||e.length%3!==0)throw new Error("SplatSorter: Invalid centers array provided. Length must be multiple of 3.");if(s.image.data.length<e.length/3)throw new Error("SplatSorter: orderTexture data buffer is smaller than the number of splats.");const n=e.length/3;this.orderTexture=s,this.centers=e.slice();const i=this.orderTexture.image.data;for(let g=0;g<n;g++)i[g]=g;this.orderTexture.needsUpdate=!0;const a=i.buffer.slice(0),d=this.centers.buffer.slice(0),p={order:a,centers:d},v=[a,d];if(r){this.chunks=r.slice();const g=this.chunks.buffer.slice(0);p.chunks=g,v.push(g)}this.worker.postMessage(p,v),queueMicrotask(()=>{this.dispatchEvent({type:"updated",count:n})})}setMapping(s){if(!this.centers)return console.warn("SplatSorter: Cannot set mapping before initialization.");let e;const r=[];if(!s){const d=this.centers.buffer.slice(0);return e={centers:d,mapping:null},r.push(d),this.worker.postMessage(e,r)}const n=new Float32Array(s.length*3);for(let d=0;d<s.length;d++){const p=s[d];if(p*3+2>=this.centers.length){console.warn(`SplatSorter: Mapping index ${p} out of bounds.`);continue}const v=p*3,g=d*3;n[g+0]=this.centers[v+0],n[g+1]=this.centers[v+1],n[g+2]=this.centers[v+2]}const i=n.buffer.slice(0),a=s.buffer.slice(0);e={centers:i,mapping:a},r.push(i,a),this.worker.postMessage(e,r)}setCamera(s,e){const r=this.lastCameraPosition.distanceToSquared(s)>1e-7,n=this.lastCameraDirection.dot(e)<.9999;if(!r&&!n)return;this.lastCameraPosition.copy(s),this.lastCameraDirection.copy(e);const i={cameraPosition:{x:s.x,y:s.y,z:s.z},cameraDirection:{x:e.x,y:e.y,z:e.z}};this.worker.postMessage(i)}dispose(){this.worker&&this.worker.terminate(),this.orderTexture=null,this.centers=null,this.chunks=null}createWorkerCode(){return`(${(function(){let e=null,r=null,n=null,i=null,a=null,d=null,p=!1;const v={x:0,y:0,z:0},g={x:0,y:0,z:0},f={x:0,y:0,z:0},h={x:0,y:0,z:0};let l=null,b=null;const _=32,q=new Array(_).fill(0),W=new Array(_).fill(0),R=new Array(_).fill(0),j=(D,S,F)=>{for(;D<=S;){const M=S+D>>1,m=F(M);if(m>0)D=M+1;else if(m<0)S=M-1;else return M}return~D},N=()=>{if(!e||!r||!a||!d)return;if(r.length===0){const y={order:e.buffer,count:0};self.postMessage(y,[e.buffer]),e=null;return}const D=a.x,S=a.y,F=a.z,M=d.x,m=d.y,k=d.z,U=1e-4,E=Math.abs(D-v.x)>U||Math.abs(S-v.y)>U||Math.abs(F-v.z)>U,x=Math.abs(M-g.x)>U||Math.abs(m-g.y)>U||Math.abs(k-g.z)>U;if(!p&&!E&&!x)return;p=!1,v.x=D,v.y=S,v.z=F,g.x=M,g.y=m,g.z=k;let u=1/0,C=-1/0;for(let y=0;y<8;++y){const B=y&1?f.x:h.x,O=y&2?f.y:h.y,w=y&4?f.z:h.z,V=B*M+O*m+w*k;u=Math.min(u,V),C=Math.max(C,V)}const T=r.length/3,Y=C-u,A=(1<<Math.max(10,Math.min(20,Math.ceil(Math.log2(T/4)))))+1;if((!l||l.length!==T)&&(l=new Uint32Array(T)),!b||b.length!==A?b=new Uint32Array(A):b.fill(0),Y<1e-7){for(let y=0;y<T;++y)l[y]=0;b[0]=T}else if(n&&n.length>0){const y=n.length/6;q.fill(0);for(let w=0;w<y;++w){const V=w*6,$=n[V+0],J=n[V+1],tt=n[V+2],X=n[V+3],Z=$*M+J*m+tt*k-u,et=Z-X,K=Z+X,nt=Math.max(0,Math.floor(et*_/Y)),ot=Math.min(_,Math.ceil(K*_/Y));for(let G=nt;G<ot;++G)q[G]++}let B=0;for(let w=0;w<_;++w)B+=q[w];R[0]=0,W[0]=0;for(let w=1;w<_;++w)R[w-1]=q[w-1]/B*A>>>0,W[w]=W[w-1]+R[w-1];R[_-1]=q[_-1]/B*A>>>0;const O=Y/_;for(let w=0;w<T;++w){const V=w*3,$=r[V+0],J=r[V+1],tt=r[V+2],X=$*M+J*m+tt*k,et=(C-X)/O,K=Math.max(0,Math.min(_-1,Math.floor(et))),nt=et-K,ot=W[K]+R[K]*nt>>>0,G=Math.min(ot,A-1);l[w]=G,b[G]++}}else{const y=(A-1)/Y;for(let B=0;B<T;++B){const O=B*3,w=r[O+0],V=r[O+1],$=r[O+2],J=w*M+V*m+$*k,X=(C-J)*y>>>0,Z=Math.min(X,A-1);l[B]=Z,b[Z]++}}for(let y=1;y<A;y++)b[y]+=b[y-1];for(let y=T-1;y>=0;y--){const B=l[y],O=--b[B];e[O]=i?i[y]:y}const bt=D*M+S*m+F*k,dt=y=>{if(!e)return-1/0;const B=e[y],O=B;if(!r||O*3+2>=r.length)return-1/0;const w=O*3;return r[w]*M+r[w+1]*m+r[w+2]*k-bt};let ft=T;if(T>0&&dt(T-1)<0){const y=j(0,T-1,dt);ft=y<0?~y:y}const Mt={order:e.buffer,count:ft};self.postMessage(Mt,[e.buffer]),e=null};self.onmessage=D=>{const S=D.data;S.order&&(e=new Uint32Array(S.order));let F=!1;if(S.centers&&(r=new Float32Array(S.centers),F=!0,p=!0),Object.prototype.hasOwnProperty.call(S,"mapping")&&(i=S.mapping?new Uint32Array(S.mapping):null,p=!0),S.chunks){if(n=new Float32Array(S.chunks),n.length>0&&n[3]>0)for(let M=0;M<n.length/6;++M){const m=M*6,k=n[m+0],U=n[m+1],E=n[m+2],x=n[m+3],u=n[m+4],C=n[m+5];n[m+0]=(k+x)*.5,n[m+1]=(U+u)*.5,n[m+2]=(E+C)*.5,n[m+3]=Math.sqrt((x-k)**2+(u-U)**2+(C-E)**2)*.5}p=!0}if(F&&r&&r.length>0){f.x=h.x=r[0],f.y=h.y=r[1],f.z=h.z=r[2];for(let M=1;M<r.length/3;M++){const m=M*3;f.x=Math.min(f.x,r[m+0]),h.x=Math.max(h.x,r[m+0]),f.y=Math.min(f.y,r[m+1]),h.y=Math.max(h.y,r[m+1]),f.z=Math.min(f.z,r[m+2]),h.z=Math.max(h.z,r[m+2])}}else F&&r&&r.length===0&&(f.x=h.x=f.y=h.y=f.z=h.z=0);S.cameraPosition&&(a=S.cameraPosition),S.cameraDirection&&(d=S.cameraDirection),N()}}).toString()})();`}}const pt=(I,t)=>{const s=ct(I),e=ct(t);return s|e<<16};function ct(I){const t=new Float32Array([I]),e=new Int32Array(t.buffer)[0];let r=e>>16&32768,n=e>>12&2047;const i=e>>23&255;return i<103?r:i>142?(r|=31744,r|=(i===255?0:1)&&e&8388607,r):i<113?(n|=2048,r|=(n>>114-i)+(n>>113-i&1),r):(r|=i-112<<10|n>>1,r+=n&1,r)}const mt=new ArrayBuffer(4),lt=new DataView(mt),xt=I=>(lt.setUint32(0,I,!0),lt.getFloat32(0,!0));class ht{constructor(t){c(this,"transformA");c(this,"transformB");c(this,"colorTexture");c(this,"orderTexture");c(this,"textureWidth");c(this,"textureHeight");const s=t.numSplats;this.textureWidth=Math.ceil(Math.sqrt(s)),this.textureHeight=Math.ceil(s/this.textureWidth),this.transformA=this.createTransformATexture(t),this.transformB=this.createTransformBTexture(t),this.colorTexture=this.createColorTexture(t),this.orderTexture=this.createOrderTexture(s)}createTransformATexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.positions[a],e[i+1]=t.positions[a+1],e[i+2]=t.positions[a+2];const p=t.rotations[d+0],v=t.rotations[d+1],g=pt(p,v);e[i+3]=xt(g)}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createTransformBTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3,d=n*4;e[i]=t.scales[a],e[i+1]=t.scales[a+1],e[i+2]=t.scales[a+2],e[i+3]=t.rotations[d+2]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r.magFilter=o.NearestFilter,r.minFilter=o.NearestFilter,r}createColorTexture(t){const s=t.numSplats,e=new Float32Array(this.textureWidth*this.textureHeight*4);for(let n=0;n<s;n++){const i=n*4,a=n*3;e[i]=t.colors[a],e[i+1]=t.colors[a+1],e[i+2]=t.colors[a+2],e[i+3]=t.opacities[n]}const r=new o.DataTexture(e,this.textureWidth,this.textureHeight,o.RGBAFormat,o.FloatType);return r.needsUpdate=!0,r}createOrderTexture(t){const s=new Uint32Array(this.textureWidth*this.textureHeight);for(let r=0;r<t;r++)s[r]=r;const e=new o.DataTexture(s,this.textureWidth,this.textureHeight,o.RedIntegerFormat,o.UnsignedIntType);return e.needsUpdate=!0,e}dispose(){this.transformA.dispose(),this.transformB.dispose(),this.colorTexture.dispose(),this.orderTexture.dispose()}}const yt=`
3
3
  precision highp float;
4
4
  precision highp int;
5
5
  precision highp usampler2D;
@@ -254,7 +254,7 @@ void main(void) {
254
254
  vColor = vec4(splatColor, splatOpacity);
255
255
  vUv = clippedCornerOffset;
256
256
  }
257
- `,ye=`
257
+ `,gt=`
258
258
  precision highp float;
259
259
 
260
260
  varying vec4 vColor; // Color and opacity passed from vertex shader
@@ -284,7 +284,7 @@ void main(void) {
284
284
  // Premultiply color by alpha (required for correct blending)
285
285
  gl_FragColor = vec4(vColor.rgb * alpha, alpha);
286
286
  }
287
- `;class de extends i.ShaderMaterial{constructor(e={}){const t={transformA:{value:null},transformB:{value:null},splatColor:{value:null},splatOrder:{value:null},viewport:{value:new i.Vector2(1,1)},numSplats:{value:0}};super({vertexShader:ge,fragmentShader:ye,uniforms:t,transparent:!0,blending:i.CustomBlending,blendSrc:i.OneFactor,blendDst:i.OneMinusSrcAlphaFactor,blendSrcAlpha:i.OneFactor,blendDstAlpha:i.OneMinusSrcAlphaFactor,blendEquation:i.AddEquation,blendEquationAlpha:i.AddEquation,depthTest:!0,depthWrite:!1,side:i.DoubleSide,alphaTest:e.alphaTest!==void 0?e.alphaTest:0,toneMapped:e.toneMapped!==void 0?e.toneMapped:!1}),e.alphaHash&&(this.alphaHash=!0,this.depthWrite=!0,this.blending=i.NoBlending)}updateViewport(e,t){this.uniforms.viewport.value.set(e,t)}setTransformA(e){this.uniforms.transformA.value=e}setTransformB(e){this.uniforms.transformB.value=e}setColorTexture(e){this.uniforms.splatColor.value=e}setOrderTexture(e){this.uniforms.splatOrder.value=e}setNumSplats(e){this.uniforms.numSplats.value=e}}const N=class N extends i.Mesh{constructor(t,o={}){const r=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0;r&&console.debug("[1/8] MESH SplatMesh: creating mesh with",t.numSplats,"splats");const n=new de(o),s=N.createInstancedGeometry(t.numSplats,N.INSTANCE_SIZE);r&&console.debug("[2/8] MESH SplatMesh: created instanced geometry with",Math.ceil(t.numSplats/N.INSTANCE_SIZE),"instances");super(s,n);p(this,"sorter");p(this,"splatData");p(this,"options");p(this,"textureManager");p(this,"material");p(this,"geometry");p(this,"lastCameraPositionLocal",new i.Vector3);p(this,"lastCameraDirectionLocal",new i.Vector3);p(this,"invModelMatrix",new i.Matrix4);this.geometry=s,this.material=n,this.splatData=t,this.frustumCulled=!1,this.options={autoSort:!0,...o},r&&console.debug("[3/8] MESH SplatMesh: initializing texture manager"),this.textureManager=new ue(t),this.sorter=new ae,r&&console.debug("[4/8] MESH SplatMesh: creating chunks for sorter");let a=this.createChunks()||void 0;a===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),a=void 0,r&&console.debug("[5/8] MESH SplatMesh: initializing sorter with",a?"chunks":"no chunks"),this.sorter.init(this.textureManager.orderTexture,this.splatData.centers,a??void 0),this.sorter.addEventListener("updated",c=>{const f=c.count;r&&console.debug("[6/8] MESH SplatMesh: sorter updated, rendering",f,"splats"),this.geometry.instanceCount=Math.ceil(f/N.INSTANCE_SIZE),this.material.setNumSplats(f)}),r&&console.debug("[7/8] MESH SplatMesh: setting up material textures"),this.material.setTransformA(this.textureManager.transformA),this.material.setTransformB(this.textureManager.transformB),this.material.setColorTexture(this.textureManager.colorTexture),this.material.setOrderTexture(this.textureManager.orderTexture),this.material.setNumSplats(0),this.geometry.boundingBox=t.boundingBox.toBox3(),this.geometry.boundingSphere=new i.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere),r&&console.debug("[8/8] MESH SplatMesh: mesh initialization complete, bounding box:",t.boundingBox)}static createInstancedGeometry(t,o){const r=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0,n=Math.ceil(t/o);r&&console.debug("MESH createInstancedGeometry: creating geometry for",t,"splats,",n,"instances");const s=new i.BufferGeometry,a=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),c=new Uint16Array([0,1,2,0,2,3]),f=new Float32Array(4*3*o);for(let d=0;d<o;d++){const S=d*4*3;for(let u=0;u<4;u++)f[S+u*3+0]=a[u*3+0],f[S+u*3+1]=a[u*3+1],f[S+u*3+2]=d}const m=new Uint32Array(6*o);for(let d=0;d<o;d++){const S=d*6,u=d*4;m[S+0]=c[0]+u,m[S+1]=c[1]+u,m[S+2]=c[2]+u,m[S+3]=c[3]+u,m[S+4]=c[4]+u,m[S+5]=c[5]+u}s.setAttribute("position",new i.BufferAttribute(f,3)),s.setIndex(new i.BufferAttribute(m,1));const x=new i.InstancedBufferGeometry;x.index=s.index,x.setAttribute("position",s.getAttribute("position"));const v=new Uint32Array(n);for(let d=0;d<n;d++)v[d]=d*o;return x.setAttribute("splatInstanceIndex",new i.InstancedBufferAttribute(v,1,!1)),x.instanceCount=0,r&&console.debug("MESH createInstancedGeometry: geometry created with",x.attributes.position.count,"vertices"),x}createChunks(){const t=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0,o=this.splatData.boundingBox;if(o.min.x===1/0||o.max.x===-1/0)return t&&console.debug("MESH createChunks: invalid bounding box, cannot create chunks"),null;const r=new Float32Array([o.min.x,o.min.y,o.min.z,o.max.x,o.max.y,o.max.z]);return t&&console.debug("MESH createChunks: created chunks with bounding box",o),r}updateViewport(t,o){(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0&&console.debug("MESH updateViewport: updating viewport to",t,"x",o),this.material.updateViewport(t,o)}sort(t){const o=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0,r=new i.Vector3,n=new i.Vector3;t.getWorldPosition(r),t.getWorldDirection(n),this.invModelMatrix.copy(this.matrixWorld).invert();const s=r.applyMatrix4(this.invModelMatrix),a=n.transformDirection(this.invModelMatrix),c=this.lastCameraPositionLocal.distanceToSquared(s)>1e-6,f=this.lastCameraDirectionLocal.dot(a)<.999;this.options.autoSort&&(c||f)&&(o&&console.debug("MESH sort: camera changed, triggering sort. Position changed:",c,"Direction changed:",f),this.lastCameraPositionLocal.copy(s),this.lastCameraDirectionLocal.copy(a),this.sorter.setCamera(s,a))}onBeforeRender(t,o,r){this.sort(r);const n=t.getSize(new i.Vector2);let{width:s,height:a}=n;const c=t.xr;if(c.enabled&&c.isPresenting){const f=c.getCamera().cameras[0].view;f&&(s=f.width,a=f.height)}this.updateViewport(s,a)}dispose(){const t=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0;t&&console.debug("MESH dispose: cleaning up mesh resources"),this.sorter.dispose(),this.geometry.dispose(),this.material.dispose(),this.textureManager.dispose(),t&&console.debug("MESH dispose: mesh resources cleaned up")}};p(N,"INSTANCE_SIZE",128);let oe=N;class we extends i.Loader{load(e,t,o,r){(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0&&console.debug("[1/12] LOADER PlyLoader: loading",e);const s=new i.FileLoader(this.manager);s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setPath(this.path),s.setWithCredentials(this.withCredentials),s.load(e,a=>{try{if(t){const c=this.parse(a);t(c)}}catch(c){r?r(c):console.error(c),this.manager.itemError(e)}},o,r)}loadAsync(e,t){return new Promise((o,r)=>{const n=new i.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(e,s=>{try{const a=this.parse(s);o(a)}catch(a){r(a),this.manager.itemError(e)}},t,s=>{r(s),this.manager.itemError(e)})})}parse(e){const t=(typeof window<"u"&&window.__VISUS_SPLAT_DEBUG__)===!0;t&&console.debug("[2/12] LOADER PlyLoader: starting parse, buffer size:",e.byteLength);const o=new TextDecoder,r=new Uint8Array(e),n=[112,108,121,10],s=`
287
+ `;class ut extends o.ShaderMaterial{constructor(t={}){const s={transformA:{value:null},transformB:{value:null},splatColor:{value:null},splatOrder:{value:null},viewport:{value:new o.Vector2(1,1)},numSplats:{value:0}};super({vertexShader:yt,fragmentShader:gt,uniforms:s,transparent:!0,blending:o.CustomBlending,blendSrc:o.OneFactor,blendDst:o.OneMinusSrcAlphaFactor,blendSrcAlpha:o.OneFactor,blendDstAlpha:o.OneMinusSrcAlphaFactor,blendEquation:o.AddEquation,blendEquationAlpha:o.AddEquation,depthTest:!0,depthWrite:!1,side:o.DoubleSide,alphaTest:t.alphaTest!==void 0?t.alphaTest:0,toneMapped:t.toneMapped!==void 0?t.toneMapped:!1}),t.alphaHash&&(this.alphaHash=!0,this.depthWrite=!0,this.blending=o.NoBlending)}updateViewport(t,s){this.uniforms.viewport.value.set(t,s)}setTransformA(t){this.uniforms.transformA.value=t}setTransformB(t){this.uniforms.transformB.value=t}setColorTexture(t){this.uniforms.splatColor.value=t}setOrderTexture(t){this.uniforms.splatOrder.value=t}setNumSplats(t){this.uniforms.numSplats.value=t}}const H=class H extends o.Mesh{constructor(s,e={}){const r=new ut(e),n=H.createInstancedGeometry(s.numSplats,H.INSTANCE_SIZE);super(n,r);c(this,"sorter");c(this,"splatData");c(this,"options");c(this,"textureManager");c(this,"material");c(this,"geometry");c(this,"lastCameraPositionLocal",new o.Vector3);c(this,"lastCameraDirectionLocal",new o.Vector3);c(this,"invModelMatrix",new o.Matrix4);c(this,"_vpW",-1);c(this,"_vpH",-1);c(this,"_size",new o.Vector2);c(this,"_camPosW",new o.Vector3);c(this,"_camDirW",new o.Vector3);c(this,"_camPosL",new o.Vector3);c(this,"_camDirL",new o.Vector3);c(this,"onSorterUpdated",s=>{const e=s.count;this.geometry.instanceCount=Math.ceil(e/H.INSTANCE_SIZE),this.material.setNumSplats(e)});this.geometry=n,this.material=r,this.splatData=s,this.frustumCulled=!1,this.options={autoSort:!0,...e},this.textureManager=new ht(s),this.sorter=new at;let i=this.createChunks()||void 0;i===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),i=void 0,this.sorter.addEventListener("updated",this.onSorterUpdated),this.sorter.init(this.textureManager.orderTexture,this.splatData.centers,i??void 0),this.material.setTransformA(this.textureManager.transformA),this.material.setTransformB(this.textureManager.transformB),this.material.setColorTexture(this.textureManager.colorTexture),this.material.setOrderTexture(this.textureManager.orderTexture),this.material.setNumSplats(0),this.geometry.boundingBox=s.boundingBox.toBox3(),this.geometry.boundingSphere=new o.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere)}static createInstancedGeometry(s,e){const r=Math.ceil(s/e),n=new o.BufferGeometry,i=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),a=new Uint16Array([0,1,2,0,2,3]),d=new Float32Array(4*3*e);for(let f=0;f<e;f++){const h=f*4*3;for(let l=0;l<4;l++)d[h+l*3+0]=i[l*3+0],d[h+l*3+1]=i[l*3+1],d[h+l*3+2]=f}const p=new Uint32Array(6*e);for(let f=0;f<e;f++){const h=f*6,l=f*4;p[h+0]=a[0]+l,p[h+1]=a[1]+l,p[h+2]=a[2]+l,p[h+3]=a[3]+l,p[h+4]=a[4]+l,p[h+5]=a[5]+l}n.setAttribute("position",new o.BufferAttribute(d,3)),n.setIndex(new o.BufferAttribute(p,1));const v=new o.InstancedBufferGeometry;v.index=n.index,v.setAttribute("position",n.getAttribute("position"));const g=new Uint32Array(r);for(let f=0;f<r;f++)g[f]=f*e;return v.setAttribute("splatInstanceIndex",new o.InstancedBufferAttribute(g,1,!1)),v.instanceCount=0,v}createChunks(){const s=this.splatData.boundingBox;return s.min.x===1/0||s.max.x===-1/0?null:new Float32Array([s.min.x,s.min.y,s.min.z,s.max.x,s.max.y,s.max.z])}updateViewport(s,e){s===this._vpW&&e===this._vpH||(this._vpW=s,this._vpH=e,this.material.updateViewport(s,e))}sort(s){s.getWorldPosition(this._camPosW),s.getWorldDirection(this._camDirW),this.invModelMatrix.copy(this.matrixWorld).invert(),this._camPosL.copy(this._camPosW).applyMatrix4(this.invModelMatrix),this._camDirL.copy(this._camDirW).transformDirection(this.invModelMatrix);const e=this.lastCameraPositionLocal.distanceToSquared(this._camPosL)>1e-6,r=this.lastCameraDirectionLocal.dot(this._camDirL)<.999;this.options.autoSort&&(e||r)&&(this.lastCameraPositionLocal.copy(this._camPosL),this.lastCameraDirectionLocal.copy(this._camDirL),this.sorter.setCamera(this._camPosL,this._camDirL))}onBeforeRender(s,e,r){this.sort(r),s.getSize(this._size),this.updateViewport(this._size.x,this._size.y)}dispose(){this.sorter.removeEventListener("updated",this.onSorterUpdated),this.sorter.dispose(),this.geometry.dispose(),this.material.dispose(),this.textureManager.dispose()}};c(H,"INSTANCE_SIZE",128);let rt=H;class vt extends o.Loader{load(t,s,e,r){const n=new o.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(t,i=>{try{if(s){const a=this.parse(i);s(a)}}catch(a){r?r(a):console.error(a),this.manager.itemError(t)}},e,r)}loadAsync(t,s){return new Promise((e,r)=>{const n=new o.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(t,i=>{try{const a=this.parse(i);e(a)}catch(a){r(a),this.manager.itemError(t)}},s,i=>{r(i),this.manager.itemError(t)})})}parse(t){const s=new TextDecoder,e=new Uint8Array(t),r=[112,108,121,10],n=`
288
288
  end_header
289
- `;for(let l=0;l<n.length;l++)if(r[l]!==n[l])throw new Error("Invalid PLY file: Missing magic bytes");t&&console.debug("[3/12] LOADER PlyLoader: PLY magic bytes verified");let a=0;for(let l=0;l<r.length-s.length;l++){let h=!0;for(let w=0;w<s.length;w++)if(r[l+w]!==s.charCodeAt(w)){h=!1;break}if(h){a=l+s.length;break}}if(a===0)throw new Error("Invalid PLY file: Could not find end of header");t&&console.debug("[4/12] LOADER PlyLoader: header length:",a);const c=o.decode(r.subarray(0,a));t&&console.debug("[5/12] LOADER PlyLoader: header text:",c);const f=c.split(`
290
- `),m=[];let x=null;for(let l=1;l<f.length;l++){const h=f[l].trim();if(h===""||h==="end_header")continue;const w=h.split(" ");switch(w[0]){case"format":x=w[1],t&&console.debug("[6/12] LOADER PlyLoader: format detected:",x);break;case"element":m.push({name:w[1],count:parseInt(w[2],10),properties:[]}),t&&console.debug("[6/12] LOADER PlyLoader: element found:",w[1],"count:",w[2]);break;case"property":if(m.length===0)throw new Error("Invalid PLY file: Property without element");m[m.length-1].properties.push({type:w[1],name:w[2],storage:null}),t&&console.debug("[6/12] LOADER PlyLoader: property found:",w[2],"type:",w[1]);break}}if(x!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${x}`);const v=m.find(l=>l.name==="vertex");if(!v)throw new Error("Invalid PLY file: No vertex element found");t&&console.debug("[7/12] LOADER PlyLoader: vertex element properties:",v.properties.map(l=>l.name));const d=new ie(v.count);t&&console.debug("[8/12] LOADER PlyLoader: created SplatData for",v.count,"splats");const S=new DataView(e);let u=a;const M=l=>v.properties.findIndex(h=>h.name===l),q=M("x"),j=M("y"),H=M("z"),L=[M("rot_0"),M("rot_1"),M("rot_2"),M("rot_3")],Y=[M("scale_0"),M("scale_1"),M("scale_2")],T=[M("f_dc_0"),M("f_dc_1"),M("f_dc_2")],A=M("opacity");if(t&&console.debug("[9/12] LOADER PlyLoader: property indices:",{position:[q,j,H],rotation:L,scale:Y,color:T,opacity:A}),[q,j,H,...L,...Y,...T,A].some(l=>l===-1))throw new Error("Invalid PLY file: Missing required properties");const C=.28209479177387814,y=l=>{if(l>0)return 1/(1+Math.exp(-l));const h=Math.exp(l);return h/(1+h)};t&&console.debug("[10/12] LOADER PlyLoader: starting binary data parsing, offset:",u);const z=new i.Vector3,_=new i.Quaternion,R=new i.Vector3,B=new i.Color;for(let l=0;l<v.count;l++){t&&l%1e4===0&&console.debug(`[10/12] LOADER PlyLoader: processing splat ${l}/${v.count} (${(l/v.count*100).toFixed(1)}%)`);const h=[];for(let W=0;W<v.properties.length;W++){const U=v.properties[W].type;let V;switch(U){case"char":V=S.getInt8(u),u+=1;break;case"uchar":V=S.getUint8(u),u+=1;break;case"short":V=S.getInt16(u,!0),u+=2;break;case"ushort":V=S.getUint16(u,!0),u+=2;break;case"int":V=S.getInt32(u,!0),u+=4;break;case"uint":V=S.getUint32(u,!0),u+=4;break;case"float":V=S.getFloat32(u,!0),u+=4;break;case"double":V=S.getFloat64(u,!0),u+=8;break;default:throw new Error(`Unsupported property type: ${U}`)}h.push(V)}z.set(h[q],h[j],h[H]),_.set(h[L[1]],h[L[2]],h[L[3]],h[L[0]]).normalize(),t&&l<5&&console.debug(`[10/12] LOADER PlyLoader: splat ${l} rotation:`,{original:[h[L[0]],h[L[1]],h[L[2]],h[L[3]]],processed:[_.x,_.y,_.z,_.w]}),R.set(h[Y[0]],h[Y[1]],h[Y[2]]),B.set(.5+h[T[0]]*C,.5+h[T[1]]*C,.5+h[T[2]]*C),B.r=Math.max(0,Math.min(1,B.r)),B.g=Math.max(0,Math.min(1,B.g)),B.b=Math.max(0,Math.min(1,B.b));const w=y(h[A]);t&&l<3&&console.debug(`[10/12] LOADER PlyLoader: splat ${l} data:`,{position:[z.x,z.y,z.z],rotation:[_.x,_.y,_.z,_.w],scale:[R.x,R.y,R.z],color:[B.r,B.g,B.b],opacity:w}),d.setSplat(l,z,_,R,B,w)}return t&&console.debug("[11/12] LOADER PlyLoader: finished parsing all splats, calculating bounding box"),d.calculateBoundingBox(),t&&console.debug("[12/12] LOADER PlyLoader: parsing complete, bounding box:",{min:[d.boundingBox.min.x,d.boundingBox.min.y,d.boundingBox.min.z],max:[d.boundingBox.max.x,d.boundingBox.max.y,d.boundingBox.max.z]}),d}}const ve="0.3.0";I.BoundingBox=ee,I.PlyLoader=we,I.SplatData=ie,I.SplatMaterial=de,I.SplatMesh=oe,I.SplatSorter=ae,I.TextureManager=ue,I.VERSION=ve,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
289
+ `;for(let x=0;x<r.length;x++)if(e[x]!==r[x])throw new Error("Invalid PLY file: Missing magic bytes");let i=0;for(let x=0;x<e.length-n.length;x++){let u=!0;for(let C=0;C<n.length;C++)if(e[x+C]!==n.charCodeAt(C)){u=!1;break}if(u){i=x+n.length;break}}if(i===0)throw new Error("Invalid PLY file: Could not find end of header");const d=s.decode(e.subarray(0,i)).split(`
290
+ `),p=[];let v=null;for(let x=1;x<d.length;x++){const u=d[x].trim();if(u===""||u==="end_header")continue;const C=u.split(" ");switch(C[0]){case"format":v=C[1];break;case"element":p.push({name:C[1],count:parseInt(C[2],10),properties:[]});break;case"property":if(p.length===0)throw new Error("Invalid PLY file: Property without element");p[p.length-1].properties.push({type:C[1],name:C[2],storage:null});break}}if(v!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${v}`);const g=p.find(x=>x.name==="vertex");if(!g)throw new Error("Invalid PLY file: No vertex element found");const f=new it(g.count),h=new DataView(t);let l=i;const b=x=>g.properties.findIndex(u=>u.name===x),_=b("x"),q=b("y"),W=b("z"),R=[b("rot_0"),b("rot_1"),b("rot_2"),b("rot_3")],j=[b("scale_0"),b("scale_1"),b("scale_2")],N=[b("f_dc_0"),b("f_dc_1"),b("f_dc_2")],D=b("opacity");if([_,q,W,...R,...j,...N,D].some(x=>x===-1))throw new Error("Invalid PLY file: Missing required properties");const F=.28209479177387814,M=x=>{if(x>0)return 1/(1+Math.exp(-x));const u=Math.exp(x);return u/(1+u)},m=new o.Vector3,k=new o.Quaternion,U=new o.Vector3,E=new o.Color;for(let x=0;x<g.count;x++){const u=[];for(let T=0;T<g.properties.length;T++){const st=g.properties[T].type;let A;switch(st){case"char":A=h.getInt8(l),l+=1;break;case"uchar":A=h.getUint8(l),l+=1;break;case"short":A=h.getInt16(l,!0),l+=2;break;case"ushort":A=h.getUint16(l,!0),l+=2;break;case"int":A=h.getInt32(l,!0),l+=4;break;case"uint":A=h.getUint32(l,!0),l+=4;break;case"float":A=h.getFloat32(l,!0),l+=4;break;case"double":A=h.getFloat64(l,!0),l+=8;break;default:throw new Error(`Unsupported property type: ${st}`)}u.push(A)}m.set(u[_],u[q],u[W]),k.set(u[R[1]],u[R[2]],u[R[3]],u[R[0]]).normalize(),U.set(u[j[0]],u[j[1]],u[j[2]]),E.set(.5+u[N[0]]*F,.5+u[N[1]]*F,.5+u[N[2]]*F),E.r=Math.max(0,Math.min(1,E.r)),E.g=Math.max(0,Math.min(1,E.g)),E.b=Math.max(0,Math.min(1,E.b));const C=M(u[D]);f.setSplat(x,m,k,U,E,C)}return f.calculateBoundingBox(),f}}const wt="0.3.0";z.BoundingBox=Q,z.PlyLoader=vt,z.SplatData=it,z.SplatMaterial=ut,z.SplatMesh=rt,z.SplatSorter=at,z.TextureManager=ht,z.VERSION=wt,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});