@dvt3d/splat-mesh 1.0.0 → 1.1.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/dist/index.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{BufferAttribute as I,BufferGeometry as P,CustomBlending as W,DataTexture as A,DynamicDrawUsage as V,FloatType as U,InstancedBufferAttribute as z,InstancedBufferGeometry as B,Mesh as R,OneFactor as j,RGBAFormat as G,RGBAIntegerFormat as H,ShaderMaterial as E,UnsignedIntType as q,Vector4 as $,Frustum as J,Matrix4 as L}from"three";var g="precision highp sampler2D;precision highp usampler2D;out vec4 vColor;out vec2 vPosition;uniform vec2 viewport;uniform mat4 gsModelViewMatrix;attribute uint splatIndex;uniform sampler2D centerAndScaleTexture;uniform usampler2D covAndColorTexture;vec2 unpackInt16(in uint value){int v=int(value);int v0=v>>16;int v1=(v&0xFFFF);if((v&0x8000)!=0)v1|=0xFFFF0000;return vec2(float(v1),float(v0));}vec4 calcCovVectors(vec3 viewPos,mat3 Vrk){float focal=(viewport.y/2.0)*abs(projectionMatrix[1][1]);mat3 J=mat3(focal/viewPos.z,0.,-(focal*viewPos.x)/(viewPos.z*viewPos.z),0.,focal/viewPos.z,-(focal*viewPos.y)/(viewPos.z*viewPos.z),0.,0.,0.);mat3 W=transpose(mat3(gsModelViewMatrix));mat3 T=W*J;mat3 cov=transpose(T)*Vrk*T;float diagonal1=cov[0][0]+0.3;float offDiagonal=cov[0][1];float diagonal2=cov[1][1]+0.3;float mid=0.5*(diagonal1+diagonal2);float radius=length(vec2((diagonal1-diagonal2)/2.0,offDiagonal));float lambda1=mid+radius;float lambda2=max(mid-radius,0.1);vec2 diagonalVector=normalize(vec2(offDiagonal,lambda1-diagonal1));vec2 v1=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 v2=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);return vec4(v1,v2);}void main(){ivec2 texSize=textureSize(centerAndScaleTexture,0);ivec2 texPos=ivec2(splatIndex % uint(texSize.x),splatIndex/uint(texSize.x));vec4 centerAndScaleData=texelFetch(centerAndScaleTexture,texPos,0);vec4 viewPos=gsModelViewMatrix*vec4(centerAndScaleData.xyz,1);vec4 pos2d=projectionMatrix*viewPos;float clip=1.2*pos2d.w;if(pos2d.z<-pos2d.w||pos2d.x<-clip||pos2d.x>clip||pos2d.y<-clip||pos2d.y>clip){gl_Position=vec4(0.0,0.0,2.0,1.0);return;}uvec4 covAndColorData=texelFetch(covAndColorTexture,texPos,0);vec2 cov3D_M11_M12=unpackInt16(covAndColorData.x)*centerAndScaleData.w;vec2 cov3D_M13_M22=unpackInt16(covAndColorData.y)*centerAndScaleData.w;vec2 cov3D_M23_M33=unpackInt16(covAndColorData.z)*centerAndScaleData.w;mat3 Vrk=mat3(cov3D_M11_M12.x,cov3D_M11_M12.y,cov3D_M13_M22.x,cov3D_M11_M12.y,cov3D_M13_M22.y,cov3D_M23_M33.x,cov3D_M13_M22.x,cov3D_M23_M33.x,cov3D_M23_M33.y);vec4 covVectors=calcCovVectors(viewPos.xyz,Vrk);vPosition=position.xy;uint colorUint=covAndColorData.w;vColor=vec4(float(colorUint&uint(0xFF))/255.0,float((colorUint>>uint(8))&uint(0xFF))/255.0,float((colorUint>>uint(16))&uint(0xFF))/255.0,float(colorUint>>uint(24))/255.0);vec2 vCenter=vec2(pos2d)/pos2d.w;gl_Position=vec4(vCenter+(position.x*covVectors.zw+position.y*covVectors.xy)/viewport*2.0,pos2d.z/pos2d.w,1.0);}";var S="in vec4 vColor;in vec2 vPosition;void main(){float A=-dot(vPosition,vPosition);if(A<-4.0)discard;float B=exp(A)*vColor.a;gl_FragColor=vec4(vColor.rgb,B);}";var x=class{constructor(){this._intervalTime=200,this._stableStopTime=3e3,this._isSorting=!1,this._dirty=!0,this._lastMvMatrix=null,this._lastSortTime=0,this._stableSince=0}set isSorting(t){this._isSorting=t}get isSorting(){return this._isSorting}set dirty(t){this._dirty=t}get dirty(){return this._dirty}set intervalTime(t){this._intervalTime=t}get intervalTime(){return this._intervalTime}set stableStopTime(t){this._stableStopTime=t}get stableStopTime(){return this._stableStopTime}_isMatrixChanged(t,e){return t?!t.equals(e):!0}tick(t,e){let r=performance.now(),i=this._isMatrixChanged(this._lastMvMatrix,t);i?this._stableSince=r:this._stableSince===0&&(this._stableSince=r);let s=r-this._lastSortTime>=this._intervalTime,h=r-this._stableSince<this._stableStopTime;return!this._isSorting&&s&&(this._dirty||i||h)&&(this._isSorting=!0,this._dirty=!1,this._lastSortTime=r,e()),this._lastMvMatrix=t,this}},M=x;var F="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");function y(o="D"){let t=[];t[8]=t[13]=t[18]=t[23]="-",t[14]="4";let e;for(let r=0;r<36;r++)t[r]||(e=0|Math.random()*16,t[r]=F[r===19?e&3|8:e]);return o+"-"+t.join("")}function k(){let o=document.createElement("canvas"),t=o.getContext("webgl2")||o.getContext("webgl");return t.getParameter(t.MAX_TEXTURE_SIZE)}var f=k(),O=f*f,C=new P;C.setAttribute("position",new I(new Float32Array([-2,-2,0,2,2,0,-2,2,0,2,-2,0,2,2,0,-2,-2,0]),3));var v=class extends R{constructor(){super(),this._meshId=y(),this._vertexCount=0,this._textureWidth=f,this._textureHeight=1,this._threshold=-1e-5,this._centerAndScaleData=null,this._centerAndScaleTexture=null,this._rotationAndColorData=null,this._rotationAndColorTexture=null,this.geometry=new B().copy(C),this.geometry.instanceCount=1,this.material=new E({uniforms:{viewport:{value:new Float32Array([1980,1080])},centerAndScaleTexture:{value:null},covAndColorTexture:{value:null},gsModelViewMatrix:{value:null}},vertexShader:g,fragmentShader:S,blending:W,blendSrcAlpha:j,depthTest:!0,depthWrite:!1,transparent:!0}),this.material.onBeforeRender=this._onMaterialBeforeRender.bind(this),this.frustumCulled=!1,this._bounds=null,this._sortScheduler=new M,this._worker=null,this._useFrustumCulled=!1}get isSplatMesh(){return!0}set threshold(t){this._threshold=t}get threshold(){return this._threshold}set worker(t){this._worker=t}get worker(){return this._worker}get bounds(){return this._bounds}set vertexCount(t){this.setVertexCount(t)}get vertexCount(){return this._vertexCount}set useFrustumCulled(t){this._useFrustumCulled=t}get useFrustumCulled(){return this._useFrustumCulled}get sortScheduler(){return this._sortScheduler}_getModelViewMatrix(t){return t.matrixWorld.clone().invert().multiply(this.matrixWorld)}_updateTexture(t,e){t&&this._meshId===t.meshId&&(this._centerAndScaleData.set(t.out_cs),this._rotationAndColorData.set(t.out_rc),this._centerAndScaleTexture.image.data.set(this._centerAndScaleData.subarray(0,e*4),0),this._rotationAndColorTexture.image.data.set(this._rotationAndColorData.subarray(0,e*4),0),this._centerAndScaleTexture.needsUpdate=!0,this._rotationAndColorTexture.needsUpdate=!0,this._sortScheduler.dirty=!0)}_onMaterialBeforeRender(t,e,r,i,s,h){let u=this._getModelViewMatrix(r),p=s.material;p.uniforms.gsModelViewMatrix.value=u;let m=new $;t.getCurrentViewport(m),p.uniforms.viewport.value[0]=m.z,p.uniforms.viewport.value[1]=m.w,this._sortScheduler&&this._sortScheduler.tick(u,()=>{let c=u.elements,D=new Float32Array([c[2],c[6],c[10],c[14]]),a=new Float32Array(0);if(this._useFrustumCulled){a=new Float32Array(24);let n=new L;n.multiplyMatrices(r.projectionMatrix,r.matrixWorldInverse);let l=new J;l.setFromProjectionMatrix(n),l.planes.forEach((d,_)=>{a[_*4+0]=d.normal.x,a[_*4+1]=d.normal.y,a[_*4+2]=d.normal.z,a[_*4+3]=d.constant})}this._worker&&this._worker.call("sort_splats",this._meshId,D,a,this._threshold).then(n=>{if(n||(this._sortScheduler.isSorting=!1),n&&this._meshId===n.meshId){let l=new Uint32Array(n.data);this.geometry.attributes.splatIndex.set(l),this.geometry.attributes.splatIndex.needsUpdate=!0,this.geometry.instanceCount=l.length,this._sortScheduler.isSorting=!1}})})}setVertexCount(t){if(t===this._vertexCount)return;this._vertexCount=Math.min(t,O),this._textureHeight=Math.floor((this._vertexCount-1)/this._textureWidth)+1,this._centerAndScaleData=new Float32Array(this._textureWidth*this._textureHeight*4),this._centerAndScaleTexture&&this._centerAndScaleTexture.dispose(),this._centerAndScaleTexture=new A(this._centerAndScaleData,this._textureWidth,this._textureHeight,G,U),this._rotationAndColorData=new Uint32Array(this._textureWidth*this._textureHeight*4),this._rotationAndColorTexture&&this._rotationAndColorTexture.dispose(),this._rotationAndColorTexture=new A(this._rotationAndColorData,this._textureWidth,this._textureHeight,H,q),this._rotationAndColorTexture.internalFormat="RGBA32UI";let e=new Uint32Array(this._textureWidth*this._textureHeight),r=new z(e,1,!1);return r.setUsage(V),this.geometry.setAttribute("splatIndex",r),this.material.uniforms.centerAndScaleTexture.value=this._centerAndScaleTexture,this.material.uniforms.covAndColorTexture.value=this._rotationAndColorTexture,this}attachWorker(t){return this._worker=t,this}detachWorker(){return this._worker&&this._worker.call("unregister_positions",this._bufferId),this._worker=null,this}async setDataFromBuffer(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromBuffer skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromBuffer skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_buffer",this._meshId,t,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromGeometry(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromGeometry skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromGeometry skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_geometry",this._meshId,t.attributes.position.array,t.attributes._scale.array,t.attributes._rotation.array,t.attributes.color.array,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromSpz(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromSpz skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromSpz skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_spz",this._meshId,t.positions,t.scales,t.rotations,t.colors,t.alphas,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async computeBounds(){if(!this._worker)return console.warn("[SplatMesh] computeBounds skipped: worker not ready"),this;if(!this._bounds){let t=await this._worker.call("compute_bounds",this._meshId);this._meshId===t.meshId&&(this._bounds=t.data)}return this}dispose(){this._bounds=null,this._centerAndScaleTexture&&(this._centerAndScaleTexture.dispose(),this._centerAndScaleData=null),this._rotationAndColorTexture&&(this._rotationAndColorTexture.dispose(),this._rotationAndColorData=null),this._worker&&this._worker.call("unregister_positions",this._bufferId),this._bufferId=null,this._sortScheduler=null,this.geometry.dispose(),this.material.dispose(),this.parent=null}},b=v;var w=class{constructor(t,{timeout:e=0}={}){this._workerUrl=t,this._worker=null,this._seq=0,this._pending=new Map,this._timeout=e,this._initPromise=null,this._ready=!1,this._createWorker()}_createWorker(){let t=e=>{e.onmessage=r=>this._handleMessage(r),e.onerror=r=>this._handleError(r),e.onmessageerror=r=>console.error("[SplatWorker] Worker message error:",r)};try{this._worker=new Worker(this._workerUrl,{type:"module"}),t(this._worker);return}catch(e){console.error("Worker error:",e)}fetch(this._workerUrl).then(e=>{if(!e.ok)throw new Error(`[SplatWorker] Failed to fetch worker: ${this._workerUrl}`);return e.text()}).then(e=>{let r=new Blob([e],{type:"application/javascript"}),i=URL.createObjectURL(r);this._worker=new Worker(i),t(this._worker)})}_handleMessage(t){let{id:e,result:r,error:i}=t.data,s=this._pending.get(e);s&&(this._pending.delete(e),i?s.reject(i):s.resolve(r))}_handleError(t){console.error("[SplatWorker] Worker error:",t);for(let[e,r]of this._pending)r.reject("[SplatWorker] Worker crashed");this._pending.clear()}_collectTransferables(t){let e=[];for(let r of t)r&&(ArrayBuffer.isView(r)?e.push(r.buffer):r instanceof ArrayBuffer&&e.push(r));return e}async init(){if(this._ready)return!0;if(this._initPromise)return this._initPromise;this._initPromise=new Promise((e,r)=>{let i=++this._seq;this._pending.set(i,{resolve:e,reject:r}),this._worker.postMessage({id:i,fn:"__init_wasm__",args:[]})});let t=await this._initPromise;return this._ready=!0,t}call(t,...e){return new Promise((r,i)=>{this._worker||i(`the worker ${this._workerUrl} does not exist`);let s=++this._seq;this._pending.set(s,{resolve:r,reject:i});let h=this._collectTransferables(e);this._worker.postMessage({id:s,fn:t,args:e},h),this._timeout>0&&setTimeout(()=>{this._pending.has(s)&&(this._pending.delete(s),i(`[SplatWorker] Task "${t}" timeout after ${this._timeout}ms`))},this._timeout)})}cancel(t,e="canceled"){let r=this._pending.get(t);return r&&(r.reject(e),this._pending.delete(t)),this}dispose(){return this._worker.terminate(),this._pending.clear(),this}},T=w;typeof window!="undefined"&&(window.SplatMesh=b,window.SplatWorker=T);export{b as SplatMesh,T as SplatWorker};
|
|
1
|
+
import{BufferAttribute as P,BufferGeometry as V,CustomBlending as W,DataTexture as b,DynamicDrawUsage as z,FloatType as B,InstancedBufferAttribute as R,InstancedBufferGeometry as j,Mesh as G,OneFactor as H,RGBAFormat as E,RGBAIntegerFormat as L,ShaderMaterial as q,UnsignedIntType as J,Vector4 as O,Frustum as $,Matrix4 as X}from"three";var S="precision highp sampler2D;precision highp usampler2D;out vec4 vColor;out vec2 vPosition;uniform vec2 viewport;uniform mat4 gsModelViewMatrix;attribute uint splatIndex;uniform sampler2D centerAndScaleTexture;uniform usampler2D covAndColorTexture;vec2 unpackInt16(in uint value){int v=int(value);int v0=v>>16;int v1=(v&0xFFFF);if((v&0x8000)!=0)v1|=0xFFFF0000;return vec2(float(v1),float(v0));}vec4 calcCovVectors(vec3 viewPos,mat3 Vrk){float focal=(viewport.y/2.0)*abs(projectionMatrix[1][1]);mat3 J=mat3(focal/viewPos.z,0.,-(focal*viewPos.x)/(viewPos.z*viewPos.z),0.,focal/viewPos.z,-(focal*viewPos.y)/(viewPos.z*viewPos.z),0.,0.,0.);mat3 W=transpose(mat3(gsModelViewMatrix));mat3 T=W*J;mat3 cov=transpose(T)*Vrk*T;float diagonal1=cov[0][0]+0.3;float offDiagonal=cov[0][1];float diagonal2=cov[1][1]+0.3;float mid=0.5*(diagonal1+diagonal2);float radius=length(vec2((diagonal1-diagonal2)/2.0,offDiagonal));float lambda1=mid+radius;float lambda2=max(mid-radius,0.1);vec2 diagonalVector=normalize(vec2(offDiagonal,lambda1-diagonal1));vec2 v1=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 v2=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);return vec4(v1,v2);}void main(){ivec2 texSize=textureSize(centerAndScaleTexture,0);ivec2 texPos=ivec2(splatIndex % uint(texSize.x),splatIndex/uint(texSize.x));vec4 centerAndScaleData=texelFetch(centerAndScaleTexture,texPos,0);vec4 viewPos=gsModelViewMatrix*vec4(centerAndScaleData.xyz,1);vec4 pos2d=projectionMatrix*viewPos;float clip=1.2*pos2d.w;if(pos2d.z<-pos2d.w||pos2d.x<-clip||pos2d.x>clip||pos2d.y<-clip||pos2d.y>clip){gl_Position=vec4(0.0,0.0,2.0,1.0);return;}uvec4 covAndColorData=texelFetch(covAndColorTexture,texPos,0);vec2 cov3D_M11_M12=unpackInt16(covAndColorData.x)*centerAndScaleData.w;vec2 cov3D_M13_M22=unpackInt16(covAndColorData.y)*centerAndScaleData.w;vec2 cov3D_M23_M33=unpackInt16(covAndColorData.z)*centerAndScaleData.w;mat3 Vrk=mat3(cov3D_M11_M12.x,cov3D_M11_M12.y,cov3D_M13_M22.x,cov3D_M11_M12.y,cov3D_M13_M22.y,cov3D_M23_M33.x,cov3D_M13_M22.x,cov3D_M23_M33.x,cov3D_M23_M33.y);vec4 covVectors=calcCovVectors(viewPos.xyz,Vrk);vPosition=position.xy;uint colorUint=covAndColorData.w;vColor=vec4(float(colorUint&uint(0xFF))/255.0,float((colorUint>>uint(8))&uint(0xFF))/255.0,float((colorUint>>uint(16))&uint(0xFF))/255.0,float(colorUint>>uint(24))/255.0);vec2 vCenter=vec2(pos2d)/pos2d.w;gl_Position=vec4(vCenter+(position.x*covVectors.zw+position.y*covVectors.xy)/viewport*2.0,pos2d.z/pos2d.w,1.0);}";var y="in vec4 vColor;in vec2 vPosition;void main(){float A=-dot(vPosition,vPosition);if(A<-4.0)discard;float B=exp(A)*vColor.a;gl_FragColor=vec4(vColor.rgb,B);}";var f=class{constructor(){this._intervalTime=200,this._stableStopTime=3e3,this._isSorting=!1,this._dirty=!0,this._lastMvMatrix=null,this._lastSortTime=0,this._stableSince=0}set isSorting(t){this._isSorting=t}get isSorting(){return this._isSorting}set dirty(t){this._dirty=t}get dirty(){return this._dirty}set intervalTime(t){this._intervalTime=t}get intervalTime(){return this._intervalTime}set stableStopTime(t){this._stableStopTime=t}get stableStopTime(){return this._stableStopTime}_isMatrixChanged(t,e){return t?!t.equals(e):!0}tick(t,e){let r=performance.now(),i=this._isMatrixChanged(this._lastMvMatrix,t);i?this._stableSince=r:this._stableSince===0&&(this._stableSince=r);let s=r-this._lastSortTime>=this._intervalTime,u=r-this._stableSince<this._stableStopTime;return!this._isSorting&&s&&(this._dirty||i||u)&&(this._isSorting=!0,this._dirty=!1,this._lastSortTime=r,e()),this._lastMvMatrix=t,this}},M=f;var x={},I="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");function A(o="D"){let t=[];t[8]=t[13]=t[18]=t[23]="-",t[14]="4";let e;for(let r=0;r<36;r++)t[r]||(e=0|Math.random()*16,t[r]=I[r===19?e&3|8:e]);return o+"-"+t.join("")}function C(){let o=document.createElement("canvas"),t=o.getContext("webgl2")||o.getContext("webgl");return t.getParameter(t.MAX_TEXTURE_SIZE)}function k(o){if(!o||/^[a-zA-Z]+:\/\//.test(o))return o;try{if(typeof x!="undefined"&&x.url)return new URL(o,x.url).href}catch{}if(typeof document!="undefined"&&document.currentScript&&document.currentScript.src)return new URL(o,document.currentScript.src).href;try{return new URL(o,typeof location!="undefined"?location.href:void 0).href}catch{return o}}var v=C(),Z=v*v,T=new V;T.setAttribute("position",new P(new Float32Array([-2,-2,0,2,2,0,-2,2,0,2,-2,0,2,2,0,-2,-2,0]),3));var w=class extends G{constructor(){super(),this._meshId=A(),this._vertexCount=0,this._textureWidth=v,this._textureHeight=1,this._threshold=-1e-5,this._centerAndScaleData=null,this._centerAndScaleTexture=null,this._rotationAndColorData=null,this._rotationAndColorTexture=null,this.geometry=new j().copy(T),this.geometry.instanceCount=1,this.material=new q({uniforms:{viewport:{value:new Float32Array([1980,1080])},centerAndScaleTexture:{value:null},covAndColorTexture:{value:null},gsModelViewMatrix:{value:null}},vertexShader:S,fragmentShader:y,blending:W,blendSrcAlpha:H,depthTest:!0,depthWrite:!1,transparent:!0}),this.material.onBeforeRender=this._onMaterialBeforeRender.bind(this),this.frustumCulled=!1,this._bounds=null,this._sortScheduler=new M,this._worker=null,this._useFrustumCulled=!1}get isSplatMesh(){return!0}set threshold(t){this._threshold=t}get threshold(){return this._threshold}set worker(t){this._worker=t}get worker(){return this._worker}get bounds(){return this._bounds}set vertexCount(t){this.setVertexCount(t)}get vertexCount(){return this._vertexCount}set useFrustumCulled(t){this._useFrustumCulled=t}get useFrustumCulled(){return this._useFrustumCulled}get sortScheduler(){return this._sortScheduler}_getModelViewMatrix(t){return t.matrixWorld.clone().invert().multiply(this.matrixWorld)}_updateTexture(t,e){t&&this._meshId===t.meshId&&(this._centerAndScaleData.set(t.out_cs),this._rotationAndColorData.set(t.out_rc),this._centerAndScaleTexture.image.data.set(this._centerAndScaleData.subarray(0,e*4),0),this._rotationAndColorTexture.image.data.set(this._rotationAndColorData.subarray(0,e*4),0),this._centerAndScaleTexture.needsUpdate=!0,this._rotationAndColorTexture.needsUpdate=!0,this._sortScheduler.dirty=!0)}_onMaterialBeforeRender(t,e,r,i,s,u){let h=this._getModelViewMatrix(r),p=s.material;p.uniforms.gsModelViewMatrix.value=h;let m=new O;t.getCurrentViewport(m),p.uniforms.viewport.value[0]=m.z,p.uniforms.viewport.value[1]=m.w,this._sortScheduler&&this._sortScheduler.tick(h,()=>{let c=h.elements,U=new Float32Array([c[2],c[6],c[10],c[14]]),a=new Float32Array(0);if(this._useFrustumCulled){a=new Float32Array(24);let n=new X;n.multiplyMatrices(r.projectionMatrix,r.matrixWorldInverse);let l=new $;l.setFromProjectionMatrix(n),l.planes.forEach((d,_)=>{a[_*4+0]=d.normal.x,a[_*4+1]=d.normal.y,a[_*4+2]=d.normal.z,a[_*4+3]=d.constant})}this._worker&&this._worker.call("sort_splats",this._meshId,U,a,this._threshold).then(n=>{if(n||(this._sortScheduler.isSorting=!1),n&&this._meshId===n.meshId){let l=new Uint32Array(n.data);this.geometry.attributes.splatIndex.set(l),this.geometry.attributes.splatIndex.needsUpdate=!0,this.geometry.instanceCount=l.length,this._sortScheduler.isSorting=!1}})})}setVertexCount(t){if(t===this._vertexCount)return;this._vertexCount=Math.min(t,Z),this._textureHeight=Math.floor((this._vertexCount-1)/this._textureWidth)+1,this._centerAndScaleData=new Float32Array(this._textureWidth*this._textureHeight*4),this._centerAndScaleTexture&&this._centerAndScaleTexture.dispose(),this._centerAndScaleTexture=new b(this._centerAndScaleData,this._textureWidth,this._textureHeight,E,B),this._rotationAndColorData=new Uint32Array(this._textureWidth*this._textureHeight*4),this._rotationAndColorTexture&&this._rotationAndColorTexture.dispose(),this._rotationAndColorTexture=new b(this._rotationAndColorData,this._textureWidth,this._textureHeight,L,J),this._rotationAndColorTexture.internalFormat="RGBA32UI";let e=new Uint32Array(this._textureWidth*this._textureHeight),r=new R(e,1,!1);return r.setUsage(z),this.geometry.setAttribute("splatIndex",r),this.material.uniforms.centerAndScaleTexture.value=this._centerAndScaleTexture,this.material.uniforms.covAndColorTexture.value=this._rotationAndColorTexture,this}attachWorker(t){return this._worker=t,this}detachWorker(){return this._worker&&this._worker.call("unregister_positions",this._bufferId),this._worker=null,this}async setDataFromBuffer(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromBuffer skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromBuffer skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_buffer",this._meshId,t,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromGeometry(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromGeometry skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromGeometry skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_geometry",this._meshId,t.attributes.position.array,t.attributes._scale.array,t.attributes._rotation.array,t.attributes.color.array,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromSpz(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromSpz skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromSpz skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_spz",this._meshId,t.positions,t.scales,t.rotations,t.colors,t.alphas,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async computeBounds(){if(!this._worker)return console.warn("[SplatMesh] computeBounds skipped: worker not ready"),this;if(!this._bounds){let t=await this._worker.call("compute_bounds",this._meshId);this._meshId===t.meshId&&(this._bounds=t.data)}return this}dispose(){this._bounds=null,this._centerAndScaleTexture&&(this._centerAndScaleTexture.dispose(),this._centerAndScaleData=null),this._rotationAndColorTexture&&(this._rotationAndColorTexture.dispose(),this._rotationAndColorData=null),this._worker&&this._worker.call("unregister_positions",this._bufferId),this._bufferId=null,this._sortScheduler=null,this.geometry.dispose(),this.material.dispose(),this.parent=null}},D=w;var g=class{constructor(t,{timeout:e=0}={}){this._baseUrl=k(t||"./"),this._workerUrl=new URL("wasm_splat.worker.min.js",this._baseUrl).href,this._wasmUrl=new URL("wasm_splat_bg.wasm",this._baseUrl).href,this._seq=0,this._pending=new Map,this._timeout=e,this._initPromise=null,this._ready=!1,this._createWorker()}_createWorker(){let t=i=>{i.onmessage=s=>this._handleMessage(s),i.onerror=s=>this._handleError(s),i.onmessageerror=s=>console.error("[SplatWorker] Worker message error:",s)};try{this._worker=new Worker(this._workerUrl,{type:"module"}),t(this._worker);return}catch{}let e=`
|
|
2
|
+
import ${JSON.stringify(this._workerUrl)};
|
|
3
|
+
`,r=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));this._worker=new Worker(r,{type:"module"}),t(this._worker)}_handleMessage(t){let{id:e,result:r,error:i}=t.data,s=this._pending.get(e);s&&(this._pending.delete(e),i?s.reject(i):s.resolve(r))}_handleError(t){console.error("[SplatWorker] Worker error:",t);for(let[e,r]of this._pending)r.reject("[SplatWorker]Worker crashed");this._pending.clear()}_collectTransferables(t){let e=[];for(let r of t)r&&(ArrayBuffer.isView(r)?e.push(r.buffer):r instanceof ArrayBuffer&&e.push(r));return e}async init(){if(this._ready)return!0;if(this._initPromise)return this._initPromise;this._initPromise=new Promise((e,r)=>{let i=++this._seq;this._pending.set(i,{resolve:e,reject:r}),this._worker.postMessage({id:i,fn:"__init__",wasmUrl:this._wasmUrl,args:[]})});let t=await this._initPromise;return this._ready=!0,t}call(t,...e){return new Promise((r,i)=>{this._worker||i(`the worker ${this._workerUrl} does not exist`);let s=++this._seq;this._pending.set(s,{resolve:r,reject:i});let u=this._collectTransferables(e);this._worker.postMessage({id:s,fn:t,wasmUrl:this._wasmUrl,args:e},u),this._timeout>0&&setTimeout(()=>{this._pending.has(s)&&(this._pending.delete(s),i(`[SplatWorker] Task "${t}" timeout after ${this._timeout}ms`))},this._timeout)})}cancel(t,e="canceled"){let r=this._pending.get(t);return r&&(r.reject(e),this._pending.delete(t)),this}dispose(){return this._worker.terminate(),this._pending.clear(),this}},F=g;typeof window!="undefined"&&(window.SplatMesh=D,window.SplatWorker=F);export{D as SplatMesh,F as SplatWorker};
|
package/dist/splat-mesh.min.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
(()=>{var W=Object.create;var S=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var R=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports);var E=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of U(t))!B.call(o,s)&&s!==e&&S(o,s,{get:()=>t[s],enumerable:!(r=V(t,s))||r.enumerable});return o};var H=(o,t,e)=>(e=o!=null?W(z(o)):{},E(t||!o||!o.__esModule?S(e,"default",{value:o,enumerable:!0}):e,o));var y=R(($,M)=>{M.exports=THREE});var i=H(y());var k="precision highp sampler2D;precision highp usampler2D;out vec4 vColor;out vec2 vPosition;uniform vec2 viewport;uniform mat4 gsModelViewMatrix;attribute uint splatIndex;uniform sampler2D centerAndScaleTexture;uniform usampler2D covAndColorTexture;vec2 unpackInt16(in uint value){int v=int(value);int v0=v>>16;int v1=(v&0xFFFF);if((v&0x8000)!=0)v1|=0xFFFF0000;return vec2(float(v1),float(v0));}vec4 calcCovVectors(vec3 viewPos,mat3 Vrk){float focal=(viewport.y/2.0)*abs(projectionMatrix[1][1]);mat3 J=mat3(focal/viewPos.z,0.,-(focal*viewPos.x)/(viewPos.z*viewPos.z),0.,focal/viewPos.z,-(focal*viewPos.y)/(viewPos.z*viewPos.z),0.,0.,0.);mat3 W=transpose(mat3(gsModelViewMatrix));mat3 T=W*J;mat3 cov=transpose(T)*Vrk*T;float diagonal1=cov[0][0]+0.3;float offDiagonal=cov[0][1];float diagonal2=cov[1][1]+0.3;float mid=0.5*(diagonal1+diagonal2);float radius=length(vec2((diagonal1-diagonal2)/2.0,offDiagonal));float lambda1=mid+radius;float lambda2=max(mid-radius,0.1);vec2 diagonalVector=normalize(vec2(offDiagonal,lambda1-diagonal1));vec2 v1=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 v2=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);return vec4(v1,v2);}void main(){ivec2 texSize=textureSize(centerAndScaleTexture,0);ivec2 texPos=ivec2(splatIndex % uint(texSize.x),splatIndex/uint(texSize.x));vec4 centerAndScaleData=texelFetch(centerAndScaleTexture,texPos,0);vec4 viewPos=gsModelViewMatrix*vec4(centerAndScaleData.xyz,1);vec4 pos2d=projectionMatrix*viewPos;float clip=1.2*pos2d.w;if(pos2d.z<-pos2d.w||pos2d.x<-clip||pos2d.x>clip||pos2d.y<-clip||pos2d.y>clip){gl_Position=vec4(0.0,0.0,2.0,1.0);return;}uvec4 covAndColorData=texelFetch(covAndColorTexture,texPos,0);vec2 cov3D_M11_M12=unpackInt16(covAndColorData.x)*centerAndScaleData.w;vec2 cov3D_M13_M22=unpackInt16(covAndColorData.y)*centerAndScaleData.w;vec2 cov3D_M23_M33=unpackInt16(covAndColorData.z)*centerAndScaleData.w;mat3 Vrk=mat3(cov3D_M11_M12.x,cov3D_M11_M12.y,cov3D_M13_M22.x,cov3D_M11_M12.y,cov3D_M13_M22.y,cov3D_M23_M33.x,cov3D_M13_M22.x,cov3D_M23_M33.x,cov3D_M23_M33.y);vec4 covVectors=calcCovVectors(viewPos.xyz,Vrk);vPosition=position.xy;uint colorUint=covAndColorData.w;vColor=vec4(float(colorUint&uint(0xFF))/255.0,float((colorUint>>uint(8))&uint(0xFF))/255.0,float((colorUint>>uint(16))&uint(0xFF))/255.0,float(colorUint>>uint(24))/255.0);vec2 vCenter=vec2(pos2d)/pos2d.w;gl_Position=vec4(vCenter+(position.x*covVectors.zw+position.y*covVectors.xy)/viewport*2.0,pos2d.z/pos2d.w,1.0);}";var A="in vec4 vColor;in vec2 vPosition;void main(){float A=-dot(vPosition,vPosition);if(A<-4.0)discard;float B=exp(A)*vColor.a;gl_FragColor=vec4(vColor.rgb,B);}";var f=class{constructor(){this._intervalTime=200,this._stableStopTime=3e3,this._isSorting=!1,this._dirty=!0,this._lastMvMatrix=null,this._lastSortTime=0,this._stableSince=0}set isSorting(t){this._isSorting=t}get isSorting(){return this._isSorting}set dirty(t){this._dirty=t}get dirty(){return this._dirty}set intervalTime(t){this._intervalTime=t}get intervalTime(){return this._intervalTime}set stableStopTime(t){this._stableStopTime=t}get stableStopTime(){return this._stableStopTime}_isMatrixChanged(t,e){return t?!t.equals(e):!0}tick(t,e){let r=performance.now(),s=this._isMatrixChanged(this._lastMvMatrix,t);s?this._stableSince=r:this._stableSince===0&&(this._stableSince=r);let n=r-this._lastSortTime>=this._intervalTime,u=r-this._stableSince<this._stableStopTime;return!this._isSorting&&n&&(this._dirty||s||u)&&(this._isSorting=!0,this._dirty=!1,this._lastSortTime=r,e()),this._lastMvMatrix=t,this}},C=f;var j="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");function T(o="D"){let t=[];t[8]=t[13]=t[18]=t[23]="-",t[14]="4";let e;for(let r=0;r<36;r++)t[r]||(e=0|Math.random()*16,t[r]=j[r===19?e&3|8:e]);return o+"-"+t.join("")}function b(){let o=document.createElement("canvas"),t=o.getContext("webgl2")||o.getContext("webgl");return t.getParameter(t.MAX_TEXTURE_SIZE)}var v=b(),G=v*v,D=new i.BufferGeometry;D.setAttribute("position",new i.BufferAttribute(new Float32Array([-2,-2,0,2,2,0,-2,2,0,2,-2,0,2,2,0,-2,-2,0]),3));var w=class extends i.Mesh{constructor(){super(),this._meshId=T(),this._vertexCount=0,this._textureWidth=v,this._textureHeight=1,this._threshold=-1e-5,this._centerAndScaleData=null,this._centerAndScaleTexture=null,this._rotationAndColorData=null,this._rotationAndColorTexture=null,this.geometry=new i.InstancedBufferGeometry().copy(D),this.geometry.instanceCount=1,this.material=new i.ShaderMaterial({uniforms:{viewport:{value:new Float32Array([1980,1080])},centerAndScaleTexture:{value:null},covAndColorTexture:{value:null},gsModelViewMatrix:{value:null}},vertexShader:k,fragmentShader:A,blending:i.CustomBlending,blendSrcAlpha:i.OneFactor,depthTest:!0,depthWrite:!1,transparent:!0}),this.material.onBeforeRender=this._onMaterialBeforeRender.bind(this),this.frustumCulled=!1,this._bounds=null,this._sortScheduler=new C,this._worker=null,this._useFrustumCulled=!1}get isSplatMesh(){return!0}set threshold(t){this._threshold=t}get threshold(){return this._threshold}set worker(t){this._worker=t}get worker(){return this._worker}get bounds(){return this._bounds}set vertexCount(t){this.setVertexCount(t)}get vertexCount(){return this._vertexCount}set useFrustumCulled(t){this._useFrustumCulled=t}get useFrustumCulled(){return this._useFrustumCulled}get sortScheduler(){return this._sortScheduler}_getModelViewMatrix(t){return t.matrixWorld.clone().invert().multiply(this.matrixWorld)}_updateTexture(t,e){t&&this._meshId===t.meshId&&(this._centerAndScaleData.set(t.out_cs),this._rotationAndColorData.set(t.out_rc),this._centerAndScaleTexture.image.data.set(this._centerAndScaleData.subarray(0,e*4),0),this._rotationAndColorTexture.image.data.set(this._rotationAndColorData.subarray(0,e*4),0),this._centerAndScaleTexture.needsUpdate=!0,this._rotationAndColorTexture.needsUpdate=!0,this._sortScheduler.dirty=!0)}_onMaterialBeforeRender(t,e,r,s,n,u){let c=this._getModelViewMatrix(r),m=n.material;m.uniforms.gsModelViewMatrix.value=c;let x=new i.Vector4;t.getCurrentViewport(x),m.uniforms.viewport.value[0]=x.z,m.uniforms.viewport.value[1]=x.w,this._sortScheduler&&this._sortScheduler.tick(c,()=>{let d=c.elements,P=new Float32Array([d[2],d[6],d[10],d[14]]),l=new Float32Array(0);if(this._useFrustumCulled){l=new Float32Array(24);let a=new i.Matrix4;a.multiplyMatrices(r.projectionMatrix,r.matrixWorldInverse);let h=new i.Frustum;h.setFromProjectionMatrix(a),h.planes.forEach((_,p)=>{l[p*4+0]=_.normal.x,l[p*4+1]=_.normal.y,l[p*4+2]=_.normal.z,l[p*4+3]=_.constant})}this._worker&&this._worker.call("sort_splats",this._meshId,P,l,this._threshold).then(a=>{if(a||(this._sortScheduler.isSorting=!1),a&&this._meshId===a.meshId){let h=new Uint32Array(a.data);this.geometry.attributes.splatIndex.set(h),this.geometry.attributes.splatIndex.needsUpdate=!0,this.geometry.instanceCount=h.length,this._sortScheduler.isSorting=!1}})})}setVertexCount(t){if(t===this._vertexCount)return;this._vertexCount=Math.min(t,G),this._textureHeight=Math.floor((this._vertexCount-1)/this._textureWidth)+1,this._centerAndScaleData=new Float32Array(this._textureWidth*this._textureHeight*4),this._centerAndScaleTexture&&this._centerAndScaleTexture.dispose(),this._centerAndScaleTexture=new i.DataTexture(this._centerAndScaleData,this._textureWidth,this._textureHeight,i.RGBAFormat,i.FloatType),this._rotationAndColorData=new Uint32Array(this._textureWidth*this._textureHeight*4),this._rotationAndColorTexture&&this._rotationAndColorTexture.dispose(),this._rotationAndColorTexture=new i.DataTexture(this._rotationAndColorData,this._textureWidth,this._textureHeight,i.RGBAIntegerFormat,i.UnsignedIntType),this._rotationAndColorTexture.internalFormat="RGBA32UI";let e=new Uint32Array(this._textureWidth*this._textureHeight),r=new i.InstancedBufferAttribute(e,1,!1);return r.setUsage(i.DynamicDrawUsage),this.geometry.setAttribute("splatIndex",r),this.material.uniforms.centerAndScaleTexture.value=this._centerAndScaleTexture,this.material.uniforms.covAndColorTexture.value=this._rotationAndColorTexture,this}attachWorker(t){return this._worker=t,this}detachWorker(){return this._worker&&this._worker.call("unregister_positions",this._bufferId),this._worker=null,this}async setDataFromBuffer(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromBuffer skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromBuffer skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_buffer",this._meshId,t,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromGeometry(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromGeometry skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromGeometry skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_geometry",this._meshId,t.attributes.position.array,t.attributes._scale.array,t.attributes._rotation.array,t.attributes.color.array,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromSpz(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromSpz skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromSpz skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_spz",this._meshId,t.positions,t.scales,t.rotations,t.colors,t.alphas,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async computeBounds(){if(!this._worker)return console.warn("[SplatMesh] computeBounds skipped: worker not ready"),this;if(!this._bounds){let t=await this._worker.call("compute_bounds",this._meshId);this._meshId===t.meshId&&(this._bounds=t.data)}return this}dispose(){this._bounds=null,this._centerAndScaleTexture&&(this._centerAndScaleTexture.dispose(),this._centerAndScaleData=null),this._rotationAndColorTexture&&(this._rotationAndColorTexture.dispose(),this._rotationAndColorData=null),this._worker&&this._worker.call("unregister_positions",this._bufferId),this._bufferId=null,this._sortScheduler=null,this.geometry.dispose(),this.material.dispose(),this.parent=null}},F=w;var g=class{constructor(t,{timeout:e=0}={}){this._workerUrl=t,this._worker=null,this._seq=0,this._pending=new Map,this._timeout=e,this._initPromise=null,this._ready=!1,this._createWorker()}_createWorker(){let t=e=>{e.onmessage=r=>this._handleMessage(r),e.onerror=r=>this._handleError(r),e.onmessageerror=r=>console.error("[SplatWorker] Worker message error:",r)};try{this._worker=new Worker(this._workerUrl,{type:"module"}),t(this._worker);return}catch(e){console.error("Worker error:",e)}fetch(this._workerUrl).then(e=>{if(!e.ok)throw new Error(`[SplatWorker] Failed to fetch worker: ${this._workerUrl}`);return e.text()}).then(e=>{let r=new Blob([e],{type:"application/javascript"}),s=URL.createObjectURL(r);this._worker=new Worker(s),t(this._worker)})}_handleMessage(t){let{id:e,result:r,error:s}=t.data,n=this._pending.get(e);n&&(this._pending.delete(e),s?n.reject(s):n.resolve(r))}_handleError(t){console.error("[SplatWorker] Worker error:",t);for(let[e,r]of this._pending)r.reject("[SplatWorker] Worker crashed");this._pending.clear()}_collectTransferables(t){let e=[];for(let r of t)r&&(ArrayBuffer.isView(r)?e.push(r.buffer):r instanceof ArrayBuffer&&e.push(r));return e}async init(){if(this._ready)return!0;if(this._initPromise)return this._initPromise;this._initPromise=new Promise((e,r)=>{let s=++this._seq;this._pending.set(s,{resolve:e,reject:r}),this._worker.postMessage({id:s,fn:"__init_wasm__",args:[]})});let t=await this._initPromise;return this._ready=!0,t}call(t,...e){return new Promise((r,s)=>{this._worker||s(`the worker ${this._workerUrl} does not exist`);let n=++this._seq;this._pending.set(n,{resolve:r,reject:s});let u=this._collectTransferables(e);this._worker.postMessage({id:n,fn:t,args:e},u),this._timeout>0&&setTimeout(()=>{this._pending.has(n)&&(this._pending.delete(n),s(`[SplatWorker] Task "${t}" timeout after ${this._timeout}ms`))},this._timeout)})}cancel(t,e="canceled"){let r=this._pending.get(t);return r&&(r.reject(e),this._pending.delete(t)),this}dispose(){return this._worker.terminate(),this._pending.clear(),this}},I=g;typeof window!="undefined"&&(window.SplatMesh=F,window.SplatWorker=I);})();
|
|
1
|
+
(()=>{var W=Object.create;var y=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var H=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var E=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of B(t))!j.call(s,o)&&o!==e&&y(s,o,{get:()=>t[o],enumerable:!(r=z(t,o))||r.enumerable});return s};var G=(s,t,e)=>(e=s!=null?W(R(s)):{},E(t||!s||!s.__esModule?y(e,"default",{value:s,enumerable:!0}):e,s));var A=H((O,M)=>{M.exports=THREE});var i=G(A());var C="precision highp sampler2D;precision highp usampler2D;out vec4 vColor;out vec2 vPosition;uniform vec2 viewport;uniform mat4 gsModelViewMatrix;attribute uint splatIndex;uniform sampler2D centerAndScaleTexture;uniform usampler2D covAndColorTexture;vec2 unpackInt16(in uint value){int v=int(value);int v0=v>>16;int v1=(v&0xFFFF);if((v&0x8000)!=0)v1|=0xFFFF0000;return vec2(float(v1),float(v0));}vec4 calcCovVectors(vec3 viewPos,mat3 Vrk){float focal=(viewport.y/2.0)*abs(projectionMatrix[1][1]);mat3 J=mat3(focal/viewPos.z,0.,-(focal*viewPos.x)/(viewPos.z*viewPos.z),0.,focal/viewPos.z,-(focal*viewPos.y)/(viewPos.z*viewPos.z),0.,0.,0.);mat3 W=transpose(mat3(gsModelViewMatrix));mat3 T=W*J;mat3 cov=transpose(T)*Vrk*T;float diagonal1=cov[0][0]+0.3;float offDiagonal=cov[0][1];float diagonal2=cov[1][1]+0.3;float mid=0.5*(diagonal1+diagonal2);float radius=length(vec2((diagonal1-diagonal2)/2.0,offDiagonal));float lambda1=mid+radius;float lambda2=max(mid-radius,0.1);vec2 diagonalVector=normalize(vec2(offDiagonal,lambda1-diagonal1));vec2 v1=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 v2=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);return vec4(v1,v2);}void main(){ivec2 texSize=textureSize(centerAndScaleTexture,0);ivec2 texPos=ivec2(splatIndex % uint(texSize.x),splatIndex/uint(texSize.x));vec4 centerAndScaleData=texelFetch(centerAndScaleTexture,texPos,0);vec4 viewPos=gsModelViewMatrix*vec4(centerAndScaleData.xyz,1);vec4 pos2d=projectionMatrix*viewPos;float clip=1.2*pos2d.w;if(pos2d.z<-pos2d.w||pos2d.x<-clip||pos2d.x>clip||pos2d.y<-clip||pos2d.y>clip){gl_Position=vec4(0.0,0.0,2.0,1.0);return;}uvec4 covAndColorData=texelFetch(covAndColorTexture,texPos,0);vec2 cov3D_M11_M12=unpackInt16(covAndColorData.x)*centerAndScaleData.w;vec2 cov3D_M13_M22=unpackInt16(covAndColorData.y)*centerAndScaleData.w;vec2 cov3D_M23_M33=unpackInt16(covAndColorData.z)*centerAndScaleData.w;mat3 Vrk=mat3(cov3D_M11_M12.x,cov3D_M11_M12.y,cov3D_M13_M22.x,cov3D_M11_M12.y,cov3D_M13_M22.y,cov3D_M23_M33.x,cov3D_M13_M22.x,cov3D_M23_M33.x,cov3D_M23_M33.y);vec4 covVectors=calcCovVectors(viewPos.xyz,Vrk);vPosition=position.xy;uint colorUint=covAndColorData.w;vColor=vec4(float(colorUint&uint(0xFF))/255.0,float((colorUint>>uint(8))&uint(0xFF))/255.0,float((colorUint>>uint(16))&uint(0xFF))/255.0,float(colorUint>>uint(24))/255.0);vec2 vCenter=vec2(pos2d)/pos2d.w;gl_Position=vec4(vCenter+(position.x*covVectors.zw+position.y*covVectors.xy)/viewport*2.0,pos2d.z/pos2d.w,1.0);}";var k="in vec4 vColor;in vec2 vPosition;void main(){float A=-dot(vPosition,vPosition);if(A<-4.0)discard;float B=exp(A)*vColor.a;gl_FragColor=vec4(vColor.rgb,B);}";var x=class{constructor(){this._intervalTime=200,this._stableStopTime=3e3,this._isSorting=!1,this._dirty=!0,this._lastMvMatrix=null,this._lastSortTime=0,this._stableSince=0}set isSorting(t){this._isSorting=t}get isSorting(){return this._isSorting}set dirty(t){this._dirty=t}get dirty(){return this._dirty}set intervalTime(t){this._intervalTime=t}get intervalTime(){return this._intervalTime}set stableStopTime(t){this._stableStopTime=t}get stableStopTime(){return this._stableStopTime}_isMatrixChanged(t,e){return t?!t.equals(e):!0}tick(t,e){let r=performance.now(),o=this._isMatrixChanged(this._lastMvMatrix,t);o?this._stableSince=r:this._stableSince===0&&(this._stableSince=r);let n=r-this._lastSortTime>=this._intervalTime,h=r-this._stableSince<this._stableStopTime;return!this._isSorting&&n&&(this._dirty||o||h)&&(this._isSorting=!0,this._dirty=!1,this._lastSortTime=r,e()),this._lastMvMatrix=t,this}},T=x;var v={},L="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");function b(s="D"){let t=[];t[8]=t[13]=t[18]=t[23]="-",t[14]="4";let e;for(let r=0;r<36;r++)t[r]||(e=0|Math.random()*16,t[r]=L[r===19?e&3|8:e]);return s+"-"+t.join("")}function D(){let s=document.createElement("canvas"),t=s.getContext("webgl2")||s.getContext("webgl");return t.getParameter(t.MAX_TEXTURE_SIZE)}function F(s){if(!s||/^[a-zA-Z]+:\/\//.test(s))return s;try{if(typeof v!="undefined"&&v.url)return new URL(s,v.url).href}catch{}if(typeof document!="undefined"&&document.currentScript&&document.currentScript.src)return new URL(s,document.currentScript.src).href;try{return new URL(s,typeof location!="undefined"?location.href:void 0).href}catch{return s}}var w=D(),q=w*w,U=new i.BufferGeometry;U.setAttribute("position",new i.BufferAttribute(new Float32Array([-2,-2,0,2,2,0,-2,2,0,2,-2,0,2,2,0,-2,-2,0]),3));var g=class extends i.Mesh{constructor(){super(),this._meshId=b(),this._vertexCount=0,this._textureWidth=w,this._textureHeight=1,this._threshold=-1e-5,this._centerAndScaleData=null,this._centerAndScaleTexture=null,this._rotationAndColorData=null,this._rotationAndColorTexture=null,this.geometry=new i.InstancedBufferGeometry().copy(U),this.geometry.instanceCount=1,this.material=new i.ShaderMaterial({uniforms:{viewport:{value:new Float32Array([1980,1080])},centerAndScaleTexture:{value:null},covAndColorTexture:{value:null},gsModelViewMatrix:{value:null}},vertexShader:C,fragmentShader:k,blending:i.CustomBlending,blendSrcAlpha:i.OneFactor,depthTest:!0,depthWrite:!1,transparent:!0}),this.material.onBeforeRender=this._onMaterialBeforeRender.bind(this),this.frustumCulled=!1,this._bounds=null,this._sortScheduler=new T,this._worker=null,this._useFrustumCulled=!1}get isSplatMesh(){return!0}set threshold(t){this._threshold=t}get threshold(){return this._threshold}set worker(t){this._worker=t}get worker(){return this._worker}get bounds(){return this._bounds}set vertexCount(t){this.setVertexCount(t)}get vertexCount(){return this._vertexCount}set useFrustumCulled(t){this._useFrustumCulled=t}get useFrustumCulled(){return this._useFrustumCulled}get sortScheduler(){return this._sortScheduler}_getModelViewMatrix(t){return t.matrixWorld.clone().invert().multiply(this.matrixWorld)}_updateTexture(t,e){t&&this._meshId===t.meshId&&(this._centerAndScaleData.set(t.out_cs),this._rotationAndColorData.set(t.out_rc),this._centerAndScaleTexture.image.data.set(this._centerAndScaleData.subarray(0,e*4),0),this._rotationAndColorTexture.image.data.set(this._rotationAndColorData.subarray(0,e*4),0),this._centerAndScaleTexture.needsUpdate=!0,this._rotationAndColorTexture.needsUpdate=!0,this._sortScheduler.dirty=!0)}_onMaterialBeforeRender(t,e,r,o,n,h){let c=this._getModelViewMatrix(r),m=n.material;m.uniforms.gsModelViewMatrix.value=c;let f=new i.Vector4;t.getCurrentViewport(f),m.uniforms.viewport.value[0]=f.z,m.uniforms.viewport.value[1]=f.w,this._sortScheduler&&this._sortScheduler.tick(c,()=>{let d=c.elements,V=new Float32Array([d[2],d[6],d[10],d[14]]),l=new Float32Array(0);if(this._useFrustumCulled){l=new Float32Array(24);let a=new i.Matrix4;a.multiplyMatrices(r.projectionMatrix,r.matrixWorldInverse);let u=new i.Frustum;u.setFromProjectionMatrix(a),u.planes.forEach((_,p)=>{l[p*4+0]=_.normal.x,l[p*4+1]=_.normal.y,l[p*4+2]=_.normal.z,l[p*4+3]=_.constant})}this._worker&&this._worker.call("sort_splats",this._meshId,V,l,this._threshold).then(a=>{if(a||(this._sortScheduler.isSorting=!1),a&&this._meshId===a.meshId){let u=new Uint32Array(a.data);this.geometry.attributes.splatIndex.set(u),this.geometry.attributes.splatIndex.needsUpdate=!0,this.geometry.instanceCount=u.length,this._sortScheduler.isSorting=!1}})})}setVertexCount(t){if(t===this._vertexCount)return;this._vertexCount=Math.min(t,q),this._textureHeight=Math.floor((this._vertexCount-1)/this._textureWidth)+1,this._centerAndScaleData=new Float32Array(this._textureWidth*this._textureHeight*4),this._centerAndScaleTexture&&this._centerAndScaleTexture.dispose(),this._centerAndScaleTexture=new i.DataTexture(this._centerAndScaleData,this._textureWidth,this._textureHeight,i.RGBAFormat,i.FloatType),this._rotationAndColorData=new Uint32Array(this._textureWidth*this._textureHeight*4),this._rotationAndColorTexture&&this._rotationAndColorTexture.dispose(),this._rotationAndColorTexture=new i.DataTexture(this._rotationAndColorData,this._textureWidth,this._textureHeight,i.RGBAIntegerFormat,i.UnsignedIntType),this._rotationAndColorTexture.internalFormat="RGBA32UI";let e=new Uint32Array(this._textureWidth*this._textureHeight),r=new i.InstancedBufferAttribute(e,1,!1);return r.setUsage(i.DynamicDrawUsage),this.geometry.setAttribute("splatIndex",r),this.material.uniforms.centerAndScaleTexture.value=this._centerAndScaleTexture,this.material.uniforms.covAndColorTexture.value=this._rotationAndColorTexture,this}attachWorker(t){return this._worker=t,this}detachWorker(){return this._worker&&this._worker.call("unregister_positions",this._bufferId),this._worker=null,this}async setDataFromBuffer(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromBuffer skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromBuffer skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_buffer",this._meshId,t,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromGeometry(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromGeometry skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromGeometry skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_geometry",this._meshId,t.attributes.position.array,t.attributes._scale.array,t.attributes._rotation.array,t.attributes.color.array,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async setDataFromSpz(t){if(this._vertexCount<=0)return console.warn("[SplatMesh] setDataFromSpz skipped: vertexCount is 0"),this;if(!this._worker)return console.warn("[SplatMesh] setDataFromSpz skipped: worker not ready"),this;let e=await this._worker.call("process_splats_from_spz",this._meshId,t.positions,t.scales,t.rotations,t.colors,t.alphas,this._vertexCount);return this._updateTexture(e,this._vertexCount),this._bounds=null,this}async computeBounds(){if(!this._worker)return console.warn("[SplatMesh] computeBounds skipped: worker not ready"),this;if(!this._bounds){let t=await this._worker.call("compute_bounds",this._meshId);this._meshId===t.meshId&&(this._bounds=t.data)}return this}dispose(){this._bounds=null,this._centerAndScaleTexture&&(this._centerAndScaleTexture.dispose(),this._centerAndScaleData=null),this._rotationAndColorTexture&&(this._rotationAndColorTexture.dispose(),this._rotationAndColorData=null),this._worker&&this._worker.call("unregister_positions",this._bufferId),this._bufferId=null,this._sortScheduler=null,this.geometry.dispose(),this.material.dispose(),this.parent=null}},I=g;var S=class{constructor(t,{timeout:e=0}={}){this._baseUrl=F(t||"./"),this._workerUrl=new URL("wasm_splat.worker.min.js",this._baseUrl).href,this._wasmUrl=new URL("wasm_splat_bg.wasm",this._baseUrl).href,this._seq=0,this._pending=new Map,this._timeout=e,this._initPromise=null,this._ready=!1,this._createWorker()}_createWorker(){let t=o=>{o.onmessage=n=>this._handleMessage(n),o.onerror=n=>this._handleError(n),o.onmessageerror=n=>console.error("[SplatWorker] Worker message error:",n)};try{this._worker=new Worker(this._workerUrl,{type:"module"}),t(this._worker);return}catch{}let e=`
|
|
2
|
+
import ${JSON.stringify(this._workerUrl)};
|
|
3
|
+
`,r=URL.createObjectURL(new Blob([e],{type:"text/javascript"}));this._worker=new Worker(r,{type:"module"}),t(this._worker)}_handleMessage(t){let{id:e,result:r,error:o}=t.data,n=this._pending.get(e);n&&(this._pending.delete(e),o?n.reject(o):n.resolve(r))}_handleError(t){console.error("[SplatWorker] Worker error:",t);for(let[e,r]of this._pending)r.reject("[SplatWorker]Worker crashed");this._pending.clear()}_collectTransferables(t){let e=[];for(let r of t)r&&(ArrayBuffer.isView(r)?e.push(r.buffer):r instanceof ArrayBuffer&&e.push(r));return e}async init(){if(this._ready)return!0;if(this._initPromise)return this._initPromise;this._initPromise=new Promise((e,r)=>{let o=++this._seq;this._pending.set(o,{resolve:e,reject:r}),this._worker.postMessage({id:o,fn:"__init__",wasmUrl:this._wasmUrl,args:[]})});let t=await this._initPromise;return this._ready=!0,t}call(t,...e){return new Promise((r,o)=>{this._worker||o(`the worker ${this._workerUrl} does not exist`);let n=++this._seq;this._pending.set(n,{resolve:r,reject:o});let h=this._collectTransferables(e);this._worker.postMessage({id:n,fn:t,wasmUrl:this._wasmUrl,args:e},h),this._timeout>0&&setTimeout(()=>{this._pending.has(n)&&(this._pending.delete(n),o(`[SplatWorker] Task "${t}" timeout after ${this._timeout}ms`))},this._timeout)})}cancel(t,e="canceled"){let r=this._pending.get(t);return r&&(r.reject(e),this._pending.delete(t)),this}dispose(){return this._worker.terminate(),this._pending.clear(),this}},P=S;typeof window!="undefined"&&(window.SplatMesh=I,window.SplatWorker=P);})();
|
|
@@ -1 +1,363 @@
|
|
|
1
|
-
|
|
1
|
+
// pkg-web/wasm_splat.js
|
|
2
|
+
var wasm;
|
|
3
|
+
function addHeapObject(obj) {
|
|
4
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
5
|
+
const idx = heap_next;
|
|
6
|
+
heap_next = heap[idx];
|
|
7
|
+
heap[idx] = obj;
|
|
8
|
+
return idx;
|
|
9
|
+
}
|
|
10
|
+
function dropObject(idx) {
|
|
11
|
+
if (idx < 132) return;
|
|
12
|
+
heap[idx] = heap_next;
|
|
13
|
+
heap_next = idx;
|
|
14
|
+
}
|
|
15
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
16
|
+
ptr = ptr >>> 0;
|
|
17
|
+
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
18
|
+
}
|
|
19
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
20
|
+
ptr = ptr >>> 0;
|
|
21
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
22
|
+
}
|
|
23
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
24
|
+
ptr = ptr >>> 0;
|
|
25
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
26
|
+
}
|
|
27
|
+
var cachedDataViewMemory0 = null;
|
|
28
|
+
function getDataViewMemory0() {
|
|
29
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
|
|
30
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
31
|
+
}
|
|
32
|
+
return cachedDataViewMemory0;
|
|
33
|
+
}
|
|
34
|
+
var cachedFloat32ArrayMemory0 = null;
|
|
35
|
+
function getFloat32ArrayMemory0() {
|
|
36
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
37
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
38
|
+
}
|
|
39
|
+
return cachedFloat32ArrayMemory0;
|
|
40
|
+
}
|
|
41
|
+
var cachedUint32ArrayMemory0 = null;
|
|
42
|
+
function getUint32ArrayMemory0() {
|
|
43
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
44
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
45
|
+
}
|
|
46
|
+
return cachedUint32ArrayMemory0;
|
|
47
|
+
}
|
|
48
|
+
var cachedUint8ArrayMemory0 = null;
|
|
49
|
+
function getUint8ArrayMemory0() {
|
|
50
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
51
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
52
|
+
}
|
|
53
|
+
return cachedUint8ArrayMemory0;
|
|
54
|
+
}
|
|
55
|
+
function getObject(idx) {
|
|
56
|
+
return heap[idx];
|
|
57
|
+
}
|
|
58
|
+
var heap = new Array(128).fill(void 0);
|
|
59
|
+
heap.push(void 0, null, true, false);
|
|
60
|
+
var heap_next = heap.length;
|
|
61
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
62
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
63
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
64
|
+
WASM_VECTOR_LEN = arg.length;
|
|
65
|
+
return ptr;
|
|
66
|
+
}
|
|
67
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
68
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
69
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
70
|
+
WASM_VECTOR_LEN = arg.length;
|
|
71
|
+
return ptr;
|
|
72
|
+
}
|
|
73
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
74
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
75
|
+
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
76
|
+
WASM_VECTOR_LEN = arg.length;
|
|
77
|
+
return ptr;
|
|
78
|
+
}
|
|
79
|
+
function takeObject(idx) {
|
|
80
|
+
const ret = getObject(idx);
|
|
81
|
+
dropObject(idx);
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
var WASM_VECTOR_LEN = 0;
|
|
85
|
+
function append_data_from_buffer(buffer_id, u8buf, vertex_count, out_center_scale, out_cov_color) {
|
|
86
|
+
const ptr0 = passArray8ToWasm0(u8buf, wasm.__wbindgen_export);
|
|
87
|
+
const len0 = WASM_VECTOR_LEN;
|
|
88
|
+
var ptr1 = passArrayF32ToWasm0(out_center_scale, wasm.__wbindgen_export);
|
|
89
|
+
var len1 = WASM_VECTOR_LEN;
|
|
90
|
+
var ptr2 = passArray32ToWasm0(out_cov_color, wasm.__wbindgen_export);
|
|
91
|
+
var len2 = WASM_VECTOR_LEN;
|
|
92
|
+
wasm.append_data_from_buffer(buffer_id, ptr0, len0, vertex_count, ptr1, len1, addHeapObject(out_center_scale), ptr2, len2, addHeapObject(out_cov_color));
|
|
93
|
+
}
|
|
94
|
+
function compute_bounds(buffer_id) {
|
|
95
|
+
try {
|
|
96
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
97
|
+
wasm.compute_bounds(retptr, buffer_id);
|
|
98
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
99
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
100
|
+
var v1 = getArrayF32FromWasm0(r0, r1).slice();
|
|
101
|
+
wasm.__wbindgen_export2(r0, r1 * 4, 4);
|
|
102
|
+
return v1;
|
|
103
|
+
} finally {
|
|
104
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function process_splats_from_buffer(u8buf, vertex_count, out_center_scale, out_cov_color) {
|
|
108
|
+
const ptr0 = passArray8ToWasm0(u8buf, wasm.__wbindgen_export);
|
|
109
|
+
const len0 = WASM_VECTOR_LEN;
|
|
110
|
+
var ptr1 = passArrayF32ToWasm0(out_center_scale, wasm.__wbindgen_export);
|
|
111
|
+
var len1 = WASM_VECTOR_LEN;
|
|
112
|
+
var ptr2 = passArray32ToWasm0(out_cov_color, wasm.__wbindgen_export);
|
|
113
|
+
var len2 = WASM_VECTOR_LEN;
|
|
114
|
+
const ret = wasm.process_splats_from_buffer(ptr0, len0, vertex_count, ptr1, len1, addHeapObject(out_center_scale), ptr2, len2, addHeapObject(out_cov_color));
|
|
115
|
+
return ret >>> 0;
|
|
116
|
+
}
|
|
117
|
+
function process_splats_from_geometry(positions, scales, rotations, colors, vertex_count, out_center_scale, out_cov_color) {
|
|
118
|
+
const ptr0 = passArrayF32ToWasm0(positions, wasm.__wbindgen_export);
|
|
119
|
+
const len0 = WASM_VECTOR_LEN;
|
|
120
|
+
const ptr1 = passArrayF32ToWasm0(scales, wasm.__wbindgen_export);
|
|
121
|
+
const len1 = WASM_VECTOR_LEN;
|
|
122
|
+
const ptr2 = passArrayF32ToWasm0(rotations, wasm.__wbindgen_export);
|
|
123
|
+
const len2 = WASM_VECTOR_LEN;
|
|
124
|
+
const ptr3 = passArray8ToWasm0(colors, wasm.__wbindgen_export);
|
|
125
|
+
const len3 = WASM_VECTOR_LEN;
|
|
126
|
+
var ptr4 = passArrayF32ToWasm0(out_center_scale, wasm.__wbindgen_export);
|
|
127
|
+
var len4 = WASM_VECTOR_LEN;
|
|
128
|
+
var ptr5 = passArray32ToWasm0(out_cov_color, wasm.__wbindgen_export);
|
|
129
|
+
var len5 = WASM_VECTOR_LEN;
|
|
130
|
+
const ret = wasm.process_splats_from_geometry(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, vertex_count, ptr4, len4, addHeapObject(out_center_scale), ptr5, len5, addHeapObject(out_cov_color));
|
|
131
|
+
return ret >>> 0;
|
|
132
|
+
}
|
|
133
|
+
function process_splats_from_spz(positions, scales, rotations, colors, alphas, vertex_count, out_center_scale, out_cov_color) {
|
|
134
|
+
const ptr0 = passArrayF32ToWasm0(positions, wasm.__wbindgen_export);
|
|
135
|
+
const len0 = WASM_VECTOR_LEN;
|
|
136
|
+
const ptr1 = passArrayF32ToWasm0(scales, wasm.__wbindgen_export);
|
|
137
|
+
const len1 = WASM_VECTOR_LEN;
|
|
138
|
+
const ptr2 = passArrayF32ToWasm0(rotations, wasm.__wbindgen_export);
|
|
139
|
+
const len2 = WASM_VECTOR_LEN;
|
|
140
|
+
const ptr3 = passArrayF32ToWasm0(colors, wasm.__wbindgen_export);
|
|
141
|
+
const len3 = WASM_VECTOR_LEN;
|
|
142
|
+
const ptr4 = passArrayF32ToWasm0(alphas, wasm.__wbindgen_export);
|
|
143
|
+
const len4 = WASM_VECTOR_LEN;
|
|
144
|
+
var ptr5 = passArrayF32ToWasm0(out_center_scale, wasm.__wbindgen_export);
|
|
145
|
+
var len5 = WASM_VECTOR_LEN;
|
|
146
|
+
var ptr6 = passArray32ToWasm0(out_cov_color, wasm.__wbindgen_export);
|
|
147
|
+
var len6 = WASM_VECTOR_LEN;
|
|
148
|
+
const ret = wasm.process_splats_from_spz(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, vertex_count, ptr5, len5, addHeapObject(out_center_scale), ptr6, len6, addHeapObject(out_cov_color));
|
|
149
|
+
return ret >>> 0;
|
|
150
|
+
}
|
|
151
|
+
function sort_splats(buffer_id, view, frustum, threshold) {
|
|
152
|
+
try {
|
|
153
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
154
|
+
const ptr0 = passArrayF32ToWasm0(view, wasm.__wbindgen_export);
|
|
155
|
+
const len0 = WASM_VECTOR_LEN;
|
|
156
|
+
const ptr1 = passArrayF32ToWasm0(frustum, wasm.__wbindgen_export);
|
|
157
|
+
const len1 = WASM_VECTOR_LEN;
|
|
158
|
+
wasm.sort_splats(retptr, buffer_id, ptr0, len0, ptr1, len1, threshold);
|
|
159
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
160
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
161
|
+
var v3 = getArrayU32FromWasm0(r0, r1).slice();
|
|
162
|
+
wasm.__wbindgen_export2(r0, r1 * 4, 4);
|
|
163
|
+
return v3;
|
|
164
|
+
} finally {
|
|
165
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function unregister_positions(buffer_id) {
|
|
169
|
+
wasm.unregister_positions(buffer_id);
|
|
170
|
+
}
|
|
171
|
+
var EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
|
|
172
|
+
async function __wbg_load(module, imports) {
|
|
173
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
174
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
175
|
+
try {
|
|
176
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
179
|
+
if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
|
|
180
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
181
|
+
} else {
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const bytes = await module.arrayBuffer();
|
|
187
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
188
|
+
} else {
|
|
189
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
190
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
191
|
+
return { instance, module };
|
|
192
|
+
} else {
|
|
193
|
+
return instance;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function __wbg_get_imports() {
|
|
198
|
+
const imports = {};
|
|
199
|
+
imports.wbg = {};
|
|
200
|
+
imports.wbg.__wbg___wbindgen_copy_to_typed_array_db832bc4df7216c1 = function(arg0, arg1, arg2) {
|
|
201
|
+
new Uint8Array(getObject(arg2).buffer, getObject(arg2).byteOffset, getObject(arg2).byteLength).set(getArrayU8FromWasm0(arg0, arg1));
|
|
202
|
+
};
|
|
203
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
204
|
+
takeObject(arg0);
|
|
205
|
+
};
|
|
206
|
+
return imports;
|
|
207
|
+
}
|
|
208
|
+
function __wbg_finalize_init(instance, module) {
|
|
209
|
+
wasm = instance.exports;
|
|
210
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
211
|
+
cachedDataViewMemory0 = null;
|
|
212
|
+
cachedFloat32ArrayMemory0 = null;
|
|
213
|
+
cachedUint32ArrayMemory0 = null;
|
|
214
|
+
cachedUint8ArrayMemory0 = null;
|
|
215
|
+
return wasm;
|
|
216
|
+
}
|
|
217
|
+
async function __wbg_init(module_or_path) {
|
|
218
|
+
if (wasm !== void 0) return wasm;
|
|
219
|
+
if (typeof module_or_path !== "undefined") {
|
|
220
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
221
|
+
({ module_or_path } = module_or_path);
|
|
222
|
+
} else {
|
|
223
|
+
console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (typeof module_or_path === "undefined") {
|
|
227
|
+
module_or_path = new URL("wasm_splat_bg.wasm", import.meta.url);
|
|
228
|
+
}
|
|
229
|
+
const imports = __wbg_get_imports();
|
|
230
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
|
|
231
|
+
module_or_path = fetch(module_or_path);
|
|
232
|
+
}
|
|
233
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
234
|
+
return __wbg_finalize_init(instance, module);
|
|
235
|
+
}
|
|
236
|
+
var wasm_splat_default = __wbg_init;
|
|
237
|
+
|
|
238
|
+
// workers/wasm_splat.worker.js
|
|
239
|
+
var wasmReady = false;
|
|
240
|
+
var initPromise = null;
|
|
241
|
+
var meshCache = {};
|
|
242
|
+
async function _ensureWasm(wasmUrl) {
|
|
243
|
+
if (wasmReady) return true;
|
|
244
|
+
if (!initPromise) {
|
|
245
|
+
initPromise = wasm_splat_default(wasmUrl).then(() => {
|
|
246
|
+
wasmReady = true;
|
|
247
|
+
return true;
|
|
248
|
+
}).catch((err) => {
|
|
249
|
+
wasmReady = false;
|
|
250
|
+
initPromise = null;
|
|
251
|
+
throw err;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return initPromise;
|
|
255
|
+
}
|
|
256
|
+
function _createOutputBuffers(count) {
|
|
257
|
+
const outCS = new Float32Array(new ArrayBuffer(count * 4 * 4));
|
|
258
|
+
const outRC = new Uint32Array(new ArrayBuffer(count * 4 * 4));
|
|
259
|
+
return { outCS, outRC };
|
|
260
|
+
}
|
|
261
|
+
self.onmessage = async (e) => {
|
|
262
|
+
const { id, fn, wasmUrl, args } = e.data;
|
|
263
|
+
try {
|
|
264
|
+
let result;
|
|
265
|
+
if (fn === "__init__") {
|
|
266
|
+
if (!wasmReady) {
|
|
267
|
+
await wasm_splat_default(wasmUrl);
|
|
268
|
+
wasmReady = true;
|
|
269
|
+
}
|
|
270
|
+
postMessage({ id, result: true });
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
await _ensureWasm(wasmUrl);
|
|
274
|
+
if (fn === "process_splats_from_buffer") {
|
|
275
|
+
const [meshId, buffer, count] = args;
|
|
276
|
+
const u8 = new Uint8Array(buffer);
|
|
277
|
+
const { outCS, outRC } = _createOutputBuffers(count);
|
|
278
|
+
const bufferId = process_splats_from_buffer(u8, count, outCS, outRC);
|
|
279
|
+
meshCache[meshId] = { bufferId };
|
|
280
|
+
result = { meshId, out_cs: outCS, out_rc: outRC };
|
|
281
|
+
} else if (fn === "append_data_from_buffer") {
|
|
282
|
+
let [meshId, buffer, count] = args;
|
|
283
|
+
const { bufferId } = meshCache[meshId];
|
|
284
|
+
let u8 = new Uint8Array(buffer);
|
|
285
|
+
const { outCS, outRC } = _createOutputBuffers(count);
|
|
286
|
+
append_data_from_buffer(bufferId, u8, count, outCS, outRC);
|
|
287
|
+
result = { out_cs: outCS, out_rc: outRC };
|
|
288
|
+
buffer = null;
|
|
289
|
+
u8 = null;
|
|
290
|
+
} else if (fn === "process_splats_from_geometry") {
|
|
291
|
+
let [meshId, positions, scales, rotations, colors, count] = args;
|
|
292
|
+
const { outCS, outRC } = _createOutputBuffers(count);
|
|
293
|
+
const bufferId = process_splats_from_geometry(
|
|
294
|
+
positions,
|
|
295
|
+
scales,
|
|
296
|
+
rotations,
|
|
297
|
+
colors,
|
|
298
|
+
count,
|
|
299
|
+
outCS,
|
|
300
|
+
outRC
|
|
301
|
+
);
|
|
302
|
+
meshCache[meshId] = { bufferId };
|
|
303
|
+
result = { meshId, out_cs: outCS, out_rc: outRC };
|
|
304
|
+
positions = null;
|
|
305
|
+
scales = null;
|
|
306
|
+
rotations = null;
|
|
307
|
+
colors = null;
|
|
308
|
+
} else if (fn === "process_splats_from_spz") {
|
|
309
|
+
let [meshId, positions, scales, rotations, colors, alphas, count] = args;
|
|
310
|
+
const { outCS, outRC } = _createOutputBuffers(count);
|
|
311
|
+
const bufferId = process_splats_from_spz(
|
|
312
|
+
positions,
|
|
313
|
+
scales,
|
|
314
|
+
rotations,
|
|
315
|
+
colors,
|
|
316
|
+
alphas,
|
|
317
|
+
count,
|
|
318
|
+
outCS,
|
|
319
|
+
outRC
|
|
320
|
+
);
|
|
321
|
+
meshCache[meshId] = { bufferId };
|
|
322
|
+
result = { meshId, out_cs: outCS, out_rc: outRC };
|
|
323
|
+
positions = null;
|
|
324
|
+
scales = null;
|
|
325
|
+
rotations = null;
|
|
326
|
+
colors = null;
|
|
327
|
+
alphas = null;
|
|
328
|
+
} else if (fn === "sort_splats") {
|
|
329
|
+
const [meshId, view, planes, threshold] = args;
|
|
330
|
+
const { bufferId } = meshCache[meshId];
|
|
331
|
+
const data = sort_splats(bufferId, view, planes, threshold);
|
|
332
|
+
result = { meshId, data };
|
|
333
|
+
} else if (fn === "compute_bounds") {
|
|
334
|
+
const [meshId] = args;
|
|
335
|
+
const { bufferId } = meshCache[meshId];
|
|
336
|
+
const data = compute_bounds(bufferId);
|
|
337
|
+
result = { meshId, data };
|
|
338
|
+
} else if (fn === "unregister_positions") {
|
|
339
|
+
const [meshId] = args;
|
|
340
|
+
const { bufferId } = meshCache[meshId];
|
|
341
|
+
unregister_positions(bufferId);
|
|
342
|
+
result = true;
|
|
343
|
+
}
|
|
344
|
+
if (result instanceof Uint32Array) {
|
|
345
|
+
postMessage({ id, result }, [result.buffer]);
|
|
346
|
+
result = null;
|
|
347
|
+
} else if (result && result.data) {
|
|
348
|
+
postMessage({ id, result }, [result.data.buffer]);
|
|
349
|
+
result.data = null;
|
|
350
|
+
result = null;
|
|
351
|
+
} else if (result && result.out_cs && result.out_rc) {
|
|
352
|
+
postMessage({ id, result }, [result.out_cs.buffer, result.out_rc.buffer]);
|
|
353
|
+
result.out_cs = null;
|
|
354
|
+
result.out_rc = null;
|
|
355
|
+
result = null;
|
|
356
|
+
} else {
|
|
357
|
+
postMessage({ id, result });
|
|
358
|
+
}
|
|
359
|
+
} catch (err) {
|
|
360
|
+
console.error(err);
|
|
361
|
+
postMessage({ id, error: err?.message || String(err) });
|
|
362
|
+
}
|
|
363
|
+
};
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@dvt3d/splat-mesh",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"repository": "https://github.com/dvt3d/splat-mesh.git",
|
|
6
|
-
"author": "Caven Chen <cavencj@gmail.com>",
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "rimraf dist && gulp dev",
|
|
10
|
-
"build": "rimraf dist && gulp build",
|
|
11
|
-
"build:node": "rimraf dist && gulp buildNode",
|
|
12
|
-
"build:iife": "rimraf dist && gulp buildIIFE",
|
|
13
|
-
"build:release": "rimraf dist && gulp buildRelease",
|
|
14
|
-
"prepublishOnly": "yarn run build:release",
|
|
15
|
-
"lint": "eslint --fix src"
|
|
16
|
-
},
|
|
17
|
-
"peerDependencies": {
|
|
18
|
-
"three": "^0.182.0"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"Gaussian splatting",
|
|
22
|
-
"3dgs",
|
|
23
|
-
"three.js",
|
|
24
|
-
"splat-mesh"
|
|
25
|
-
],
|
|
26
|
-
"files": [
|
|
27
|
-
"dist"
|
|
28
|
-
],
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"chalk": "^5.6.2",
|
|
31
|
-
"esbuild": "^0.27.2",
|
|
32
|
-
"esbuild-plugin-globals": "^0.2.0",
|
|
33
|
-
"esbuild-plugin-glsl": "^1.4.1",
|
|
34
|
-
"fs-extra": "^11.3.3",
|
|
35
|
-
"gulp": "^5.0.1",
|
|
36
|
-
"prettier": "^3.7.4",
|
|
37
|
-
"rimraf": "^6.1.2",
|
|
38
|
-
"shelljs": "^0.10.0"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@dvt3d/splat-mesh",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"repository": "https://github.com/dvt3d/splat-mesh.git",
|
|
6
|
+
"author": "Caven Chen <cavencj@gmail.com>",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "rimraf dist && gulp dev",
|
|
10
|
+
"build": "rimraf dist && gulp build",
|
|
11
|
+
"build:node": "rimraf dist && gulp buildNode",
|
|
12
|
+
"build:iife": "rimraf dist && gulp buildIIFE",
|
|
13
|
+
"build:release": "rimraf dist && gulp buildRelease",
|
|
14
|
+
"prepublishOnly": "yarn run build:release",
|
|
15
|
+
"lint": "eslint --fix src"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"three": "^0.182.0"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"Gaussian splatting",
|
|
22
|
+
"3dgs",
|
|
23
|
+
"three.js",
|
|
24
|
+
"splat-mesh"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"chalk": "^5.6.2",
|
|
31
|
+
"esbuild": "^0.27.2",
|
|
32
|
+
"esbuild-plugin-globals": "^0.2.0",
|
|
33
|
+
"esbuild-plugin-glsl": "^1.4.1",
|
|
34
|
+
"fs-extra": "^11.3.3",
|
|
35
|
+
"gulp": "^5.0.1",
|
|
36
|
+
"prettier": "^3.7.4",
|
|
37
|
+
"rimraf": "^6.1.2",
|
|
38
|
+
"shelljs": "^0.10.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let e;function n(e){l===f.length&&f.push(f.length+1);const n=l;return l=f[n],f[n]=e,n}function t(e,n){return e>>>=0,i().subarray(e/4,e/4+n)}let r=null;function o(){return(null===r||!0===r.buffer.detached||void 0===r.buffer.detached&&r.buffer!==e.memory.buffer)&&(r=new DataView(e.memory.buffer)),r}let _=null;function i(){return null!==_&&0!==_.byteLength||(_=new Float32Array(e.memory.buffer)),_}let s=null;function a(){return null!==s&&0!==s.byteLength||(s=new Uint32Array(e.memory.buffer)),s}let u=null;function c(){return null!==u&&0!==u.byteLength||(u=new Uint8Array(e.memory.buffer)),u}function p(e){return f[e]}let f=new Array(128).fill(void 0);f.push(void 0,null,!0,!1);let l=f.length;function b(e,n){const t=n(4*e.length,4)>>>0;return a().set(e,t/4),y=e.length,t}function d(e,n){const t=n(1*e.length,1)>>>0;return c().set(e,t/1),y=e.length,t}function g(e,n){const t=n(4*e.length,4)>>>0;return i().set(e,t/4),y=e.length,t}function w(e){const n=p(e);return function(e){e<132||(f[e]=l,l=e)}(e),n}let y=0;export function append_data_from_buffer(t,r,o,_,i){const s=d(r,e.__wbindgen_export),a=y;var u=g(_,e.__wbindgen_export),c=y,p=b(i,e.__wbindgen_export),f=y;e.append_data_from_buffer(t,s,a,o,u,c,n(_),p,f,n(i))}export function compute_bounds(n){try{const s=e.__wbindgen_add_to_stack_pointer(-16);e.compute_bounds(s,n);var r=o().getInt32(s+0,!0),_=o().getInt32(s+4,!0),i=t(r,_).slice();return e.__wbindgen_export2(r,4*_,4),i}finally{e.__wbindgen_add_to_stack_pointer(16)}}export function get_positions(n){try{const s=e.__wbindgen_add_to_stack_pointer(-16);e.get_positions(s,n);var r=o().getInt32(s+0,!0),_=o().getInt32(s+4,!0),i=t(r,_).slice();return e.__wbindgen_export2(r,4*_,4),i}finally{e.__wbindgen_add_to_stack_pointer(16)}}export function process_splats_from_buffer(t,r,o,_){const i=d(t,e.__wbindgen_export),s=y;var a=g(o,e.__wbindgen_export),u=y,c=b(_,e.__wbindgen_export),p=y;return e.process_splats_from_buffer(i,s,r,a,u,n(o),c,p,n(_))>>>0}export function process_splats_from_geometry(t,r,o,_,i,s,a){const u=g(t,e.__wbindgen_export),c=y,p=g(r,e.__wbindgen_export),f=y,l=g(o,e.__wbindgen_export),w=y,m=d(_,e.__wbindgen_export),x=y;var h=g(s,e.__wbindgen_export),v=y,A=b(a,e.__wbindgen_export),W=y;return e.process_splats_from_geometry(u,c,p,f,l,w,m,x,i,h,v,n(s),A,W,n(a))>>>0}export function process_splats_from_spz(t,r,o,_,i,s,a,u){const c=g(t,e.__wbindgen_export),p=y,f=g(r,e.__wbindgen_export),l=y,d=g(o,e.__wbindgen_export),w=y,m=g(_,e.__wbindgen_export),x=y,h=g(i,e.__wbindgen_export),v=y;var A=g(a,e.__wbindgen_export),W=y,I=b(u,e.__wbindgen_export),k=y;return e.process_splats_from_spz(c,p,f,l,d,w,m,x,h,v,s,A,W,n(a),I,k,n(u))>>>0}export function sort_splats(n,t,r,_){try{const f=e.__wbindgen_add_to_stack_pointer(-16),l=g(t,e.__wbindgen_export),b=y,d=g(r,e.__wbindgen_export),w=y;e.sort_splats(f,n,l,b,d,w,_);var i=o().getInt32(f+0,!0),s=o().getInt32(f+4,!0),u=(c=i,p=s,c>>>=0,a().subarray(c/4,c/4+p)).slice();return e.__wbindgen_export2(i,4*s,4),u}finally{e.__wbindgen_add_to_stack_pointer(16)}var c,p}export function unregister_positions(n){e.unregister_positions(n)}const m=new Set(["basic","cors","default"]);function x(){const e={wbg:{}};return e.wbg.__wbg___wbindgen_copy_to_typed_array_db832bc4df7216c1=function(e,n,t){var r,o;new Uint8Array(p(t).buffer,p(t).byteOffset,p(t).byteLength).set((r=e,o=n,r>>>=0,c().subarray(r/1,r/1+o)))},e.wbg.__wbindgen_object_drop_ref=function(e){w(e)},e}function h(n,t){return e=n.exports,A.__wbindgen_wasm_module=t,r=null,_=null,s=null,u=null,e}function v(n){if(void 0!==e)return e;void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module:n}=n):console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const t=x();n instanceof WebAssembly.Module||(n=new WebAssembly.Module(n));return h(new WebAssembly.Instance(n,t),n)}async function A(n){if(void 0!==e)return e;void 0!==n&&(Object.getPrototypeOf(n)===Object.prototype?({module_or_path:n}=n):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===n&&(n=new URL("wasm_splat_bg.wasm",import.meta.url));const t=x();("string"==typeof n||"function"==typeof Request&&n instanceof Request||"function"==typeof URL&&n instanceof URL)&&(n=fetch(n));const{instance:r,module:o}=await async function(e,n){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,n)}catch(n){if(!e.ok||!m.has(e.type)||"application/wasm"===e.headers.get("Content-Type"))throw n;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n)}const t=await e.arrayBuffer();return await WebAssembly.instantiate(t,n)}{const t=await WebAssembly.instantiate(e,n);return t instanceof WebAssembly.Instance?{instance:t,module:e}:t}}(await n,t);return h(r,o)}export{v as initSync};export default A;
|