@speridlabs/visus 2.4.0 → 2.4.1
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.d.ts +1 -0
- package/dist/main.es.js +3 -0
- package/dist/main.umd.js +1 -1
- package/dist/react.es.js +3 -0
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ export declare class PlyLoader extends THREE.Loader {
|
|
|
94
94
|
* Class for loading SOGS (Self Organizing Gaussians) files
|
|
95
95
|
*/
|
|
96
96
|
export declare class SogsLoader extends THREE.Loader {
|
|
97
|
+
constructor(manager?: THREE.LoadingManager);
|
|
97
98
|
/**
|
|
98
99
|
* Detect if a buffer is a ZIP file by checking magic bytes
|
|
99
100
|
* ZIP files start with signature: PK\x03\x04 (0x50 0x4B 0x03 0x04)
|
package/dist/main.es.js
CHANGED
|
@@ -1848,6 +1848,9 @@ const Ee = (a) => {
|
|
|
1848
1848
|
};
|
|
1849
1849
|
};
|
|
1850
1850
|
class ft extends h.Loader {
|
|
1851
|
+
constructor(e) {
|
|
1852
|
+
super(e), this.withCredentials = !0;
|
|
1853
|
+
}
|
|
1851
1854
|
/**
|
|
1852
1855
|
* Detect if a buffer is a ZIP file by checking magic bytes
|
|
1853
1856
|
* ZIP files start with signature: PK\x03\x04 (0x50 0x4B 0x03 0x04)
|
package/dist/main.umd.js
CHANGED
|
@@ -256,4 +256,4 @@ void main(void) {
|
|
|
256
256
|
`;class Re extends h.ShaderMaterial{constructor(e={}){const t={packedGeometry:{value:null},packedColor:{value:null},splatOrder:{value:null},meansMin:{value:new h.Vector3},meansMax:{value:new h.Vector3},scalesMin:{value:new h.Vector3},scalesMax:{value:new h.Vector3},sh0Min:{value:new h.Vector3},sh0Max:{value:new h.Vector3},texWidth:{value:0},viewport:{value:new h.Vector2(1,1)},numSplats:{value:0}};super({uniforms:t,vertexShader:Ne,fragmentShader:He,transparent:!0,glslVersion:h.GLSL3,blendSrc:h.OneFactor,blendSrcAlpha:h.OneFactor,blending:h.CustomBlending,blendEquation:h.AddEquation,blendEquationAlpha:h.AddEquation,blendDst:h.OneMinusSrcAlphaFactor,blendDstAlpha:h.OneMinusSrcAlphaFactor,depthTest:!0,depthWrite:!1,side:h.DoubleSide,alphaTest:e.alphaTest??0,toneMapped:e.toneMapped??!1}),e.alphaHash&&(this.alphaHash=!0,this.depthWrite=!0,this.blending=h.NoBlending)}setTexWidth(e){this.uniforms.texWidth.value=e|0}updateViewport(e,t){this.uniforms.viewport.value.set(e,t)}setPackedGeometry(e){this.uniforms.packedGeometry.value=e}setPackedColor(e){this.uniforms.packedColor.value=e}setOrderTexture(e){this.uniforms.splatOrder.value=e}setRanges(e){this.uniforms.meansMin.value.copy(e.means.min),this.uniforms.meansMax.value.copy(e.means.max),this.uniforms.scalesMin.value.copy(e.scales.min),this.uniforms.scalesMax.value.copy(e.scales.max),this.uniforms.sh0Min.value.copy(e.sh0.min),this.uniforms.sh0Max.value.copy(e.sh0.max)}setNumSplats(e){this.uniforms.numSplats.value=e}}const ye=class ye extends h.Mesh{constructor(t,s={}){const r=new Re(s),n=ye.createInstancedGeometry(t.numSplats,ye.INSTANCE_SIZE);super(n,r);w(this,"sorter");w(this,"options");w(this,"splatData");w(this,"textureManager");w(this,"material");w(this,"geometry");w(this,"lastCameraPositionLocal",new h.Vector3);w(this,"lastCameraDirectionLocal",new h.Vector3);w(this,"invModelMatrix",new h.Matrix4);w(this,"_vpW",-1);w(this,"_vpH",-1);w(this,"_size",new h.Vector2);w(this,"_camPosW",new h.Vector3);w(this,"_camDirW",new h.Vector3);w(this,"_camPosL",new h.Vector3);w(this,"_camDirL",new h.Vector3);w(this,"onSorterUpdated",t=>{const s=t.count;this.geometry.instanceCount=Math.ceil(s/ye.INSTANCE_SIZE),this.material.setNumSplats(s)});this.geometry=n,this.material=r,this.options={autoSort:!0,...s},this.splatData=t,this.frustumCulled=!1,this.sorter=new Fe,this.textureManager=new Pe(t);let o=this.createChunks()||void 0;o===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),o=void 0,this.sorter.addEventListener("updated",this.onSorterUpdated),this.sorter.init(this.textureManager.orderTexture,this.splatData.centers,o??void 0,!this.options.keepSplatData),this.material.setRanges(t.ranges),this.material.setTexWidth(t.textureWidth),this.material.setPackedColor(this.textureManager.packedColor),this.material.setOrderTexture(this.textureManager.orderTexture),this.material.setPackedGeometry(this.textureManager.packedGeometry),this.material.setNumSplats(0),this.geometry.boundingBox=t.boundingBox.toBox3(),this.geometry.boundingSphere=new h.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere),this.options.keepSplatData||(this.splatData=null)}static createInstancedGeometry(t,s){const r=Math.ceil(t/s),n=new h.BufferGeometry,o=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),i=new Uint16Array([0,1,2,0,2,3]),u=new Float32Array(4*3*s);for(let l=0;l<s;l++){const p=l*4*3;for(let y=0;y<4;y++)u[p+y*3+0]=o[y*3+0],u[p+y*3+1]=o[y*3+1],u[p+y*3+2]=l}const m=new Uint32Array(6*s);for(let l=0;l<s;l++){const p=l*6,y=l*4;m[p+0]=i[0]+y,m[p+1]=i[1]+y,m[p+2]=i[2]+y,m[p+3]=i[3]+y,m[p+4]=i[4]+y,m[p+5]=i[5]+y}n.setAttribute("position",new h.BufferAttribute(u,3)),n.setIndex(new h.BufferAttribute(m,1));const x=new h.InstancedBufferGeometry;x.index=n.index,x.setAttribute("position",n.getAttribute("position"));const c=new Uint32Array(r);for(let l=0;l<r;l++)c[l]=l*s;return x.setAttribute("splatInstanceIndex",new h.InstancedBufferAttribute(c,1,!1)),x.instanceCount=0,x}createChunks(){if(!this.splatData)return null;const t=this.splatData.boundingBox;return t.min.x===1/0||t.max.x===-1/0?null:new Float32Array([t.min.x,t.min.y,t.min.z,t.max.x,t.max.y,t.max.z])}updateViewport(t,s){t===this._vpW&&s===this._vpH||(this._vpW=t,this._vpH=s,this.material.updateViewport(t,s))}sort(t){t.getWorldPosition(this._camPosW),t.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 s=this.lastCameraPositionLocal.distanceToSquared(this._camPosL)>1e-6,r=this.lastCameraDirectionLocal.dot(this._camDirL)<.999;this.options.autoSort&&(s||r)&&(this.lastCameraPositionLocal.copy(this._camPosL),this.lastCameraDirectionLocal.copy(this._camDirL),this.sorter.setCamera(this._camPosL,this._camDirL))}onBeforeRender(t,s,r){this.sort(r),t.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()}};w(ye,"INSTANCE_SIZE",128);let be=ye;const pe=.28209479177387814;class Se{static packPly(e){const t=e.numSplats,s=Math.ceil(Math.sqrt(t)),r=Math.ceil(t/s),n=s*r,{ranges:o,colorScale:i}=this.calculatePlyRanges(e),u=new Uint32Array(n*4),m=new Uint8Array(n*4),x=new h.Quaternion;for(let c=0;c<t;c++){const l=c*4,p=c*3,y=c*4,M=e.positions[p+0],v=e.positions[p+1],S=e.positions[p+2],k=this.clamp01(this.norm(M,o.means.min.x,o.means.max.x)),B=this.clamp01(this.norm(v,o.means.min.y,o.means.max.y)),H=this.clamp01(this.norm(S,o.means.min.z,o.means.max.z)),R=k*65535|0,b=B*65535|0,A=H*65535|0;u[l+0]=this.pack4Bytes(R&255,b&255,A&255,0),u[l+1]=this.pack4Bytes(R>>8,b>>8,A>>8,0),x.set(e.rotations[y],e.rotations[y+1],e.rotations[y+2],e.rotations[y+3]).normalize();let C=x.w,g=x.x,d=x.y,I=x.z;const F=Math.abs(C),T=Math.abs(g),j=Math.abs(d),U=Math.abs(I);let q=0,P=F;T>P&&(P=T,q=1),j>P&&(P=j,q=2),U>P&&(P=U,q=3),(q===0?C:q===1?g:q===2?d:I)<0&&(C=-C,g=-g,d=-d,I=-I);let W=0,L=0,Q=0;q===0&&(W=g,L=d,Q=I),q===1&&(W=C,L=d,Q=I),q===2&&(W=C,L=g,Q=I),q===3&&(W=C,L=g,Q=d);const Z=ie=>Math.min(255,Math.max(0,Math.round((.5+ie/Math.SQRT2)*255)));u[l+2]=this.pack4Bytes(Z(W),Z(L),Z(Q),q);const Y=this.norm(e.scales[p+0],o.scales.min.x,o.scales.max.x),z=this.norm(e.scales[p+1],o.scales.min.y,o.scales.max.y),f=this.norm(e.scales[p+2],o.scales.min.z,o.scales.max.z);u[l+3]=this.pack4Bytes(Math.floor(Y*255),Math.floor(z*255),Math.floor(f*255),0);const E=this.clamp01(e.colors[p+0]*i),V=this.clamp01(e.colors[p+1]*i),D=this.clamp01(e.colors[p+2]*i),O=(E-.5)/pe,$=(V-.5)/pe,X=(D-.5)/pe,J=this.clamp01(this.norm(O,o.sh0.min.x,o.sh0.max.x)),N=this.clamp01(this.norm($,o.sh0.min.y,o.sh0.max.y)),ee=this.clamp01(this.norm(X,o.sh0.min.z,o.sh0.max.z)),oe=this.clamp01(e.opacities[c]);m[l+0]=Math.round(J*255),m[l+1]=Math.round(N*255),m[l+2]=Math.round(ee*255),m[l+3]=Math.round(oe*255)}return new Me(t,s,r,e.positions,u,m,o,e.boundingBox)}static packSogs(e){const t=e.numSplats,s=Math.ceil(Math.sqrt(t)),r=Math.ceil(t/s),n=s*r,o=this.convertSogsRanges(e.ranges),i=e.ranges.means.mins[0],u=e.ranges.means.mins[1],m=e.ranges.means.mins[2],x=e.ranges.means.maxs[0],c=e.ranges.means.maxs[1],l=e.ranges.means.maxs[2],p=g=>Math.sign(g)*(Math.exp(Math.abs(g))-1),y=new h.Vector3(p(i),p(u),p(m)),M=new h.Vector3(p(x),p(c),p(l));o.means.min.copy(y),o.means.max.copy(M);const v=e,S=this.getPixels(v.means_l),k=this.getPixels(v.means_u),B=this.getPixels(v.quats),H=this.getPixels(v.scales),R=this.getPixels(v.sh0),b=new Uint32Array(n*4),A=new Uint8Array(n*4),C=new Float32Array(t*3);for(let g=0;g<t;g++){const d=g*4,I=k[d+0],F=S[d+0],T=k[d+1],j=S[d+1],U=k[d+2],q=S[d+2],P=(I<<8|F)/65535,K=(T<<8|j)/65535,W=(U<<8|q)/65535,L=this.sogsDecode(P,i,x),Q=this.sogsDecode(K,u,c),Z=this.sogsDecode(W,m,l);C[g*3+0]=L,C[g*3+1]=Q,C[g*3+2]=Z;const Y=this.clamp01(this.norm(L,y.x,M.x))*65535|0,z=this.clamp01(this.norm(Q,y.y,M.y))*65535|0,f=this.clamp01(this.norm(Z,y.z,M.z))*65535|0;b[d+0]=this.pack4Bytes(Y&255,z&255,f&255,0),b[d+1]=this.pack4Bytes(Y>>8,z>>8,f>>8,0),b[d+3]=this.pack4Bytes(H[d],H[d+1],H[d+2],0);const V=B[d+3]-252;b[d+2]=this.pack4Bytes(B[d+0],B[d+1],B[d+2],V),A[d+0]=R[d],A[d+1]=R[d+1],A[d+2]=R[d+2];const D=R[d+3]/255,O=e.ranges.sh0.mins[3]+(e.ranges.sh0.maxs[3]-e.ranges.sh0.mins[3])*D,$=1/(1+Math.exp(-O));A[d+3]=Math.round(Math.max(0,Math.min(1,$))*255)}return new Me(t,s,r,C,b,A,o,e.boundingBox)}static pack4Bytes(e,t,s,r){return(e&255)<<24|(t&255)<<16|(s&255)<<8|r&255}static getPixels(e){const t=e.image,s=t.width,r=t.height;if(t.data&&(t.data instanceof Uint8Array||t.data instanceof Uint8ClampedArray))return new Uint8Array(t.data);const n=document.createElement("canvas");n.width=s,n.height=r;const o=n.getContext("2d",{willReadFrequently:!0});if(!o)throw new Error("Canvas init failed");return o.drawImage(t,0,0),new Uint8Array(o.getImageData(0,0,s,r).data)}static convertSogsRanges(e){const t=s=>new h.Vector3(s[0],s[1],s[2]);return{sh0:{min:t(e.sh0.mins),max:t(e.sh0.maxs)},means:{min:t(e.means.mins),max:t(e.means.maxs)},scales:{min:t(e.scales.mins),max:t(e.scales.maxs)}}}static calculatePlyRanges(e){const t=new h.Vector3(1/0,1/0,1/0),s=new h.Vector3(-1/0,-1/0,-1/0),r=new h.Vector3(1/0,1/0,1/0),n=new h.Vector3(-1/0,-1/0,-1/0),o=new h.Vector3(1/0,1/0,1/0),i=new h.Vector3(-1/0,-1/0,-1/0);let u=0;for(let x=0;x<e.numSplats;x++){const c=x*3,l=e.positions[c+0],p=e.positions[c+1],y=e.positions[c+2];t.x=Math.min(t.x,l),s.x=Math.max(s.x,l),t.y=Math.min(t.y,p),s.y=Math.max(s.y,p),t.z=Math.min(t.z,y),s.z=Math.max(s.z,y),r.x=Math.min(r.x,e.scales[c]),n.x=Math.max(n.x,e.scales[c]),r.y=Math.min(r.y,e.scales[c+1]),n.y=Math.max(n.y,e.scales[c+1]),r.z=Math.min(r.z,e.scales[c+2]),n.z=Math.max(n.z,e.scales[c+2]),u=Math.max(u,e.colors[c],e.colors[c+1],e.colors[c+2])}const m=u>1.5?1/255:1;for(let x=0;x<e.numSplats;x++){const c=x*3,l=this.clamp01(e.colors[c+0]*m),p=this.clamp01(e.colors[c+1]*m),y=this.clamp01(e.colors[c+2]*m),M=(l-.5)/pe,v=(p-.5)/pe,S=(y-.5)/pe;o.x=Math.min(o.x,M),i.x=Math.max(i.x,M),o.y=Math.min(o.y,v),i.y=Math.max(i.y,v),o.z=Math.min(o.z,S),i.z=Math.max(i.z,S)}return{colorScale:m,ranges:{sh0:{min:o,max:i},means:{min:t,max:s},scales:{min:r,max:n}}}}static clamp01(e){return Math.max(0,Math.min(1,e))}static norm(e,t,s){return(e-t)/(s-t||1)}static sogsDecode(e,t,s){const r=t+(s-t)*e;return Math.sign(r)*(Math.exp(Math.abs(r))-1)}}class Ye extends h.Loader{constructor(t){super(t);w(this,"requestId",0);w(this,"worker");w(this,"pendingCallbacks",new Map);this.withCredentials=!0;const s=this.createWorkerCode(),r=new Blob([s],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(r)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(t){const{requestId:s,error:r,result:n}=t.data,o=this.pendingCallbacks.get(s);if(!o)return console.warn(`PlyLoader: Received response for unknown request ${s}`);if(this.pendingCallbacks.delete(s),r)return o.reject(new Error(r));if(!n)return o.reject(new Error("Worker returned no result"));try{const i=new je(0);i.numSplats=n.numSplats,i.positions=new Float32Array(n.positions),i.rotations=new Float32Array(n.rotations),i.scales=new Float32Array(n.scales),i.colors=new Float32Array(n.colors),i.opacities=new Float32Array(n.opacities),i.boundingBox.min.set(n.boundingBox.minX,n.boundingBox.minY,n.boundingBox.minZ),i.boundingBox.max.set(n.boundingBox.maxX,n.boundingBox.maxY,n.boundingBox.maxZ),this.worker.terminate();const u=Se.packPly(i);i.dispose(),o.resolve(u)}catch(i){o.reject(i)}}load(t,s,r,n){const o=new h.FileLoader(this.manager);o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(this.withCredentials),o.load(t,i=>{this.parseAsync(i).then(u=>{s&&s(u)}).catch(u=>{n?n(u):console.error(u),this.manager.itemError(t)})},r,n)}loadAsync(t,s){return new Promise((r,n)=>{const o=new h.FileLoader(this.manager);o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(this.withCredentials),o.load(t,i=>{this.parseAsync(i).then(r).catch(u=>{n(u),this.manager.itemError(t)})},s,i=>{n(i),this.manager.itemError(t)})})}parseAsync(t){return new Promise((s,r)=>{const n=this.requestId++;this.pendingCallbacks.set(n,{resolve:s,reject:r});const o={requestId:n,buffer:t};this.worker.postMessage(o,[t])})}dispose(){this.worker&&this.worker.terminate(),this.pendingCallbacks.clear()}createWorkerCode(){return`(${(function(){self.onmessage=r=>{const{requestId:n,buffer:o}=r.data;try{const i=s(o),u={requestId:n,result:i};self.postMessage(u,[i.positions,i.rotations,i.scales,i.colors,i.opacities])}catch(i){const u={requestId:n,error:i instanceof Error?i.message:String(i)};self.postMessage(u)}};function s(r){const n=new TextDecoder,o=new Uint8Array(r),i=[112,108,121,10],u=`
|
|
257
257
|
end_header
|
|
258
258
|
`;for(let z=0;z<i.length;z++)if(o[z]!==i[z])throw new Error("Invalid PLY file: Missing magic bytes");let m=0;for(let z=0;z<o.length-u.length;z++){let f=!0;for(let E=0;E<u.length;E++)if(o[z+E]!==u.charCodeAt(E)){f=!1;break}if(f){m=z+u.length;break}}if(m===0)throw new Error("Invalid PLY file: Could not find end of header");const c=n.decode(o.subarray(0,m)).split(`
|
|
259
|
-
`),l=[];let p=null;for(let z=1;z<c.length;z++){const f=c[z].trim();if(f===""||f==="end_header")continue;const E=f.split(" ");switch(E[0]){case"format":p=E[1];break;case"element":l.push({name:E[1],count:parseInt(E[2],10),properties:[]});break;case"property":if(l.length===0)throw new Error("Invalid PLY file: Property without element");l[l.length-1].properties.push({type:E[1],name:E[2]});break}}if(p!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${p}`);const y=l.find(z=>z.name==="vertex");if(!y)throw new Error("Invalid PLY file: No vertex element found");const M=y.count,v=new Float32Array(M*3),S=new Float32Array(M*4),k=new Float32Array(M*3),B=new Float32Array(M*3),H=new Float32Array(M),R=new DataView(r);let b=m;const A=z=>y.properties.findIndex(f=>f.name===z),C=A("x"),g=A("y"),d=A("z"),I=[A("rot_0"),A("rot_1"),A("rot_2"),A("rot_3")],F=[A("scale_0"),A("scale_1"),A("scale_2")],T=[A("f_dc_0"),A("f_dc_1"),A("f_dc_2")],j=A("opacity");if([C,g,d,...I,...F,...T,j].some(z=>z===-1))throw new Error("Invalid PLY file: Missing required properties");const q=.28209479177387814,P=z=>{if(z>0)return 1/(1+Math.exp(-z));const f=Math.exp(z);return f/(1+f)};let K=1/0,W=1/0,L=1/0,Q=-1/0,Z=-1/0,Y=-1/0;for(let z=0;z<M;z++){const f=[];for(let Ee=0;Ee<y.properties.length;Ee++){const We=y.properties[Ee].type;let he;switch(We){case"char":he=R.getInt8(b),b+=1;break;case"uchar":he=R.getUint8(b),b+=1;break;case"short":he=R.getInt16(b,!0),b+=2;break;case"ushort":he=R.getUint16(b,!0),b+=2;break;case"int":he=R.getInt32(b,!0),b+=4;break;case"uint":he=R.getUint32(b,!0),b+=4;break;case"float":he=R.getFloat32(b,!0),b+=4;break;case"double":he=R.getFloat64(b,!0),b+=8;break;default:throw new Error(`Unsupported property type: ${We}`)}f.push(he)}const E=f[C],V=f[g],D=f[d],O=z*3;v[O]=E,v[O+1]=V,v[O+2]=D,K=Math.min(K,E),W=Math.min(W,V),L=Math.min(L,D),Q=Math.max(Q,E),Z=Math.max(Z,V),Y=Math.max(Y,D);let $=f[I[1]],X=f[I[2]],J=f[I[3]],N=f[I[0]];const ee=Math.sqrt($*$+X*X+J*J+N*N);ee>0&&($/=ee,X/=ee,J/=ee,N/=ee),N<0&&($=-$,X=-X,J=-J,N=-N);const oe=z*4;S[oe]=$,S[oe+1]=X,S[oe+2]=J,S[oe+3]=N;const ie=z*3;k[ie]=f[F[0]],k[ie+1]=f[F[1]],k[ie+2]=f[F[2]];let me=.5+f[T[0]]*q,de=.5+f[T[1]]*q,le=.5+f[T[2]]*q;me=Math.max(0,Math.min(1,me)),de=Math.max(0,Math.min(1,de)),le=Math.max(0,Math.min(1,le));const De=z*3;B[De]=me,B[De+1]=de,B[De+2]=le,H[z]=P(f[j])}return{numSplats:M,positions:v.buffer,rotations:S.buffer,scales:k.buffer,colors:B.buffer,opacities:H.buffer,boundingBox:{minX:K,minY:W,minZ:L,maxX:Q,maxY:Z,maxZ:Y}}}}).toString()})();`}}var se=Uint8Array,xe=Uint16Array,$e=Int32Array,Te=new se([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ue=new se([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ze=new se([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_e=function(a,e){for(var t=new xe(31),s=0;s<31;++s)t[s]=e+=1<<a[s-1];for(var r=new $e(t[30]),s=1;s<30;++s)for(var n=t[s];n<t[s+1];++n)r[n]=n-t[s]<<5|s;return{b:t,r}},Ve=_e(Te,2),Oe=Ve.b,Xe=Ve.r;Oe[28]=258,Xe[258]=28;for(var Qe=_e(Ue,0),Je=Qe.b,Ae=new xe(32768),_=0;_<32768;++_){var ue=(_&43690)>>1|(_&21845)<<1;ue=(ue&52428)>>2|(ue&13107)<<2,ue=(ue&61680)>>4|(ue&3855)<<4,Ae[_]=((ue&65280)>>8|(ue&255)<<8)>>1}for(var we=function(a,e,t){for(var s=a.length,r=0,n=new xe(e);r<s;++r)a[r]&&++n[a[r]-1];var o=new xe(e);for(r=1;r<e;++r)o[r]=o[r-1]+n[r-1]<<1;var i;if(t){i=new xe(1<<e);var u=15-e;for(r=0;r<s;++r)if(a[r])for(var m=r<<4|a[r],x=e-a[r],c=o[a[r]-1]++<<x,l=c|(1<<x)-1;c<=l;++c)i[Ae[c]>>u]=m}else for(i=new xe(s),r=0;r<s;++r)a[r]&&(i[r]=Ae[o[a[r]-1]++]>>15-a[r]);return i},ve=new se(288),_=0;_<144;++_)ve[_]=8;for(var _=144;_<256;++_)ve[_]=9;for(var _=256;_<280;++_)ve[_]=7;for(var _=280;_<288;++_)ve[_]=8;for(var Le=new se(32),_=0;_<32;++_)Le[_]=5;var Ke=we(ve,9,1),et=we(Le,5,1),Ie=function(a){for(var e=a[0],t=1;t<a.length;++t)a[t]>e&&(e=a[t]);return e},ne=function(a,e,t){var s=e/8|0;return(a[s]|a[s+1]<<8)>>(e&7)&t},ke=function(a,e){var t=e/8|0;return(a[t]|a[t+1]<<8|a[t+2]<<16)>>(e&7)},tt=function(a){return(a+7)/8|0},Ce=function(a,e,t){return(e==null||e<0)&&(e=0),(t==null||t>a.length)&&(t=a.length),new se(a.subarray(e,t))},st=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],re=function(a,e,t){var s=new Error(e||st[a]);if(s.code=a,Error.captureStackTrace&&Error.captureStackTrace(s,re),!t)throw s;return s},rt=function(a,e,t,s){var r=a.length,n=s?s.length:0;if(!r||e.f&&!e.l)return t||new se(0);var o=!t,i=o||e.i!=2,u=e.i;o&&(t=new se(r*3));var m=function(X){var J=t.length;if(X>J){var N=new se(Math.max(J*2,X));N.set(t),t=N}},x=e.f||0,c=e.p||0,l=e.b||0,p=e.l,y=e.d,M=e.m,v=e.n,S=r*8;do{if(!p){x=ne(a,c,1);var k=ne(a,c+1,3);if(c+=3,k)if(k==1)p=Ke,y=et,M=9,v=5;else if(k==2){var b=ne(a,c,31)+257,A=ne(a,c+10,15)+4,C=b+ne(a,c+5,31)+1;c+=14;for(var g=new se(C),d=new se(19),I=0;I<A;++I)d[Ze[I]]=ne(a,c+I*3,7);c+=A*3;for(var F=Ie(d),T=(1<<F)-1,j=we(d,F,1),I=0;I<C;){var U=j[ne(a,c,T)];c+=U&15;var B=U>>4;if(B<16)g[I++]=B;else{var q=0,P=0;for(B==16?(P=3+ne(a,c,3),c+=2,q=g[I-1]):B==17?(P=3+ne(a,c,7),c+=3):B==18&&(P=11+ne(a,c,127),c+=7);P--;)g[I++]=q}}var K=g.subarray(0,b),W=g.subarray(b);M=Ie(K),v=Ie(W),p=we(K,M,1),y=we(W,v,1)}else re(1);else{var B=tt(c)+4,H=a[B-4]|a[B-3]<<8,R=B+H;if(R>r){u&&re(0);break}i&&m(l+H),t.set(a.subarray(B,R),l),e.b=l+=H,e.p=c=R*8,e.f=x;continue}if(c>S){u&&re(0);break}}i&&m(l+131072);for(var L=(1<<M)-1,Q=(1<<v)-1,Z=c;;Z=c){var q=p[ke(a,c)&L],Y=q>>4;if(c+=q&15,c>S){u&&re(0);break}if(q||re(2),Y<256)t[l++]=Y;else if(Y==256){Z=c,p=null;break}else{var z=Y-254;if(Y>264){var I=Y-257,f=Te[I];z=ne(a,c,(1<<f)-1)+Oe[I],c+=f}var E=y[ke(a,c)&Q],V=E>>4;E||re(3),c+=E&15;var W=Je[V];if(V>3){var f=Ue[V];W+=ke(a,c)&(1<<f)-1,c+=f}if(c>S){u&&re(0);break}i&&m(l+131072);var D=l+z;if(l<W){var O=n-W,$=Math.min(W,D);for(O+l<0&&re(3);l<$;++l)t[l]=s[O+l]}for(;l<D;++l)t[l]=t[l-W]}}e.l=p,e.p=Z,e.b=l,e.f=x,p&&(x=1,e.m=M,e.d=y,e.n=v)}while(!x);return l!=t.length&&o?Ce(t,0,l):t.subarray(0,l)},nt=new se(0),ce=function(a,e){return a[e]|a[e+1]<<8},ae=function(a,e){return(a[e]|a[e+1]<<8|a[e+2]<<16|a[e+3]<<24)>>>0},ze=function(a,e){return ae(a,e)+ae(a,e+4)*4294967296};function at(a,e){return rt(a,{i:2},e&&e.out,e&&e.dictionary)}var Be=typeof TextDecoder<"u"&&new TextDecoder,ot=0;try{Be.decode(nt,{stream:!0}),ot=1}catch{}var it=function(a){for(var e="",t=0;;){var s=a[t++],r=(s>127)+(s>223)+(s>239);if(t+r>a.length)return{s:e,r:Ce(a,t-1)};r?r==3?(s=((s&15)<<18|(a[t++]&63)<<12|(a[t++]&63)<<6|a[t++]&63)-65536,e+=String.fromCharCode(55296|s>>10,56320|s&1023)):r&1?e+=String.fromCharCode((s&31)<<6|a[t++]&63):e+=String.fromCharCode((s&15)<<12|(a[t++]&63)<<6|a[t++]&63):e+=String.fromCharCode(s)}};function ct(a,e){if(e){for(var t="",s=0;s<a.length;s+=16384)t+=String.fromCharCode.apply(null,a.subarray(s,s+16384));return t}else{if(Be)return Be.decode(a);var r=it(a),n=r.s,t=r.r;return t.length&&re(8),n}}var lt=function(a,e){return e+30+ce(a,e+26)+ce(a,e+28)},ht=function(a,e,t){var s=ce(a,e+28),r=ct(a.subarray(e+46,e+46+s),!(ce(a,e+8)&2048)),n=e+46+s,o=ae(a,e+20),i=t&&o==4294967295?ut(a,n):[o,ae(a,e+24),ae(a,e+42)],u=i[0],m=i[1],x=i[2];return[ce(a,e+10),u,m,r,n+ce(a,e+30)+ce(a,e+32),x]},ut=function(a,e){for(;ce(a,e)!=1;e+=4+ce(a,e+2));return[ze(a,e+12),ze(a,e+4),ze(a,e+20)]};function mt(a,e){for(var t={},s=a.length-22;ae(a,s)!=101010256;--s)(!s||a.length-s>65558)&&re(13);var r=ce(a,s+8);if(!r)return{};var n=ae(a,s+16),o=n==4294967295||r==65535;if(o){var i=ae(a,s-12);o=ae(a,i)==101075792,o&&(r=ae(a,i+32),n=ae(a,i+48))}for(var u=0;u<r;++u){var m=ht(a,n,o),x=m[0],c=m[1],l=m[2],p=m[3],y=m[4],M=m[5],v=lt(a,M);n=y,x?x==8?t[p]=at(a.subarray(v,v+c),{out:new se(l)}):re(14,"unknown compression type "+x):t[p]=Ce(a,v,v+c)}return t}const Ge=a=>{if(typeof a!="object"||a===null)throw new Error("Invalid SOGS metadata: not an object");const e=a,t=e.version??1;if(t!==1)throw new Error(`Unsupported SOGS version: ${String(t)}`);const s=M=>{const v=e[M];if(typeof v!="object"||v===null)throw new Error(`Invalid SOGS metadata section: ${M}`);return v},r=s("means"),n=s("sh0"),o=s("quats"),i=s("scales"),u=typeof e.count=="number"&&Number.isFinite(e.count)?e.count:void 0,m=Array.isArray(r.shape)?r.shape:void 0,x=m&&typeof m[0]=="number"?m[0]:void 0;if(u===void 0&&x===void 0)throw new Error("Invalid SOGS metadata: unable to determine splat count");if(u!==void 0&&x!==void 0&&u!==x)throw new Error("Inconsistent SOGS metadata: count does not match means.shape[0]");const c=u??x,l=(M,v)=>{const S=M.mins,k=M.maxs;if(!Array.isArray(S)||S.length!==3)throw new Error(`${v}.mins must be length-3`);if(!Array.isArray(k)||k.length!==3)throw new Error(`${v}.maxs must be length-3`);if(![...S,...k].every(B=>typeof B=="number"&&Number.isFinite(B)))throw new Error(`${v}.mins/maxs must be finite numbers`);return{mins:[S[0],S[1],S[2]],maxs:[k[0],k[1],k[2]]}},p=(M,v)=>{const S=M.mins,k=M.maxs;if(!Array.isArray(S)||S.length!==4)throw new Error(`${v}.mins must be length-4`);if(!Array.isArray(k)||k.length!==4)throw new Error(`${v}.maxs must be length-4`);if(![...S,...k].every(B=>typeof B=="number"&&Number.isFinite(B)))throw new Error(`${v}.mins/maxs must be finite numbers`);return{mins:[S[0],S[1],S[2],S[3]],maxs:[k[0],k[1],k[2],k[3]]}},y=(M,v)=>{const S=M.files;if(!Array.isArray(S))throw new Error(`${v}.files is not an array`);if(!S.every(k=>typeof k=="string"))throw new Error(`${v}.files contains non-strings`);return S};return{numSplats:c,files:{sh0:y(n,"sh0"),means:y(r,"means"),quats:y(o,"quats"),scales:y(i,"scales")},ranges:{sh0:p(n,"sh0"),means:l(r,"means"),scales:l(i,"scales")}}};class dt extends h.Loader{isZipBuffer(e){if(e.byteLength<4)return!1;const t=new Uint8Array(e,0,4);return t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}load(e,t,s,r){const n=new h.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(e,o=>{this.parseAsync(e,o).then(i=>{t&&t(i)}).catch(i=>{this.manager.itemError(e),r&&r(i),console.error("Error loading SOGS meta:",i)})},s,r)}loadAsync(e,t){return new Promise((s,r)=>{const n=new h.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(e,o=>{this.parseAsync(e,o).then(s).catch(i=>{r(i),this.manager.itemError(e)})},t,o=>{r(o),this.manager.itemError(e)})})}async parseAsync(e,t){if(!(t instanceof ArrayBuffer))throw new Error("SOGS loader: expected ArrayBuffer payload");if(this.isZipBuffer(t))return this.parseZipAsync(t);const r=new TextDecoder("utf-8").decode(t),n=JSON.parse(r);return this.parseMetaAsync(e,n)}async parseMetaAsync(e,t){const{numSplats:s,files:r,ranges:n}=Ge(t),o=new h.TextureLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials);const i=(S,k)=>{try{return new URL(k,S).toString()}catch{return S.substring(0,S.lastIndexOf("/")+1)+k}},u=(S,k)=>{const B=i(e,S);return new Promise((H,R)=>{o.load(B,b=>{b.generateMipmaps=!1,b.magFilter=h.NearestFilter,b.minFilter=h.NearestFilter,b.flipY=!1,H(b)},void 0,b=>{const A=b instanceof Error?b.message:String(b);R(new Error(`SOGS loader: failed to load ${k} (${S}): ${A}`))})})};if(!Array.isArray(r.sh0)||r.sh0.length<1)throw new Error("SOGS loader: files.sh0 must have at least 1 entry (sh0)");if(!Array.isArray(r.means)||r.means.length<2)throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");if(!Array.isArray(r.quats)||r.quats.length<1)throw new Error("SOGS loader: files.quats must have at least 1 entry");if(!Array.isArray(r.scales)||r.scales.length<1)throw new Error("SOGS loader: files.scales must have at least 1 entry");const[m,x,c,l,p]=await Promise.all([u(r.means[0],"means_l"),u(r.means[1],"means_u"),u(r.quats[0],"quats"),u(r.scales[0],"scales"),u(r.sh0[0],"sh0")]),y={means_l:m,means_u:x,quats:c,scales:l,sh0:p},M=new qe(s,n,y),v=Se.packSogs(M);return M.dispose(),v}async parseZipAsync(e){const t=mt(new Uint8Array(e)),s=Object.keys(t),r=s.find(C=>C.toLowerCase().endsWith("meta.json"))??null;if(!r)throw new Error("SOGS loader: zip missing meta.json");const n=r.includes("/")?r.slice(0,r.lastIndexOf("/")+1):"",o=new TextDecoder,i=JSON.parse(o.decode(t[r])),{numSplats:u,files:m,ranges:x}=Ge(i),c=C=>C.replace(/\\/g,"/").replace(/^\.?\//,""),l=C=>{const g=c(C),d=[c(n+g),g];for(const T of d){const j=t[T];if(j)return j}const I=g.split("/").pop(),F=s.find(T=>c(T).endsWith("/"+g))??s.find(T=>c(T).endsWith("/"+I))??s.find(T=>c(T)===I)??null;if(F)return t[F];throw new Error(`SOGS loader: zip missing file "${C}"`)},p=C=>{const g=C.toLowerCase();return g.endsWith(".png")?"image/png":g.endsWith(".jpg")||g.endsWith(".jpeg")?"image/jpeg":g.endsWith(".webp")?"image/webp":"application/octet-stream"},y=new h.TextureLoader(this.manager);y.setRequestHeader(this.requestHeader),y.setWithCredentials(this.withCredentials);const M=(C,g)=>{const d=l(C),I=new Blob([d],{type:p(C)}),F=URL.createObjectURL(I);return new Promise((T,j)=>{y.load(F,U=>{URL.revokeObjectURL(F),U.generateMipmaps=!1,U.magFilter=h.NearestFilter,U.minFilter=h.NearestFilter,U.flipY=!1,T(U)},void 0,U=>{URL.revokeObjectURL(F);const q=U instanceof Error?U.message:String(U);j(new Error(`SOGS loader: failed to load ${g} from zip (${C}): ${q}`))})})};if(!Array.isArray(m.sh0)||m.sh0.length<1)throw new Error("SOGS loader: files.sh0 must have at least 1 entry (sh0)");if(!Array.isArray(m.means)||m.means.length<2)throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");if(!Array.isArray(m.quats)||m.quats.length<1)throw new Error("SOGS loader: files.quats must have at least 1 entry");if(!Array.isArray(m.scales)||m.scales.length<1)throw new Error("SOGS loader: files.scales must have at least 1 entry");const[v,S,k,B,H]=await Promise.all([M(m.means[0],"means_l"),M(m.means[1],"means_u"),M(m.quats[0],"quats"),M(m.scales[0],"scales"),M(m.sh0[0],"sh0")]),R={means_l:v,means_u:S,quats:k,scales:B,sh0:H},b=new qe(u,x,R),A=Se.packSogs(b);return b.dispose(),A}}const ft="0.3.0";G.BoundingBox=ge,G.PlyLoader=Ye,G.SogsLoader=dt,G.SplatData=Me,G.SplatMaterial=Re,G.SplatMesh=be,G.SplatSorter=Fe,G.TextureManager=Pe,G.VERSION=ft,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});
|
|
259
|
+
`),l=[];let p=null;for(let z=1;z<c.length;z++){const f=c[z].trim();if(f===""||f==="end_header")continue;const E=f.split(" ");switch(E[0]){case"format":p=E[1];break;case"element":l.push({name:E[1],count:parseInt(E[2],10),properties:[]});break;case"property":if(l.length===0)throw new Error("Invalid PLY file: Property without element");l[l.length-1].properties.push({type:E[1],name:E[2]});break}}if(p!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${p}`);const y=l.find(z=>z.name==="vertex");if(!y)throw new Error("Invalid PLY file: No vertex element found");const M=y.count,v=new Float32Array(M*3),S=new Float32Array(M*4),k=new Float32Array(M*3),B=new Float32Array(M*3),H=new Float32Array(M),R=new DataView(r);let b=m;const A=z=>y.properties.findIndex(f=>f.name===z),C=A("x"),g=A("y"),d=A("z"),I=[A("rot_0"),A("rot_1"),A("rot_2"),A("rot_3")],F=[A("scale_0"),A("scale_1"),A("scale_2")],T=[A("f_dc_0"),A("f_dc_1"),A("f_dc_2")],j=A("opacity");if([C,g,d,...I,...F,...T,j].some(z=>z===-1))throw new Error("Invalid PLY file: Missing required properties");const q=.28209479177387814,P=z=>{if(z>0)return 1/(1+Math.exp(-z));const f=Math.exp(z);return f/(1+f)};let K=1/0,W=1/0,L=1/0,Q=-1/0,Z=-1/0,Y=-1/0;for(let z=0;z<M;z++){const f=[];for(let Ee=0;Ee<y.properties.length;Ee++){const We=y.properties[Ee].type;let he;switch(We){case"char":he=R.getInt8(b),b+=1;break;case"uchar":he=R.getUint8(b),b+=1;break;case"short":he=R.getInt16(b,!0),b+=2;break;case"ushort":he=R.getUint16(b,!0),b+=2;break;case"int":he=R.getInt32(b,!0),b+=4;break;case"uint":he=R.getUint32(b,!0),b+=4;break;case"float":he=R.getFloat32(b,!0),b+=4;break;case"double":he=R.getFloat64(b,!0),b+=8;break;default:throw new Error(`Unsupported property type: ${We}`)}f.push(he)}const E=f[C],V=f[g],D=f[d],O=z*3;v[O]=E,v[O+1]=V,v[O+2]=D,K=Math.min(K,E),W=Math.min(W,V),L=Math.min(L,D),Q=Math.max(Q,E),Z=Math.max(Z,V),Y=Math.max(Y,D);let $=f[I[1]],X=f[I[2]],J=f[I[3]],N=f[I[0]];const ee=Math.sqrt($*$+X*X+J*J+N*N);ee>0&&($/=ee,X/=ee,J/=ee,N/=ee),N<0&&($=-$,X=-X,J=-J,N=-N);const oe=z*4;S[oe]=$,S[oe+1]=X,S[oe+2]=J,S[oe+3]=N;const ie=z*3;k[ie]=f[F[0]],k[ie+1]=f[F[1]],k[ie+2]=f[F[2]];let me=.5+f[T[0]]*q,de=.5+f[T[1]]*q,le=.5+f[T[2]]*q;me=Math.max(0,Math.min(1,me)),de=Math.max(0,Math.min(1,de)),le=Math.max(0,Math.min(1,le));const De=z*3;B[De]=me,B[De+1]=de,B[De+2]=le,H[z]=P(f[j])}return{numSplats:M,positions:v.buffer,rotations:S.buffer,scales:k.buffer,colors:B.buffer,opacities:H.buffer,boundingBox:{minX:K,minY:W,minZ:L,maxX:Q,maxY:Z,maxZ:Y}}}}).toString()})();`}}var se=Uint8Array,xe=Uint16Array,$e=Int32Array,Te=new se([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Ue=new se([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ze=new se([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),_e=function(a,e){for(var t=new xe(31),s=0;s<31;++s)t[s]=e+=1<<a[s-1];for(var r=new $e(t[30]),s=1;s<30;++s)for(var n=t[s];n<t[s+1];++n)r[n]=n-t[s]<<5|s;return{b:t,r}},Ve=_e(Te,2),Oe=Ve.b,Xe=Ve.r;Oe[28]=258,Xe[258]=28;for(var Qe=_e(Ue,0),Je=Qe.b,Ae=new xe(32768),_=0;_<32768;++_){var ue=(_&43690)>>1|(_&21845)<<1;ue=(ue&52428)>>2|(ue&13107)<<2,ue=(ue&61680)>>4|(ue&3855)<<4,Ae[_]=((ue&65280)>>8|(ue&255)<<8)>>1}for(var we=function(a,e,t){for(var s=a.length,r=0,n=new xe(e);r<s;++r)a[r]&&++n[a[r]-1];var o=new xe(e);for(r=1;r<e;++r)o[r]=o[r-1]+n[r-1]<<1;var i;if(t){i=new xe(1<<e);var u=15-e;for(r=0;r<s;++r)if(a[r])for(var m=r<<4|a[r],x=e-a[r],c=o[a[r]-1]++<<x,l=c|(1<<x)-1;c<=l;++c)i[Ae[c]>>u]=m}else for(i=new xe(s),r=0;r<s;++r)a[r]&&(i[r]=Ae[o[a[r]-1]++]>>15-a[r]);return i},ve=new se(288),_=0;_<144;++_)ve[_]=8;for(var _=144;_<256;++_)ve[_]=9;for(var _=256;_<280;++_)ve[_]=7;for(var _=280;_<288;++_)ve[_]=8;for(var Le=new se(32),_=0;_<32;++_)Le[_]=5;var Ke=we(ve,9,1),et=we(Le,5,1),Ie=function(a){for(var e=a[0],t=1;t<a.length;++t)a[t]>e&&(e=a[t]);return e},ne=function(a,e,t){var s=e/8|0;return(a[s]|a[s+1]<<8)>>(e&7)&t},ke=function(a,e){var t=e/8|0;return(a[t]|a[t+1]<<8|a[t+2]<<16)>>(e&7)},tt=function(a){return(a+7)/8|0},Ce=function(a,e,t){return(e==null||e<0)&&(e=0),(t==null||t>a.length)&&(t=a.length),new se(a.subarray(e,t))},st=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],re=function(a,e,t){var s=new Error(e||st[a]);if(s.code=a,Error.captureStackTrace&&Error.captureStackTrace(s,re),!t)throw s;return s},rt=function(a,e,t,s){var r=a.length,n=s?s.length:0;if(!r||e.f&&!e.l)return t||new se(0);var o=!t,i=o||e.i!=2,u=e.i;o&&(t=new se(r*3));var m=function(X){var J=t.length;if(X>J){var N=new se(Math.max(J*2,X));N.set(t),t=N}},x=e.f||0,c=e.p||0,l=e.b||0,p=e.l,y=e.d,M=e.m,v=e.n,S=r*8;do{if(!p){x=ne(a,c,1);var k=ne(a,c+1,3);if(c+=3,k)if(k==1)p=Ke,y=et,M=9,v=5;else if(k==2){var b=ne(a,c,31)+257,A=ne(a,c+10,15)+4,C=b+ne(a,c+5,31)+1;c+=14;for(var g=new se(C),d=new se(19),I=0;I<A;++I)d[Ze[I]]=ne(a,c+I*3,7);c+=A*3;for(var F=Ie(d),T=(1<<F)-1,j=we(d,F,1),I=0;I<C;){var U=j[ne(a,c,T)];c+=U&15;var B=U>>4;if(B<16)g[I++]=B;else{var q=0,P=0;for(B==16?(P=3+ne(a,c,3),c+=2,q=g[I-1]):B==17?(P=3+ne(a,c,7),c+=3):B==18&&(P=11+ne(a,c,127),c+=7);P--;)g[I++]=q}}var K=g.subarray(0,b),W=g.subarray(b);M=Ie(K),v=Ie(W),p=we(K,M,1),y=we(W,v,1)}else re(1);else{var B=tt(c)+4,H=a[B-4]|a[B-3]<<8,R=B+H;if(R>r){u&&re(0);break}i&&m(l+H),t.set(a.subarray(B,R),l),e.b=l+=H,e.p=c=R*8,e.f=x;continue}if(c>S){u&&re(0);break}}i&&m(l+131072);for(var L=(1<<M)-1,Q=(1<<v)-1,Z=c;;Z=c){var q=p[ke(a,c)&L],Y=q>>4;if(c+=q&15,c>S){u&&re(0);break}if(q||re(2),Y<256)t[l++]=Y;else if(Y==256){Z=c,p=null;break}else{var z=Y-254;if(Y>264){var I=Y-257,f=Te[I];z=ne(a,c,(1<<f)-1)+Oe[I],c+=f}var E=y[ke(a,c)&Q],V=E>>4;E||re(3),c+=E&15;var W=Je[V];if(V>3){var f=Ue[V];W+=ke(a,c)&(1<<f)-1,c+=f}if(c>S){u&&re(0);break}i&&m(l+131072);var D=l+z;if(l<W){var O=n-W,$=Math.min(W,D);for(O+l<0&&re(3);l<$;++l)t[l]=s[O+l]}for(;l<D;++l)t[l]=t[l-W]}}e.l=p,e.p=Z,e.b=l,e.f=x,p&&(x=1,e.m=M,e.d=y,e.n=v)}while(!x);return l!=t.length&&o?Ce(t,0,l):t.subarray(0,l)},nt=new se(0),ce=function(a,e){return a[e]|a[e+1]<<8},ae=function(a,e){return(a[e]|a[e+1]<<8|a[e+2]<<16|a[e+3]<<24)>>>0},ze=function(a,e){return ae(a,e)+ae(a,e+4)*4294967296};function at(a,e){return rt(a,{i:2},e&&e.out,e&&e.dictionary)}var Be=typeof TextDecoder<"u"&&new TextDecoder,ot=0;try{Be.decode(nt,{stream:!0}),ot=1}catch{}var it=function(a){for(var e="",t=0;;){var s=a[t++],r=(s>127)+(s>223)+(s>239);if(t+r>a.length)return{s:e,r:Ce(a,t-1)};r?r==3?(s=((s&15)<<18|(a[t++]&63)<<12|(a[t++]&63)<<6|a[t++]&63)-65536,e+=String.fromCharCode(55296|s>>10,56320|s&1023)):r&1?e+=String.fromCharCode((s&31)<<6|a[t++]&63):e+=String.fromCharCode((s&15)<<12|(a[t++]&63)<<6|a[t++]&63):e+=String.fromCharCode(s)}};function ct(a,e){if(e){for(var t="",s=0;s<a.length;s+=16384)t+=String.fromCharCode.apply(null,a.subarray(s,s+16384));return t}else{if(Be)return Be.decode(a);var r=it(a),n=r.s,t=r.r;return t.length&&re(8),n}}var lt=function(a,e){return e+30+ce(a,e+26)+ce(a,e+28)},ht=function(a,e,t){var s=ce(a,e+28),r=ct(a.subarray(e+46,e+46+s),!(ce(a,e+8)&2048)),n=e+46+s,o=ae(a,e+20),i=t&&o==4294967295?ut(a,n):[o,ae(a,e+24),ae(a,e+42)],u=i[0],m=i[1],x=i[2];return[ce(a,e+10),u,m,r,n+ce(a,e+30)+ce(a,e+32),x]},ut=function(a,e){for(;ce(a,e)!=1;e+=4+ce(a,e+2));return[ze(a,e+12),ze(a,e+4),ze(a,e+20)]};function mt(a,e){for(var t={},s=a.length-22;ae(a,s)!=101010256;--s)(!s||a.length-s>65558)&&re(13);var r=ce(a,s+8);if(!r)return{};var n=ae(a,s+16),o=n==4294967295||r==65535;if(o){var i=ae(a,s-12);o=ae(a,i)==101075792,o&&(r=ae(a,i+32),n=ae(a,i+48))}for(var u=0;u<r;++u){var m=ht(a,n,o),x=m[0],c=m[1],l=m[2],p=m[3],y=m[4],M=m[5],v=lt(a,M);n=y,x?x==8?t[p]=at(a.subarray(v,v+c),{out:new se(l)}):re(14,"unknown compression type "+x):t[p]=Ce(a,v,v+c)}return t}const Ge=a=>{if(typeof a!="object"||a===null)throw new Error("Invalid SOGS metadata: not an object");const e=a,t=e.version??1;if(t!==1)throw new Error(`Unsupported SOGS version: ${String(t)}`);const s=M=>{const v=e[M];if(typeof v!="object"||v===null)throw new Error(`Invalid SOGS metadata section: ${M}`);return v},r=s("means"),n=s("sh0"),o=s("quats"),i=s("scales"),u=typeof e.count=="number"&&Number.isFinite(e.count)?e.count:void 0,m=Array.isArray(r.shape)?r.shape:void 0,x=m&&typeof m[0]=="number"?m[0]:void 0;if(u===void 0&&x===void 0)throw new Error("Invalid SOGS metadata: unable to determine splat count");if(u!==void 0&&x!==void 0&&u!==x)throw new Error("Inconsistent SOGS metadata: count does not match means.shape[0]");const c=u??x,l=(M,v)=>{const S=M.mins,k=M.maxs;if(!Array.isArray(S)||S.length!==3)throw new Error(`${v}.mins must be length-3`);if(!Array.isArray(k)||k.length!==3)throw new Error(`${v}.maxs must be length-3`);if(![...S,...k].every(B=>typeof B=="number"&&Number.isFinite(B)))throw new Error(`${v}.mins/maxs must be finite numbers`);return{mins:[S[0],S[1],S[2]],maxs:[k[0],k[1],k[2]]}},p=(M,v)=>{const S=M.mins,k=M.maxs;if(!Array.isArray(S)||S.length!==4)throw new Error(`${v}.mins must be length-4`);if(!Array.isArray(k)||k.length!==4)throw new Error(`${v}.maxs must be length-4`);if(![...S,...k].every(B=>typeof B=="number"&&Number.isFinite(B)))throw new Error(`${v}.mins/maxs must be finite numbers`);return{mins:[S[0],S[1],S[2],S[3]],maxs:[k[0],k[1],k[2],k[3]]}},y=(M,v)=>{const S=M.files;if(!Array.isArray(S))throw new Error(`${v}.files is not an array`);if(!S.every(k=>typeof k=="string"))throw new Error(`${v}.files contains non-strings`);return S};return{numSplats:c,files:{sh0:y(n,"sh0"),means:y(r,"means"),quats:y(o,"quats"),scales:y(i,"scales")},ranges:{sh0:p(n,"sh0"),means:l(r,"means"),scales:l(i,"scales")}}};class dt extends h.Loader{constructor(e){super(e),this.withCredentials=!0}isZipBuffer(e){if(e.byteLength<4)return!1;const t=new Uint8Array(e,0,4);return t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}load(e,t,s,r){const n=new h.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(e,o=>{this.parseAsync(e,o).then(i=>{t&&t(i)}).catch(i=>{this.manager.itemError(e),r&&r(i),console.error("Error loading SOGS meta:",i)})},s,r)}loadAsync(e,t){return new Promise((s,r)=>{const n=new h.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(e,o=>{this.parseAsync(e,o).then(s).catch(i=>{r(i),this.manager.itemError(e)})},t,o=>{r(o),this.manager.itemError(e)})})}async parseAsync(e,t){if(!(t instanceof ArrayBuffer))throw new Error("SOGS loader: expected ArrayBuffer payload");if(this.isZipBuffer(t))return this.parseZipAsync(t);const r=new TextDecoder("utf-8").decode(t),n=JSON.parse(r);return this.parseMetaAsync(e,n)}async parseMetaAsync(e,t){const{numSplats:s,files:r,ranges:n}=Ge(t),o=new h.TextureLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials);const i=(S,k)=>{try{return new URL(k,S).toString()}catch{return S.substring(0,S.lastIndexOf("/")+1)+k}},u=(S,k)=>{const B=i(e,S);return new Promise((H,R)=>{o.load(B,b=>{b.generateMipmaps=!1,b.magFilter=h.NearestFilter,b.minFilter=h.NearestFilter,b.flipY=!1,H(b)},void 0,b=>{const A=b instanceof Error?b.message:String(b);R(new Error(`SOGS loader: failed to load ${k} (${S}): ${A}`))})})};if(!Array.isArray(r.sh0)||r.sh0.length<1)throw new Error("SOGS loader: files.sh0 must have at least 1 entry (sh0)");if(!Array.isArray(r.means)||r.means.length<2)throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");if(!Array.isArray(r.quats)||r.quats.length<1)throw new Error("SOGS loader: files.quats must have at least 1 entry");if(!Array.isArray(r.scales)||r.scales.length<1)throw new Error("SOGS loader: files.scales must have at least 1 entry");const[m,x,c,l,p]=await Promise.all([u(r.means[0],"means_l"),u(r.means[1],"means_u"),u(r.quats[0],"quats"),u(r.scales[0],"scales"),u(r.sh0[0],"sh0")]),y={means_l:m,means_u:x,quats:c,scales:l,sh0:p},M=new qe(s,n,y),v=Se.packSogs(M);return M.dispose(),v}async parseZipAsync(e){const t=mt(new Uint8Array(e)),s=Object.keys(t),r=s.find(C=>C.toLowerCase().endsWith("meta.json"))??null;if(!r)throw new Error("SOGS loader: zip missing meta.json");const n=r.includes("/")?r.slice(0,r.lastIndexOf("/")+1):"",o=new TextDecoder,i=JSON.parse(o.decode(t[r])),{numSplats:u,files:m,ranges:x}=Ge(i),c=C=>C.replace(/\\/g,"/").replace(/^\.?\//,""),l=C=>{const g=c(C),d=[c(n+g),g];for(const T of d){const j=t[T];if(j)return j}const I=g.split("/").pop(),F=s.find(T=>c(T).endsWith("/"+g))??s.find(T=>c(T).endsWith("/"+I))??s.find(T=>c(T)===I)??null;if(F)return t[F];throw new Error(`SOGS loader: zip missing file "${C}"`)},p=C=>{const g=C.toLowerCase();return g.endsWith(".png")?"image/png":g.endsWith(".jpg")||g.endsWith(".jpeg")?"image/jpeg":g.endsWith(".webp")?"image/webp":"application/octet-stream"},y=new h.TextureLoader(this.manager);y.setRequestHeader(this.requestHeader),y.setWithCredentials(this.withCredentials);const M=(C,g)=>{const d=l(C),I=new Blob([d],{type:p(C)}),F=URL.createObjectURL(I);return new Promise((T,j)=>{y.load(F,U=>{URL.revokeObjectURL(F),U.generateMipmaps=!1,U.magFilter=h.NearestFilter,U.minFilter=h.NearestFilter,U.flipY=!1,T(U)},void 0,U=>{URL.revokeObjectURL(F);const q=U instanceof Error?U.message:String(U);j(new Error(`SOGS loader: failed to load ${g} from zip (${C}): ${q}`))})})};if(!Array.isArray(m.sh0)||m.sh0.length<1)throw new Error("SOGS loader: files.sh0 must have at least 1 entry (sh0)");if(!Array.isArray(m.means)||m.means.length<2)throw new Error("SOGS loader: files.means must have at least 2 entries (means_l, means_u)");if(!Array.isArray(m.quats)||m.quats.length<1)throw new Error("SOGS loader: files.quats must have at least 1 entry");if(!Array.isArray(m.scales)||m.scales.length<1)throw new Error("SOGS loader: files.scales must have at least 1 entry");const[v,S,k,B,H]=await Promise.all([M(m.means[0],"means_l"),M(m.means[1],"means_u"),M(m.quats[0],"quats"),M(m.scales[0],"scales"),M(m.sh0[0],"sh0")]),R={means_l:v,means_u:S,quats:k,scales:B,sh0:H},b=new qe(u,x,R),A=Se.packSogs(b);return b.dispose(),A}}const ft="0.3.0";G.BoundingBox=ge,G.PlyLoader=Ye,G.SogsLoader=dt,G.SplatData=Me,G.SplatMaterial=Re,G.SplatMesh=be,G.SplatSorter=Fe,G.TextureManager=Pe,G.VERSION=ft,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});
|
package/dist/react.es.js
CHANGED
|
@@ -1337,6 +1337,9 @@ const Oe = (n) => {
|
|
|
1337
1337
|
};
|
|
1338
1338
|
};
|
|
1339
1339
|
class St extends h.Loader {
|
|
1340
|
+
constructor(e) {
|
|
1341
|
+
super(e), this.withCredentials = !0;
|
|
1342
|
+
}
|
|
1340
1343
|
/**
|
|
1341
1344
|
* Detect if a buffer is a ZIP file by checking magic bytes
|
|
1342
1345
|
* ZIP files start with signature: PK\x03\x04 (0x50 0x4B 0x03 0x04)
|
package/package.json
CHANGED