@speridlabs/visus 2.1.1 → 2.3.0

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/README.md CHANGED
@@ -121,3 +121,4 @@ export default function App() {
121
121
 
122
122
  Apache 2.0 © Sperid Labs
123
123
 
124
+
package/dist/main.es.js CHANGED
@@ -1092,6 +1092,7 @@ class At extends i.Loader {
1092
1092
  h(this, "requestId", 0);
1093
1093
  h(this, "worker");
1094
1094
  h(this, "pendingCallbacks", /* @__PURE__ */ new Map());
1095
+ this.withCredentials = !0;
1095
1096
  const e = this.createWorkerCode(), r = new Blob([e], { type: "application/javascript" });
1096
1097
  this.worker = new Worker(URL.createObjectURL(r)), this.worker.onmessage = this.onWorkerMessage.bind(this);
1097
1098
  }
package/dist/main.umd.js CHANGED
@@ -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 yt extends a.ShaderMaterial{constructor(e={}){const o={transformA:{value:null},transformB:{value:null},splatColor:{value:null},splatOrder:{value:null},viewport:{value:new a.Vector2(1,1)},numSplats:{value:0}};super({vertexShader:St,fragmentShader:Ct,uniforms:o,transparent:!0,blending:a.CustomBlending,blendSrc:a.OneFactor,blendDst:a.OneMinusSrcAlphaFactor,blendSrcAlpha:a.OneFactor,blendDstAlpha:a.OneMinusSrcAlphaFactor,blendEquation:a.AddEquation,blendEquationAlpha:a.AddEquation,depthTest:!0,depthWrite:!1,side:a.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=a.NoBlending)}updateViewport(e,o){this.uniforms.viewport.value.set(e,o)}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 st=class st extends a.Mesh{constructor(o,t={}){const r=new yt(t),s=st.createInstancedGeometry(o.numSplats,st.INSTANCE_SIZE);super(s,r);u(this,"sorter");u(this,"splatData");u(this,"options");u(this,"textureManager");u(this,"material");u(this,"geometry");u(this,"lastCameraPositionLocal",new a.Vector3);u(this,"lastCameraDirectionLocal",new a.Vector3);u(this,"invModelMatrix",new a.Matrix4);u(this,"_vpW",-1);u(this,"_vpH",-1);u(this,"_size",new a.Vector2);u(this,"_camPosW",new a.Vector3);u(this,"_camDirW",new a.Vector3);u(this,"_camPosL",new a.Vector3);u(this,"_camDirL",new a.Vector3);u(this,"onSorterUpdated",o=>{const t=o.count;this.geometry.instanceCount=Math.ceil(t/st.INSTANCE_SIZE),this.material.setNumSplats(t)});this.geometry=s,this.material=r,this.splatData=o,this.frustumCulled=!1,this.options={autoSort:!0,...t},this.textureManager=new gt(o),this.sorter=new pt;let n=this.createChunks()||void 0;n===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),n=void 0,this.sorter.addEventListener("updated",this.onSorterUpdated),this.sorter.init(this.textureManager.orderTexture,this.splatData.positions,n??void 0,!this.options.keepSplatData),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=o.boundingBox.toBox3(),this.geometry.boundingSphere=new a.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere),this.options.keepSplatData||(this.splatData=null)}static createInstancedGeometry(o,t){const r=Math.ceil(o/t),s=new a.BufferGeometry,n=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),i=new Uint16Array([0,1,2,0,2,3]),l=new Float32Array(4*3*t);for(let h=0;h<t;h++){const y=h*4*3;for(let v=0;v<4;v++)l[y+v*3+0]=n[v*3+0],l[y+v*3+1]=n[v*3+1],l[y+v*3+2]=h}const x=new Uint32Array(6*t);for(let h=0;h<t;h++){const y=h*6,v=h*4;x[y+0]=i[0]+v,x[y+1]=i[1]+v,x[y+2]=i[2]+v,x[y+3]=i[3]+v,x[y+4]=i[4]+v,x[y+5]=i[5]+v}s.setAttribute("position",new a.BufferAttribute(l,3)),s.setIndex(new a.BufferAttribute(x,1));const b=new a.InstancedBufferGeometry;b.index=s.index,b.setAttribute("position",s.getAttribute("position"));const S=new Uint32Array(r);for(let h=0;h<r;h++)S[h]=h*t;return b.setAttribute("splatInstanceIndex",new a.InstancedBufferAttribute(S,1,!1)),b.instanceCount=0,b}createChunks(){if(!this.splatData)return null;const o=this.splatData.boundingBox;return o.min.x===1/0||o.max.x===-1/0?null:new Float32Array([o.min.x,o.min.y,o.min.z,o.max.x,o.max.y,o.max.z])}updateViewport(o,t){o===this._vpW&&t===this._vpH||(this._vpW=o,this._vpH=t,this.material.updateViewport(o,t))}sort(o){o.getWorldPosition(this._camPosW),o.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 t=this.lastCameraPositionLocal.distanceToSquared(this._camPosL)>1e-6,r=this.lastCameraDirectionLocal.dot(this._camDirL)<.999;this.options.autoSort&&(t||r)&&(this.lastCameraPositionLocal.copy(this._camPosL),this.lastCameraDirectionLocal.copy(this._camDirL),this.sorter.setCamera(this._camPosL,this._camDirL))}onBeforeRender(o,t,r){this.sort(r),o.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()}};u(st,"INSTANCE_SIZE",128);let ut=st;class It extends a.Loader{constructor(o){super(o);u(this,"requestId",0);u(this,"worker");u(this,"pendingCallbacks",new Map);const t=this.createWorkerCode(),r=new Blob([t],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(r)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(o){const{requestId:t,error:r,result:s}=o.data,n=this.pendingCallbacks.get(t);if(!n)return console.warn(`PlyLoader: Received response for unknown request ${t}`);if(this.pendingCallbacks.delete(t),r)return n.reject(new Error(r));if(!s)return n.reject(new Error("Worker returned no result"));try{const i=new ft(0);i.numSplats=s.numSplats,i.positions=new Float32Array(s.positions),i.rotations=new Float32Array(s.rotations),i.scales=new Float32Array(s.scales),i.colors=new Float32Array(s.colors),i.opacities=new Float32Array(s.opacities),i.boundingBox.min.set(s.boundingBox.minX,s.boundingBox.minY,s.boundingBox.minZ),i.boundingBox.max.set(s.boundingBox.maxX,s.boundingBox.maxY,s.boundingBox.maxZ),this.worker.terminate(),n.resolve(i)}catch(i){n.reject(i)}}load(o,t,r,s){const n=new a.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(o,i=>{this.parseAsync(i).then(l=>{t&&t(l)}).catch(l=>{s?s(l):console.error(l),this.manager.itemError(o)})},r,s)}loadAsync(o,t){return new Promise((r,s)=>{const n=new a.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(o,i=>{this.parseAsync(i).then(r).catch(l=>{s(l),this.manager.itemError(o)})},t,i=>{s(i),this.manager.itemError(o)})})}parseAsync(o){return new Promise((t,r)=>{const s=this.requestId++;this.pendingCallbacks.set(s,{resolve:t,reject:r});const n={requestId:s,buffer:o};this.worker.postMessage(n,[o])})}dispose(){this.worker&&this.worker.terminate(),this.pendingCallbacks.clear()}createWorkerCode(){return`(${(function(){self.onmessage=r=>{const{requestId:s,buffer:n}=r.data;try{const i=t(n),l={requestId:s,result:i};self.postMessage(l,[i.positions,i.rotations,i.scales,i.colors,i.opacities])}catch(i){const l={requestId:s,error:i instanceof Error?i.message:String(i)};self.postMessage(l)}};function t(r){const s=new TextDecoder,n=new Uint8Array(r),i=[112,108,121,10],l=`
287
+ `;class yt extends a.ShaderMaterial{constructor(e={}){const o={transformA:{value:null},transformB:{value:null},splatColor:{value:null},splatOrder:{value:null},viewport:{value:new a.Vector2(1,1)},numSplats:{value:0}};super({vertexShader:St,fragmentShader:Ct,uniforms:o,transparent:!0,blending:a.CustomBlending,blendSrc:a.OneFactor,blendDst:a.OneMinusSrcAlphaFactor,blendSrcAlpha:a.OneFactor,blendDstAlpha:a.OneMinusSrcAlphaFactor,blendEquation:a.AddEquation,blendEquationAlpha:a.AddEquation,depthTest:!0,depthWrite:!1,side:a.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=a.NoBlending)}updateViewport(e,o){this.uniforms.viewport.value.set(e,o)}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 st=class st extends a.Mesh{constructor(o,t={}){const r=new yt(t),s=st.createInstancedGeometry(o.numSplats,st.INSTANCE_SIZE);super(s,r);u(this,"sorter");u(this,"splatData");u(this,"options");u(this,"textureManager");u(this,"material");u(this,"geometry");u(this,"lastCameraPositionLocal",new a.Vector3);u(this,"lastCameraDirectionLocal",new a.Vector3);u(this,"invModelMatrix",new a.Matrix4);u(this,"_vpW",-1);u(this,"_vpH",-1);u(this,"_size",new a.Vector2);u(this,"_camPosW",new a.Vector3);u(this,"_camDirW",new a.Vector3);u(this,"_camPosL",new a.Vector3);u(this,"_camDirL",new a.Vector3);u(this,"onSorterUpdated",o=>{const t=o.count;this.geometry.instanceCount=Math.ceil(t/st.INSTANCE_SIZE),this.material.setNumSplats(t)});this.geometry=s,this.material=r,this.splatData=o,this.frustumCulled=!1,this.options={autoSort:!0,...t},this.textureManager=new gt(o),this.sorter=new pt;let n=this.createChunks()||void 0;n===null&&console.warn("Visus: Could not create sorter chunks, bounding box might be invalid."),n=void 0,this.sorter.addEventListener("updated",this.onSorterUpdated),this.sorter.init(this.textureManager.orderTexture,this.splatData.positions,n??void 0,!this.options.keepSplatData),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=o.boundingBox.toBox3(),this.geometry.boundingSphere=new a.Sphere,this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere),this.options.keepSplatData||(this.splatData=null)}static createInstancedGeometry(o,t){const r=Math.ceil(o/t),s=new a.BufferGeometry,n=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),i=new Uint16Array([0,1,2,0,2,3]),l=new Float32Array(4*3*t);for(let h=0;h<t;h++){const y=h*4*3;for(let v=0;v<4;v++)l[y+v*3+0]=n[v*3+0],l[y+v*3+1]=n[v*3+1],l[y+v*3+2]=h}const x=new Uint32Array(6*t);for(let h=0;h<t;h++){const y=h*6,v=h*4;x[y+0]=i[0]+v,x[y+1]=i[1]+v,x[y+2]=i[2]+v,x[y+3]=i[3]+v,x[y+4]=i[4]+v,x[y+5]=i[5]+v}s.setAttribute("position",new a.BufferAttribute(l,3)),s.setIndex(new a.BufferAttribute(x,1));const b=new a.InstancedBufferGeometry;b.index=s.index,b.setAttribute("position",s.getAttribute("position"));const S=new Uint32Array(r);for(let h=0;h<r;h++)S[h]=h*t;return b.setAttribute("splatInstanceIndex",new a.InstancedBufferAttribute(S,1,!1)),b.instanceCount=0,b}createChunks(){if(!this.splatData)return null;const o=this.splatData.boundingBox;return o.min.x===1/0||o.max.x===-1/0?null:new Float32Array([o.min.x,o.min.y,o.min.z,o.max.x,o.max.y,o.max.z])}updateViewport(o,t){o===this._vpW&&t===this._vpH||(this._vpW=o,this._vpH=t,this.material.updateViewport(o,t))}sort(o){o.getWorldPosition(this._camPosW),o.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 t=this.lastCameraPositionLocal.distanceToSquared(this._camPosL)>1e-6,r=this.lastCameraDirectionLocal.dot(this._camDirL)<.999;this.options.autoSort&&(t||r)&&(this.lastCameraPositionLocal.copy(this._camPosL),this.lastCameraDirectionLocal.copy(this._camDirL),this.sorter.setCamera(this._camPosL,this._camDirL))}onBeforeRender(o,t,r){this.sort(r),o.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()}};u(st,"INSTANCE_SIZE",128);let ut=st;class It extends a.Loader{constructor(o){super(o);u(this,"requestId",0);u(this,"worker");u(this,"pendingCallbacks",new Map);this.withCredentials=!0;const t=this.createWorkerCode(),r=new Blob([t],{type:"application/javascript"});this.worker=new Worker(URL.createObjectURL(r)),this.worker.onmessage=this.onWorkerMessage.bind(this)}onWorkerMessage(o){const{requestId:t,error:r,result:s}=o.data,n=this.pendingCallbacks.get(t);if(!n)return console.warn(`PlyLoader: Received response for unknown request ${t}`);if(this.pendingCallbacks.delete(t),r)return n.reject(new Error(r));if(!s)return n.reject(new Error("Worker returned no result"));try{const i=new ft(0);i.numSplats=s.numSplats,i.positions=new Float32Array(s.positions),i.rotations=new Float32Array(s.rotations),i.scales=new Float32Array(s.scales),i.colors=new Float32Array(s.colors),i.opacities=new Float32Array(s.opacities),i.boundingBox.min.set(s.boundingBox.minX,s.boundingBox.minY,s.boundingBox.minZ),i.boundingBox.max.set(s.boundingBox.maxX,s.boundingBox.maxY,s.boundingBox.maxZ),this.worker.terminate(),n.resolve(i)}catch(i){n.reject(i)}}load(o,t,r,s){const n=new a.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(o,i=>{this.parseAsync(i).then(l=>{t&&t(l)}).catch(l=>{s?s(l):console.error(l),this.manager.itemError(o)})},r,s)}loadAsync(o,t){return new Promise((r,s)=>{const n=new a.FileLoader(this.manager);n.setResponseType("arraybuffer"),n.setRequestHeader(this.requestHeader),n.setPath(this.path),n.setWithCredentials(this.withCredentials),n.load(o,i=>{this.parseAsync(i).then(r).catch(l=>{s(l),this.manager.itemError(o)})},t,i=>{s(i),this.manager.itemError(o)})})}parseAsync(o){return new Promise((t,r)=>{const s=this.requestId++;this.pendingCallbacks.set(s,{resolve:t,reject:r});const n={requestId:s,buffer:o};this.worker.postMessage(n,[o])})}dispose(){this.worker&&this.worker.terminate(),this.pendingCallbacks.clear()}createWorkerCode(){return`(${(function(){self.onmessage=r=>{const{requestId:s,buffer:n}=r.data;try{const i=t(n),l={requestId:s,result:i};self.postMessage(l,[i.positions,i.rotations,i.scales,i.colors,i.opacities])}catch(i){const l={requestId:s,error:i instanceof Error?i.message:String(i)};self.postMessage(l)}};function t(r){const s=new TextDecoder,n=new Uint8Array(r),i=[112,108,121,10],l=`
288
288
  end_header
289
289
  `;for(let f=0;f<i.length;f++)if(n[f]!==i[f])throw new Error("Invalid PLY file: Missing magic bytes");let x=0;for(let f=0;f<n.length-l.length;f++){let c=!0;for(let g=0;g<l.length;g++)if(n[f+g]!==l.charCodeAt(g)){c=!1;break}if(c){x=f+l.length;break}}if(x===0)throw new Error("Invalid PLY file: Could not find end of header");const S=s.decode(n.subarray(0,x)).split(`
290
290
  `),h=[];let y=null;for(let f=1;f<S.length;f++){const c=S[f].trim();if(c===""||c==="end_header")continue;const g=c.split(" ");switch(g[0]){case"format":y=g[1];break;case"element":h.push({name:g[1],count:parseInt(g[2],10),properties:[]});break;case"property":if(h.length===0)throw new Error("Invalid PLY file: Property without element");h[h.length-1].properties.push({type:g[1],name:g[2]});break}}if(y!=="binary_little_endian")throw new Error(`Unsupported PLY format: ${y}`);const v=h.find(f=>f.name==="vertex");if(!v)throw new Error("Invalid PLY file: No vertex element found");const I=v.count,A=new Float32Array(I*3),W=new Float32Array(I*4),N=new Float32Array(I*3),j=new Float32Array(I*3),ct=new Float32Array(I),H=new DataView(r);let w=x;const d=f=>v.properties.findIndex(c=>c.name===f),E=d("x"),M=d("y"),p=d("z"),z=[d("rot_0"),d("rot_1"),d("rot_2"),d("rot_3")],_=[d("scale_0"),d("scale_1"),d("scale_2")],X=[d("f_dc_0"),d("f_dc_1"),d("f_dc_2")],Q=d("opacity");if([E,M,p,...z,..._,...X,Q].some(f=>f===-1))throw new Error("Invalid PLY file: Missing required properties");const R=.28209479177387814,F=f=>{if(f>0)return 1/(1+Math.exp(-f));const c=Math.exp(f);return c/(1+c)};let Z=1/0,lt=1/0,U=1/0,it=-1/0,ot=-1/0,nt=-1/0;for(let f=0;f<I;f++){const c=[];for(let dt=0;dt<v.properties.length;dt++){const vt=v.properties[dt].type;let J;switch(vt){case"char":J=H.getInt8(w),w+=1;break;case"uchar":J=H.getUint8(w),w+=1;break;case"short":J=H.getInt16(w,!0),w+=2;break;case"ushort":J=H.getUint16(w,!0),w+=2;break;case"int":J=H.getInt32(w,!0),w+=4;break;case"uint":J=H.getUint32(w,!0),w+=4;break;case"float":J=H.getFloat32(w,!0),w+=4;break;case"double":J=H.getFloat64(w,!0),w+=8;break;default:throw new Error(`Unsupported property type: ${vt}`)}c.push(J)}const g=c[E],B=c[M],m=c[p],T=f*3;A[T]=g,A[T+1]=B,A[T+2]=m,Z=Math.min(Z,g),lt=Math.min(lt,B),U=Math.min(U,m),it=Math.max(it,g),ot=Math.max(ot,B),nt=Math.max(nt,m);let V=c[z[1]],q=c[z[2]],L=c[z[3]],P=c[z[0]];const O=Math.sqrt(V*V+q*q+L*L+P*P);O>0&&(V/=O,q/=O,L/=O,P/=O),P<0&&(V=-V,q=-q,L=-L,P=-P);const G=f*4;W[G]=V,W[G+1]=q,W[G+2]=L,W[G+3]=P;const $=f*3;N[$]=c[_[0]],N[$+1]=c[_[1]],N[$+2]=c[_[2]];let tt=.5+c[X[0]]*R,et=.5+c[X[1]]*R,Y=.5+c[X[2]]*R;tt=Math.max(0,Math.min(1,tt)),et=Math.max(0,Math.min(1,et)),Y=Math.max(0,Math.min(1,Y));const ht=f*3;j[ht]=tt,j[ht+1]=et,j[ht+2]=Y,ct[f]=F(c[Q])}return{numSplats:I,positions:A.buffer,rotations:W.buffer,scales:N.buffer,colors:j.buffer,opacities:ct.buffer,boundingBox:{minX:Z,minY:lt,minZ:U,maxX:it,maxY:ot,maxZ:nt}}}}).toString()})();`}}const At="0.3.0";C.BoundingBox=at,C.PlyLoader=It,C.SplatData=ft,C.SplatMaterial=yt,C.SplatMesh=ut,C.SplatSorter=pt,C.TextureManager=gt,C.VERSION=At,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});