UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

1 lines 64.1 kB
import{S as e,K as t,aK as s,aL as n,aM as r,aN as i,m as o,aO as a,A as c,a2 as l,r as u,X as h,W as _,Y as d,y as p,R as f,aP as m,aQ as x,g as v,M as S,V as y,f as g,aR as C,aS as w,L as T,H as E,aT as A,aU as P,b as z,e as b,C as D,aV as H,a7 as M,j as I,Q as R,aH as U,i as V,aW as F,B,aX as L,aG as k}from"./index-Bw2N6w1y.esm.min.js";import"./clipPlaneFragment-DTAX_VuH.esm.min.js";import"./logDepthDeclaration-CnH2PdMn.esm.min.js";import"./fogFragment-B-gxjitm.esm.min.js";import"./sceneUboDeclaration-NN0CuugE.esm.min.js";import"./meshUboDeclaration-DL3v2Ew4.esm.min.js";import"./clipPlaneVertex-Bnps_8-3.esm.min.js";import"./logDepthVertex-C_P25MDi.esm.min.js";import"./helperFunctions-VdqKNhfd.esm.min.js";import"./clipPlaneFragment-Bcs0Djfm.esm.min.js";import"./logDepthDeclaration-gvQQD7z7.esm.min.js";import"./fogFragment-Jrm4is7s.esm.min.js";import"./sceneUboDeclaration-Bfi1TSBE.esm.min.js";import"./meshUboDeclaration-B530jCEj.esm.min.js";import"./helperFunctions-BD2JDv1s.esm.min.js";import"./clipPlaneVertex-Ccib0o3Q.esm.min.js";import"./logDepthVertex-C70dZvsO.esm.min.js";import{R as O}from"./rawTexture-CPAqHIA7.esm.min.js";import"./thinInstanceMesh-UvlYUF1v.esm.min.js";import{A as N}from"./assetContainer-21j7tcC8.esm.min.js";import{Ray as G}from"./ray-CjC2DcOu.esm.min.js";import{S as W}from"./standardMaterial-D6B7cUry.esm.min.js";const X="gaussianSplattingFragmentDeclaration";e.IncludesShadersStore[X]||(e.IncludesShadersStore[X]="vec4 gaussianColor(vec4 inColor)\n{float A=-dot(vPosition,vPosition);if (A<-4.0) discard;float B=exp(A)*inColor.a;\n#include<logDepthFragment>\nvec3 color=inColor.rgb;\n#ifdef FOG\n#include<fogFragment>\n#endif\nreturn vec4(color,B);}\n");const j="gaussianSplattingPixelShader",Z="#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvarying vec4 vColor;varying vec2 vPosition;\n#include<gaussianSplattingFragmentDeclaration>\nvoid main () { \n#include<clipPlaneFragment>\ngl_FragColor=gaussianColor(vColor);}\n";e.ShadersStore[j]||(e.ShadersStore[j]=Z);const Y={name:j,shader:Z};var K=Object.freeze({__proto__:null,gaussianSplattingPixelShader:Y});const q="gaussianSplattingVertexDeclaration";e.IncludesShadersStore[q]||(e.IncludesShadersStore[q]="attribute vec2 position;uniform mat4 view;uniform mat4 projection;uniform mat4 world;uniform vec4 vEyePosition;");const Q="gaussianSplattingUboDeclaration";e.IncludesShadersStore[Q]||(e.IncludesShadersStore[Q]="#include<sceneUboDeclaration>\n#include<meshUboDeclaration>\nattribute vec2 position;");const J="gaussianSplatting";e.IncludesShadersStore[J]||(e.IncludesShadersStore[J]="#if !defined(WEBGL2) && !defined(WEBGPU) && !defined(NATIVE)\nmat3 transpose(mat3 matrix) {return mat3(matrix[0][0],matrix[1][0],matrix[2][0],\nmatrix[0][1],matrix[1][1],matrix[2][1],\nmatrix[0][2],matrix[1][2],matrix[2][2]);}\n#endif\nvec2 getDataUV(float index,vec2 textureSize) {float y=floor(index/textureSize.x);float x=index-y*textureSize.x;return vec2((x+0.5)/textureSize.x,(y+0.5)/textureSize.y);}\n#if SH_DEGREE>0\nivec2 getDataUVint(float index,vec2 textureSize) {float y=floor(index/textureSize.x);float x=index-y*textureSize.x;return ivec2(uint(x+0.5),uint(y+0.5));}\n#endif\nstruct Splat {vec4 center;vec4 color;vec4 covA;vec4 covB;\n#if SH_DEGREE>0\nuvec4 sh0; \n#endif\n#if SH_DEGREE>1\nuvec4 sh1;\n#endif\n#if SH_DEGREE>2\nuvec4 sh2;\n#endif\n};Splat readSplat(float splatIndex)\n{Splat splat;vec2 splatUV=getDataUV(splatIndex,dataTextureSize);splat.center=texture2D(centersTexture,splatUV);splat.color=texture2D(colorsTexture,splatUV);splat.covA=texture2D(covariancesATexture,splatUV)*splat.center.w;splat.covB=texture2D(covariancesBTexture,splatUV)*splat.center.w;\n#if SH_DEGREE>0\nivec2 splatUVint=getDataUVint(splatIndex,dataTextureSize);splat.sh0=texelFetch(shTexture0,splatUVint,0);\n#endif\n#if SH_DEGREE>1\nsplat.sh1=texelFetch(shTexture1,splatUVint,0);\n#endif\n#if SH_DEGREE>2\nsplat.sh2=texelFetch(shTexture2,splatUVint,0);\n#endif\nreturn splat;}\n#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)\nvec3 computeColorFromSHDegree(vec3 dir,const vec3 sh[16])\n{const float SH_C0=0.28209479;const float SH_C1=0.48860251;float SH_C2[5];SH_C2[0]=1.092548430;SH_C2[1]=-1.09254843;SH_C2[2]=0.315391565;SH_C2[3]=-1.09254843;SH_C2[4]=0.546274215;float SH_C3[7];SH_C3[0]=-0.59004358;SH_C3[1]=2.890611442;SH_C3[2]=-0.45704579;SH_C3[3]=0.373176332;SH_C3[4]=-0.45704579;SH_C3[5]=1.445305721;SH_C3[6]=-0.59004358;vec3 result=/*SH_C0**/sh[0];\n#if SH_DEGREE>0\nfloat x=dir.x;float y=dir.y;float z=dir.z;result+=- SH_C1*y*sh[1]+SH_C1*z*sh[2]-SH_C1*x*sh[3];\n#if SH_DEGREE>1\nfloat xx=x*x,yy=y*y,zz=z*z;float xy=x*y,yz=y*z,xz=x*z;result+=\nSH_C2[0]*xy*sh[4] +\nSH_C2[1]*yz*sh[5] +\nSH_C2[2]*(2.0*zz-xx-yy)*sh[6] +\nSH_C2[3]*xz*sh[7] +\nSH_C2[4]*(xx-yy)*sh[8];\n#if SH_DEGREE>2\nresult+=\nSH_C3[0]*y*(3.0*xx-yy)*sh[9] +\nSH_C3[1]*xy*z*sh[10] +\nSH_C3[2]*y*(4.0*zz-xx-yy)*sh[11] +\nSH_C3[3]*z*(2.0*zz-3.0*xx-3.0*yy)*sh[12] +\nSH_C3[4]*x*(4.0*zz-xx-yy)*sh[13] +\nSH_C3[5]*z*(xx-yy)*sh[14] +\nSH_C3[6]*x*(xx-3.0*yy)*sh[15];\n#endif\n#endif\n#endif\nreturn result;}\nvec4 decompose(uint value)\n{vec4 components=vec4(\nfloat((value ) & 255u),\nfloat((value>>uint( 8)) & 255u),\nfloat((value>>uint(16)) & 255u),\nfloat((value>>uint(24)) & 255u));return components*vec4(2./255.)-vec4(1.);}\nvec3 computeSH(Splat splat,vec3 dir)\n{vec3 sh[16];sh[0]=vec3(0.,0.,0.);\n#if SH_DEGREE>0\nvec4 sh00=decompose(splat.sh0.x);vec4 sh01=decompose(splat.sh0.y);vec4 sh02=decompose(splat.sh0.z);sh[1]=vec3(sh00.x,sh00.y,sh00.z);sh[2]=vec3(sh00.w,sh01.x,sh01.y);sh[3]=vec3(sh01.z,sh01.w,sh02.x);\n#endif\n#if SH_DEGREE>1\nvec4 sh03=decompose(splat.sh0.w);vec4 sh04=decompose(splat.sh1.x);vec4 sh05=decompose(splat.sh1.y);sh[4]=vec3(sh02.y,sh02.z,sh02.w);sh[5]=vec3(sh03.x,sh03.y,sh03.z);sh[6]=vec3(sh03.w,sh04.x,sh04.y);sh[7]=vec3(sh04.z,sh04.w,sh05.x);sh[8]=vec3(sh05.y,sh05.z,sh05.w);\n#endif\n#if SH_DEGREE>2\nvec4 sh06=decompose(splat.sh1.z);vec4 sh07=decompose(splat.sh1.w);vec4 sh08=decompose(splat.sh2.x);vec4 sh09=decompose(splat.sh2.y);vec4 sh10=decompose(splat.sh2.z);vec4 sh11=decompose(splat.sh2.w);sh[9]=vec3(sh06.x,sh06.y,sh06.z);sh[10]=vec3(sh06.w,sh07.x,sh07.y);sh[11]=vec3(sh07.z,sh07.w,sh08.x);sh[12]=vec3(sh08.y,sh08.z,sh08.w);sh[13]=vec3(sh09.x,sh09.y,sh09.z);sh[14]=vec3(sh09.w,sh10.x,sh10.y);sh[15]=vec3(sh10.z,sh10.w,sh11.x); \n#endif\nreturn computeColorFromSHDegree(dir,sh);}\n#else\nvec3 computeSH(Splat splat,vec3 dir)\n{return vec3(0.,0.,0.);}\n#endif\nvec4 gaussianSplatting(vec2 meshPos,vec3 worldPos,vec2 scale,vec3 covA,vec3 covB,mat4 worldMatrix,mat4 viewMatrix,mat4 projectionMatrix)\n{mat4 modelView=viewMatrix*worldMatrix;vec4 camspace=viewMatrix*vec4(worldPos,1.);vec4 pos2d=projectionMatrix*camspace;float bounds=1.2*pos2d.w;if (pos2d.z<-pos2d.w || pos2d.x<-bounds || pos2d.x>bounds\n|| pos2d.y<-bounds || pos2d.y>bounds) {return vec4(0.0,0.0,2.0,1.0);}\nmat3 Vrk=mat3(\ncovA.x,covA.y,covA.z,\ncovA.y,covB.x,covB.y,\ncovA.z,covB.y,covB.z\n);mat3 J=mat3(\nfocal.x/camspace.z,0.,-(focal.x*camspace.x)/(camspace.z*camspace.z),\n0.,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),\n0.,0.,0.\n);mat3 invy=mat3(1,0,0,0,-1,0,0,0,1);mat3 T=invy*transpose(mat3(modelView))*J;mat3 cov2d=transpose(T)*Vrk*T;\n#if COMPENSATION\nfloat c00=cov2d[0][0];float c11=cov2d[1][1];float c01=cov2d[0][1];float detOrig=c00*c11-c01*c01;\n#endif\ncov2d[0][0]+=kernelSize;cov2d[1][1]+=kernelSize;\n#if COMPENSATION\nvec3 c2d=vec3(cov2d[0][0],c01,cov2d[1][1]);float detBlur=c2d.x*c2d.z-c2d.y*c2d.y;float compensation=sqrt(max(0.,detOrig/detBlur));vColor.w*=compensation;\n#endif\nfloat mid=(cov2d[0][0]+cov2d[1][1])/2.0;float radius=length(vec2((cov2d[0][0]-cov2d[1][1])/2.0,cov2d[0][1]));float epsilon=0.0001;float lambda1=mid+radius+epsilon,lambda2=mid-radius+epsilon;if (lambda2<0.0)\n{return vec4(0.0,0.0,2.0,1.0);}\nvec2 diagonalVector=normalize(vec2(cov2d[0][1],lambda1-cov2d[0][0]));vec2 majorAxis=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 minorAxis=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);vec2 vCenter=vec2(pos2d);return vec4(\nvCenter \n+ ((meshPos.x*majorAxis\n+ meshPos.y*minorAxis)*invViewport*pos2d.w)*scale,pos2d.zw);}");const $="gaussianSplattingVertexShader",ee="#include<__decl__gaussianSplattingVertex>\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<logDepthDeclaration>\n#include<helperFunctions>\nattribute float splatIndex;uniform vec2 invViewport;uniform vec2 dataTextureSize;uniform vec2 focal;uniform float kernelSize;uniform vec3 eyePosition;uniform vec3 viewDirectionFactor;uniform sampler2D covariancesATexture;uniform sampler2D covariancesBTexture;uniform sampler2D centersTexture;uniform sampler2D colorsTexture;\n#if SH_DEGREE>0\nuniform highp usampler2D shTexture0;\n#endif\n#if SH_DEGREE>1\nuniform highp usampler2D shTexture1;\n#endif\n#if SH_DEGREE>2\nuniform highp usampler2D shTexture2;\n#endif\nvarying vec4 vColor;varying vec2 vPosition;\n#include<gaussianSplatting>\nvoid main () {Splat splat=readSplat(splatIndex);vec3 covA=splat.covA.xyz;vec3 covB=vec3(splat.covA.w,splat.covB.xy);vec4 worldPos=world*vec4(splat.center.xyz,1.0);vColor=splat.color;vPosition=position;\n#if SH_DEGREE>0\nmat3 worldRot=mat3(world);mat3 normWorldRot=inverseMat3(worldRot);vec3 dir=normalize(normWorldRot*(worldPos.xyz-eyePosition));dir*=viewDirectionFactor;vColor.xyz=splat.color.xyz+computeSH(splat,dir);\n#endif\ngl_Position=gaussianSplatting(position,worldPos.xyz,vec2(1.,1.),covA,covB,world,view,projection);\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<logDepthVertex>\n}\n";e.ShadersStore[$]||(e.ShadersStore[$]=ee);const te={name:$,shader:ee};var se=Object.freeze({__proto__:null,gaussianSplattingVertexShader:te});const ne="gaussianSplattingFragmentDeclaration";e.IncludesShadersStoreWGSL[ne]||(e.IncludesShadersStoreWGSL[ne]="fn gaussianColor(inColor: vec4f,inPosition: vec2f)->vec4f\n{var A : f32=-dot(inPosition,inPosition);if (A>-4.0)\n{var B: f32=exp(A)*inColor.a;\n#include<logDepthFragment>\nvar color: vec3f=inColor.rgb;\n#ifdef FOG\n#include<fogFragment>\n#endif\nreturn vec4f(color,B);} else {return vec4f(0.0);}}\n");const re="gaussianSplattingPixelShader",ie="#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvarying vColor: vec4f;varying vPosition: vec2f;\n#include<gaussianSplattingFragmentDeclaration>\n@fragment\nfn main(input: FragmentInputs)->FragmentOutputs {\n#include<clipPlaneFragment>\nfragmentOutputs.color=gaussianColor(input.vColor,input.vPosition);}\n";e.ShadersStoreWGSL[re]||(e.ShadersStoreWGSL[re]=ie);const oe={name:re,shader:ie};var ae=Object.freeze({__proto__:null,gaussianSplattingPixelShaderWGSL:oe});const ce="gaussianSplatting";e.IncludesShadersStoreWGSL[ce]||(e.IncludesShadersStoreWGSL[ce]="fn getDataUV(index: f32,dataTextureSize: vec2f)->vec2<f32> {let y: f32=floor(index/dataTextureSize.x);let x: f32=index-y*dataTextureSize.x;return vec2f((x+0.5),(y+0.5));}\nstruct Splat {center: vec4f,\ncolor: vec4f,\ncovA: vec4f,\ncovB: vec4f,\n#if SH_DEGREE>0\nsh0: vec4<u32>,\n#endif\n#if SH_DEGREE>1\nsh1: vec4<u32>,\n#endif\n#if SH_DEGREE>2\nsh2: vec4<u32>,\n#endif\n};fn readSplat(splatIndex: f32,dataTextureSize: vec2f)->Splat {var splat: Splat;let splatUV=getDataUV(splatIndex,dataTextureSize);let splatUVi32=vec2<i32>(i32(splatUV.x),i32(splatUV.y));splat.center=textureLoad(centersTexture,splatUVi32,0);splat.color=textureLoad(colorsTexture,splatUVi32,0);splat.covA=textureLoad(covariancesATexture,splatUVi32,0)*splat.center.w;splat.covB=textureLoad(covariancesBTexture,splatUVi32,0)*splat.center.w;\n#if SH_DEGREE>0\nsplat.sh0=textureLoad(shTexture0,splatUVi32,0);\n#endif\n#if SH_DEGREE>1\nsplat.sh1=textureLoad(shTexture1,splatUVi32,0);\n#endif\n#if SH_DEGREE>2\nsplat.sh2=textureLoad(shTexture2,splatUVi32,0);\n#endif\nreturn splat;}\nfn computeColorFromSHDegree(dir: vec3f,sh: array<vec3<f32>,16>)->vec3f\n{let SH_C0: f32=0.28209479;let SH_C1: f32=0.48860251;var SH_C2: array<f32,5>=array<f32,5>(\n1.092548430,\n-1.09254843,\n0.315391565,\n-1.09254843,\n0.546274215\n);var SH_C3: array<f32,7>=array<f32,7>(\n-0.59004358,\n2.890611442,\n-0.45704579,\n0.373176332,\n-0.45704579,\n1.445305721,\n-0.59004358\n);var result: vec3f=/*SH_C0**/sh[0];\n#if SH_DEGREE>0\nlet x: f32=dir.x;let y: f32=dir.y;let z: f32=dir.z;result+=-SH_C1*y*sh[1]+SH_C1*z*sh[2]-SH_C1*x*sh[3];\n#if SH_DEGREE>1\nlet xx: f32=x*x;let yy: f32=y*y;let zz: f32=z*z;let xy: f32=x*y;let yz: f32=y*z;let xz: f32=x*z;result+=\nSH_C2[0]*xy*sh[4] +\nSH_C2[1]*yz*sh[5] +\nSH_C2[2]*(2.0f*zz-xx-yy)*sh[6] +\nSH_C2[3]*xz*sh[7] +\nSH_C2[4]*(xx-yy)*sh[8];\n#if SH_DEGREE>2\nresult+=\nSH_C3[0]*y*(3.0f*xx-yy)*sh[9] +\nSH_C3[1]*xy*z*sh[10] +\nSH_C3[2]*y*(4.0f*zz-xx-yy)*sh[11] +\nSH_C3[3]*z*(2.0f*zz-3.0f*xx-3.0f*yy)*sh[12] +\nSH_C3[4]*x*(4.0f*zz-xx-yy)*sh[13] +\nSH_C3[5]*z*(xx-yy)*sh[14] +\nSH_C3[6]*x*(xx-3.0f*yy)*sh[15];\n#endif\n#endif\n#endif\nreturn result;}\nfn decompose(value: u32)->vec4f\n{let components : vec4f=vec4f(\nf32((value ) & 255u),\nf32((value>>u32( 8)) & 255u),\nf32((value>>u32(16)) & 255u),\nf32((value>>u32(24)) & 255u));return components*vec4f(2./255.)-vec4f(1.);}\nfn computeSH(splat: Splat,dir: vec3f)->vec3f\n{var sh: array<vec3<f32>,16>;sh[0]=vec3f(0.,0.,0.);\n#if SH_DEGREE>0\nlet sh00: vec4f=decompose(splat.sh0.x);let sh01: vec4f=decompose(splat.sh0.y);let sh02: vec4f=decompose(splat.sh0.z);sh[1]=vec3f(sh00.x,sh00.y,sh00.z);sh[2]=vec3f(sh00.w,sh01.x,sh01.y);sh[3]=vec3f(sh01.z,sh01.w,sh02.x);\n#endif\n#if SH_DEGREE>1\nlet sh03: vec4f=decompose(splat.sh0.w);let sh04: vec4f=decompose(splat.sh1.x);let sh05: vec4f=decompose(splat.sh1.y);sh[4]=vec3f(sh02.y,sh02.z,sh02.w);sh[5]=vec3f(sh03.x,sh03.y,sh03.z);sh[6]=vec3f(sh03.w,sh04.x,sh04.y);sh[7]=vec3f(sh04.z,sh04.w,sh05.x);sh[8]=vec3f(sh05.y,sh05.z,sh05.w);\n#endif\n#if SH_DEGREE>2\nlet sh06: vec4f=decompose(splat.sh1.z);let sh07: vec4f=decompose(splat.sh1.w);let sh08: vec4f=decompose(splat.sh2.x);let sh09: vec4f=decompose(splat.sh2.y);let sh10: vec4f=decompose(splat.sh2.z);let sh11: vec4f=decompose(splat.sh2.w);sh[9]=vec3f(sh06.x,sh06.y,sh06.z);sh[10]=vec3f(sh06.w,sh07.x,sh07.y);sh[11]=vec3f(sh07.z,sh07.w,sh08.x);sh[12]=vec3f(sh08.y,sh08.z,sh08.w);sh[13]=vec3f(sh09.x,sh09.y,sh09.z);sh[14]=vec3f(sh09.w,sh10.x,sh10.y);sh[15]=vec3f(sh10.z,sh10.w,sh11.x); \n#endif\nreturn computeColorFromSHDegree(dir,sh);}\nfn gaussianSplatting(\nmeshPos: vec2<f32>,\nworldPos: vec3<f32>,\nscale: vec2<f32>,\ncovA: vec3<f32>,\ncovB: vec3<f32>,\nworldMatrix: mat4x4<f32>,\nviewMatrix: mat4x4<f32>,\nprojectionMatrix: mat4x4<f32>,\nfocal: vec2f,\ninvViewport: vec2f,\nkernelSize: f32\n)->vec4f {let modelView=viewMatrix*worldMatrix;let camspace=viewMatrix*vec4f(worldPos,1.0);let pos2d=projectionMatrix*camspace;let bounds=1.2*pos2d.w;if (pos2d.z<0. || pos2d.x<-bounds || pos2d.x>bounds || pos2d.y<-bounds || pos2d.y>bounds) {return vec4f(0.0,0.0,2.0,1.0);}\nlet Vrk=mat3x3<f32>(\ncovA.x,covA.y,covA.z,\ncovA.y,covB.x,covB.y,\ncovA.z,covB.y,covB.z\n);let J=mat3x3<f32>(\nfocal.x/camspace.z,0.0,-(focal.x*camspace.x)/(camspace.z*camspace.z),\n0.0,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),\n0.0,0.0,0.0\n);let invy=mat3x3<f32>(\n1.0,0.0,0.0,\n0.0,-1.0,0.0,\n0.0,0.0,1.0\n);let T=invy*transpose(mat3x3<f32>(\nmodelView[0].xyz,\nmodelView[1].xyz,\nmodelView[2].xyz))*J;var cov2d=transpose(T)*Vrk*T;\n#if COMPENSATION\nlet c00: f32=cov2d[0][0];let c11: f32=cov2d[1][1];let c01: f32=cov2d[0][1];let detOrig: f32=c00*c11-c01*c01;\n#endif\ncov2d[0][0]+=kernelSize;cov2d[1][1]+=kernelSize;\n#if COMPENSATION\nlet c2d: vec3f=vec3f(cov2d[0][0],c01,cov2d[1][1]);let detBlur: f32=c2d.x*c2d.z-c2d.y*c2d.y;let compensation: f32=sqrt(max(0.,detOrig/detBlur));vertexOutputs.vColor.w*=compensation;\n#endif\nlet mid=(cov2d[0][0]+cov2d[1][1])/2.0;let radius=length(vec2<f32>((cov2d[0][0]-cov2d[1][1])/2.0,cov2d[0][1]));let lambda1=mid+radius;let lambda2=mid-radius;if (lambda2<0.0) {return vec4f(0.0,0.0,2.0,1.0);}\nlet diagonalVector=normalize(vec2<f32>(cov2d[0][1],lambda1-cov2d[0][0]));let majorAxis=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;let minorAxis=min(sqrt(2.0*lambda2),1024.0)*vec2<f32>(diagonalVector.y,-diagonalVector.x);let vCenter=vec2<f32>(pos2d.x,pos2d.y);return vec4f(\nvCenter+((meshPos.x*majorAxis+meshPos.y*minorAxis)*invViewport*pos2d.w)*scale,\npos2d.z,\npos2d.w\n);}\n");const le="gaussianSplattingVertexShader",ue="#include<sceneUboDeclaration>\n#include<meshUboDeclaration>\n#include<helperFunctions>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<logDepthDeclaration>\nattribute splatIndex: f32;attribute position: vec2f;uniform invViewport: vec2f;uniform dataTextureSize: vec2f;uniform focal: vec2f;uniform kernelSize: f32;uniform eyePosition: vec3f;uniform viewDirectionFactor: vec3f;var covariancesATexture: texture_2d<f32>;var covariancesBTexture: texture_2d<f32>;var centersTexture: texture_2d<f32>;var colorsTexture: texture_2d<f32>;\n#if SH_DEGREE>0\nvar shTexture0: texture_2d<u32>;\n#endif\n#if SH_DEGREE>1\nvar shTexture1: texture_2d<u32>;\n#endif\n#if SH_DEGREE>2\nvar shTexture2: texture_2d<u32>;\n#endif\nvarying vColor: vec4f;varying vPosition: vec2f;\n#include<gaussianSplatting>\n@vertex\nfn main(input : VertexInputs)->FragmentInputs {var splat: Splat=readSplat(input.splatIndex,uniforms.dataTextureSize);var covA: vec3f=splat.covA.xyz;var covB: vec3f=vec3f(splat.covA.w,splat.covB.xy);let worldPos: vec4f=mesh.world*vec4f(splat.center.xyz,1.0);vertexOutputs.vPosition=input.position;\n#if SH_DEGREE>0\nlet worldRot: mat3x3f= mat3x3f(mesh.world[0].xyz,mesh.world[1].xyz,mesh.world[2].xyz);let normWorldRot: mat3x3f=inverseMat3(worldRot);var dir: vec3f=normalize(normWorldRot*(worldPos.xyz-uniforms.eyePosition.xyz));dir*=viewDirectionFactor;vertexOutputs.vColor=vec4f(splat.color.xyz+computeSH(splat,dir),splat.color.w);\n#else\nvertexOutputs.vColor=splat.color;\n#endif\nvertexOutputs.position=gaussianSplatting(input.position,worldPos.xyz,vec2f(1.0,1.0),covA,covB,mesh.world,scene.view,scene.projection,uniforms.focal,uniforms.invViewport,uniforms.kernelSize);\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<logDepthVertex>\n}\n";e.ShadersStoreWGSL[le]||(e.ShadersStoreWGSL[le]=ue);const he={name:le,shader:ue};var _e=Object.freeze({__proto__:null,gaussianSplattingVertexShaderWGSL:he});class de extends p{constructor(){super(),this.FOG=!1,this.THIN_INSTANCES=!0,this.LOGARITHMICDEPTH=!1,this.CLIPPLANE=!1,this.CLIPPLANE2=!1,this.CLIPPLANE3=!1,this.CLIPPLANE4=!1,this.CLIPPLANE5=!1,this.CLIPPLANE6=!1,this.SH_DEGREE=0,this.COMPENSATION=!1,this.rebuild()}}class pe extends t{constructor(e,t){super(e,t),this.kernelSize=pe.KernelSize,this._compensation=pe.Compensation,this._isDirty=!1,this.backFaceCulling=!1}set compensation(e){this._isDirty=this._isDirty!=e,this._compensation=e}get compensation(){return this._compensation}get hasRenderTargetTextures(){return!1}needAlphaTesting(){return!1}needAlphaBlending(){return!0}isReadyForSubMesh(e,t){const l=!0,u=t._drawWrapper;let h=t.materialDefines;if(h&&this._isDirty&&h.markAsUnprocessed(),u.effect&&this.isFrozen&&u._wasPreviouslyReady&&u._wasPreviouslyUsingInstances===l)return!0;t.materialDefines||(h=t.materialDefines=new de);const _=this.getScene();if(this._isReadyForSubMesh(t))return!0;const d=_.getEngine(),p=e;s(e,_,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,!1,h),n(_,d,this,h,l,null,!0),r(e,h,!1,!1),(d.version>1||d.isWebGPU)&&(h.SH_DEGREE=p.shDegree);const f=p.material;if(h.COMPENSATION=f&&f.compensation?f.compensation:pe.Compensation,h.isDirty){h.markAsProcessed(),_.resetCachedMaterial();const e=[o.PositionKind,"splatIndex"];i(e,h);const s=["world","view","projection","vFogInfos","vFogColor","logarithmicDepthConstant","invViewport","dataTextureSize","focal","eyePosition","kernelSize","viewDirectionFactor"],n=["covariancesATexture","covariancesBTexture","centersTexture","colorsTexture","shTexture0","shTexture1","shTexture2"],r=["Scene","Mesh"];a({uniformsNames:s,uniformBuffersNames:r,samplers:n,defines:h}),c(s);const l=h.toString(),u=_.getEngine().createEffect("gaussianSplatting",{attributes:e,uniformsNames:s,uniformBuffersNames:r,samplers:n,defines:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{},shaderLanguage:this._shaderLanguage,extraInitializationsAsync:async()=>{1===this._shaderLanguage?await Promise.all([Promise.resolve().then((function(){return ae})),Promise.resolve().then((function(){return _e}))]):await Promise.all([Promise.resolve().then((function(){return K})),Promise.resolve().then((function(){return se}))])}},d);t.setEffect(u,h,this._materialContext)}return!(!t.effect||!t.effect.isReady())&&(h._renderId=_.getRenderId(),u._wasPreviouslyReady=!0,u._wasPreviouslyUsingInstances=l,this._isDirty=!1,!0)}static BindEffect(e,t,s){const n=s.getEngine(),r=s.activeCamera,i=n.getRenderWidth(),o=n.getRenderHeight(),a=e,c=a.material,u=r?.rigParent?.rigCameras.length||1;t.setFloat2("invViewport",1/(i/u),1/o);let h=1e3;if(r){const e=r.getProjectionMatrix().m[5];h=r.fovMode==l.FOVMODE_VERTICAL_FIXED?o*e/2:i*e/2}if(t.setFloat2("focal",h,h),t.setVector3("viewDirectionFactor",a.viewDirectionFactor),t.setFloat("kernelSize",c&&c.kernelSize?c.kernelSize:pe.KernelSize),s.bindEyePosition(t,"eyePosition",!0),a.covariancesATexture){const e=a.covariancesATexture.getSize();if(t.setFloat2("dataTextureSize",e.width,e.height),t.setTexture("covariancesATexture",a.covariancesATexture),t.setTexture("covariancesBTexture",a.covariancesBTexture),t.setTexture("centersTexture",a.centersTexture),t.setTexture("colorsTexture",a.colorsTexture),a.shTextures)for(let e=0;e<a.shTextures?.length;e++)t.setTexture(`shTexture${e}`,a.shTextures[e])}}bindForSubMesh(e,t,s){const n=this.getScene(),r=s.materialDefines;if(!r)return;const i=s.effect;if(!i)return;this._activeEffect=i,t.getMeshUniformBuffer().bindToEffect(i,"Mesh"),t.transferToEffect(e);this._mustRebind(n,i,s,t.visibility)?(this.bindView(i),this.bindViewProjection(i),pe.BindEffect(t,this._activeEffect,n),u(i,this,n)):n.getEngine()._features.needToAlwaysBindUniformBuffers&&(this._needToBindSceneUbo=!0),h(n,t,i),this.useLogarithmicDepth&&_(r,i,n),this._afterBind(t,this._activeEffect,s)}clone(e){return d.Clone((()=>new pe(e,this.getScene())),this)}serialize(){const e=super.serialize();return e.customType="BABYLON.GaussianSplattingMaterial",e}getClassName(){return"GaussianSplattingMaterial"}static Parse(e,t,s){return d.Parse((()=>new pe(e.name,t)),e,t,s)}}pe.KernelSize=.3,pe.Compensation=!1,f("BABYLON.GaussianSplattingMaterial",pe);const fe=x,me={...m,TwoPi:2*Math.PI,Sign:Math.sign,Log2:Math.log2,HCF:fe},xe=(e,t)=>{const s=(1<<t)-1;return(e&s)/s},ve=(e,t)=>{t.x=xe(e>>>21,11),t.y=xe(e>>>11,10),t.z=xe(e,11)},Se=(e,t)=>{t[0]=255*xe(e>>>24,8),t[1]=255*xe(e>>>16,8),t[2]=255*xe(e>>>8,8),t[3]=255*xe(e,8)},ye=(e,t)=>{const s=1/(.5*Math.sqrt(2)),n=(xe(e>>>20,10)-.5)*s,r=(xe(e>>>10,10)-.5)*s,i=(xe(e,10)-.5)*s,o=Math.sqrt(1-(n*n+r*r+i*i));switch(e>>>30){case 0:t.set(o,n,r,i);break;case 1:t.set(n,o,r,i);break;case 2:t.set(n,r,o,i);break;case 3:t.set(n,r,i,o)}};var ge,Ce,we,Te;!function(e){e[e.FLOAT=0]="FLOAT",e[e.INT=1]="INT",e[e.UINT=2]="UINT",e[e.DOUBLE=3]="DOUBLE",e[e.UCHAR=4]="UCHAR",e[e.UNDEFINED=5]="UNDEFINED"}(ge||(ge={})),function(e){e[e.MIN_X=0]="MIN_X",e[e.MIN_Y=1]="MIN_Y",e[e.MIN_Z=2]="MIN_Z",e[e.MAX_X=3]="MAX_X",e[e.MAX_Y=4]="MAX_Y",e[e.MAX_Z=5]="MAX_Z",e[e.MIN_SCALE_X=6]="MIN_SCALE_X",e[e.MIN_SCALE_Y=7]="MIN_SCALE_Y",e[e.MIN_SCALE_Z=8]="MIN_SCALE_Z",e[e.MAX_SCALE_X=9]="MAX_SCALE_X",e[e.MAX_SCALE_Y=10]="MAX_SCALE_Y",e[e.MAX_SCALE_Z=11]="MAX_SCALE_Z",e[e.PACKED_POSITION=12]="PACKED_POSITION",e[e.PACKED_ROTATION=13]="PACKED_ROTATION",e[e.PACKED_SCALE=14]="PACKED_SCALE",e[e.PACKED_COLOR=15]="PACKED_COLOR",e[e.X=16]="X",e[e.Y=17]="Y",e[e.Z=18]="Z",e[e.SCALE_0=19]="SCALE_0",e[e.SCALE_1=20]="SCALE_1",e[e.SCALE_2=21]="SCALE_2",e[e.DIFFUSE_RED=22]="DIFFUSE_RED",e[e.DIFFUSE_GREEN=23]="DIFFUSE_GREEN",e[e.DIFFUSE_BLUE=24]="DIFFUSE_BLUE",e[e.OPACITY=25]="OPACITY",e[e.F_DC_0=26]="F_DC_0",e[e.F_DC_1=27]="F_DC_1",e[e.F_DC_2=28]="F_DC_2",e[e.F_DC_3=29]="F_DC_3",e[e.ROT_0=30]="ROT_0",e[e.ROT_1=31]="ROT_1",e[e.ROT_2=32]="ROT_2",e[e.ROT_3=33]="ROT_3",e[e.MIN_COLOR_R=34]="MIN_COLOR_R",e[e.MIN_COLOR_G=35]="MIN_COLOR_G",e[e.MIN_COLOR_B=36]="MIN_COLOR_B",e[e.MAX_COLOR_R=37]="MAX_COLOR_R",e[e.MAX_COLOR_G=38]="MAX_COLOR_G",e[e.MAX_COLOR_B=39]="MAX_COLOR_B",e[e.SH_0=40]="SH_0",e[e.SH_1=41]="SH_1",e[e.SH_2=42]="SH_2",e[e.SH_3=43]="SH_3",e[e.SH_4=44]="SH_4",e[e.SH_5=45]="SH_5",e[e.SH_6=46]="SH_6",e[e.SH_7=47]="SH_7",e[e.SH_8=48]="SH_8",e[e.SH_9=49]="SH_9",e[e.SH_10=50]="SH_10",e[e.SH_11=51]="SH_11",e[e.SH_12=52]="SH_12",e[e.SH_13=53]="SH_13",e[e.SH_14=54]="SH_14",e[e.SH_15=55]="SH_15",e[e.SH_16=56]="SH_16",e[e.SH_17=57]="SH_17",e[e.SH_18=58]="SH_18",e[e.SH_19=59]="SH_19",e[e.SH_20=60]="SH_20",e[e.SH_21=61]="SH_21",e[e.SH_22=62]="SH_22",e[e.SH_23=63]="SH_23",e[e.SH_24=64]="SH_24",e[e.SH_25=65]="SH_25",e[e.SH_26=66]="SH_26",e[e.SH_27=67]="SH_27",e[e.SH_28=68]="SH_28",e[e.SH_29=69]="SH_29",e[e.SH_30=70]="SH_30",e[e.SH_31=71]="SH_31",e[e.SH_32=72]="SH_32",e[e.SH_33=73]="SH_33",e[e.SH_34=74]="SH_34",e[e.SH_35=75]="SH_35",e[e.SH_36=76]="SH_36",e[e.SH_37=77]="SH_37",e[e.SH_38=78]="SH_38",e[e.SH_39=79]="SH_39",e[e.SH_40=80]="SH_40",e[e.SH_41=81]="SH_41",e[e.SH_42=82]="SH_42",e[e.SH_43=83]="SH_43",e[e.SH_44=84]="SH_44",e[e.UNDEFINED=85]="UNDEFINED"}(Ce||(Ce={}));class Ee extends v{get viewDirectionFactor(){return this._viewDirectionFactor}get shDegree(){return this._shDegree}get splatsData(){return this._splatsData}get covariancesATexture(){return this._covariancesATexture}get covariancesBTexture(){return this._covariancesBTexture}get centersTexture(){return this._centersTexture}get colorsTexture(){return this._colorsTexture}get shTextures(){return this._shTextures}set material(e){this._material=e,this._material.backFaceCulling=!0,this._material.cullBackFaces=!1,e.resetDrawCache()}get material(){return this._material}constructor(e,t=null,s=null,n=!1){super(e,s),this._vertexCount=0,this._worker=null,this._frameIdLastUpdate=-1,this._modelViewMatrix=S.Identity(),this._canPostToWorker=!0,this._readyToDisplay=!1,this._covariancesATexture=null,this._covariancesBTexture=null,this._centersTexture=null,this._colorsTexture=null,this._splatPositions=null,this._splatIndex=null,this._shTextures=null,this._splatsData=null,this._sh=null,this._keepInRam=!1,this._delayedTextureUpdate=null,this._oldDirection=new y,this._useRGBACovariants=!1,this._material=null,this._tmpCovariances=[0,0,0,0,0,0],this._sortIsDirty=!1,this._shDegree=0,this._viewDirectionFactor=new y(1,1,-1);const r=new g;r.positions=[-3,-2,0,3,-2,0,0,4,0],r.indices=[0,1,2],r.applyToMesh(this),this.subMeshes=[],new C(0,0,3,0,3,this),this.setEnabled(!1),this._useRGBACovariants=!this.getEngine().isWebGPU&&1===this.getEngine().version,this._keepInRam=n,t&&this.loadFileAsync(t),this._material=new pe(this.name+"_material",this._scene)}getClassName(){return"GaussianSplattingMesh"}getTotalVertices(){return this._vertexCount}isReady(e=!1){return!!super.isReady(e,!0)&&(!!this._readyToDisplay||(this._postToWorker(!0),!1))}_postToWorker(e=!1){const t=this.getScene().getFrameId();if((e||t!==this._frameIdLastUpdate)&&this._worker&&this._scene.activeCamera&&this._canPostToWorker){const s=this._scene.activeCamera.getViewMatrix();this.getWorldMatrix().multiplyToRef(s,this._modelViewMatrix),s.invertToRef(w.Matrix[0]),this.getWorldMatrix().multiplyToRef(w.Matrix[0],w.Matrix[1]),y.TransformNormalToRef(y.Forward(this._scene.useRightHandedSystem),w.Matrix[1],w.Vector3[2]),w.Vector3[2].normalize();const n=y.Dot(w.Vector3[2],this._oldDirection);(e||Math.abs(n-1)>=.01)&&(this._oldDirection.copyFrom(w.Vector3[2]),this._frameIdLastUpdate=t,this._canPostToWorker=!1,this._worker.postMessage({view:this._modelViewMatrix.m,depthMix:this._depthMix,useRightHandedSystem:this._scene.useRightHandedSystem},[this._depthMix.buffer]))}}render(e,t,s){return this._postToWorker(),super.render(e,t,s)}static _TypeNameToEnum(e){switch(e){case"float":return 0;case"int":return 1;case"uint":return 2;case"double":return 3;case"uchar":return 4}return 5}static _ValueNameToEnum(e){switch(e){case"min_x":return 0;case"min_y":return 1;case"min_z":return 2;case"max_x":return 3;case"max_y":return 4;case"max_z":return 5;case"min_scale_x":return 6;case"min_scale_y":return 7;case"min_scale_z":return 8;case"max_scale_x":return 9;case"max_scale_y":return 10;case"max_scale_z":return 11;case"packed_position":return 12;case"packed_rotation":return 13;case"packed_scale":return 14;case"packed_color":return 15;case"x":return 16;case"y":return 17;case"z":return 18;case"scale_0":return 19;case"scale_1":return 20;case"scale_2":return 21;case"diffuse_red":case"red":return 22;case"diffuse_green":case"green":return 23;case"diffuse_blue":case"blue":return 24;case"f_dc_0":return 26;case"f_dc_1":return 27;case"f_dc_2":return 28;case"f_dc_3":return 29;case"opacity":return 25;case"rot_0":return 30;case"rot_1":return 31;case"rot_2":return 32;case"rot_3":return 33;case"min_r":return 34;case"min_g":return 35;case"min_b":return 36;case"max_r":return 37;case"max_g":return 38;case"max_b":return 39;case"f_rest_0":return 40;case"f_rest_1":return 41;case"f_rest_2":return 42;case"f_rest_3":return 43;case"f_rest_4":return 44;case"f_rest_5":return 45;case"f_rest_6":return 46;case"f_rest_7":return 47;case"f_rest_8":return 48;case"f_rest_9":return 49;case"f_rest_10":return 50;case"f_rest_11":return 51;case"f_rest_12":return 52;case"f_rest_13":return 53;case"f_rest_14":return 54;case"f_rest_15":return 55;case"f_rest_16":return 56;case"f_rest_17":return 57;case"f_rest_18":return 58;case"f_rest_19":return 59;case"f_rest_20":return 60;case"f_rest_21":return 61;case"f_rest_22":return 62;case"f_rest_23":return 63;case"f_rest_24":return 64;case"f_rest_25":return 65;case"f_rest_26":return 66;case"f_rest_27":return 67;case"f_rest_28":return 68;case"f_rest_29":return 69;case"f_rest_30":return 70;case"f_rest_31":return 71;case"f_rest_32":return 72;case"f_rest_33":return 73;case"f_rest_34":return 74;case"f_rest_35":return 75;case"f_rest_36":return 76;case"f_rest_37":return 77;case"f_rest_38":return 78;case"f_rest_39":return 79;case"f_rest_40":return 80;case"f_rest_41":return 81;case"f_rest_42":return 82;case"f_rest_43":return 83;case"f_rest_44":return 84}return 85}static ParseHeader(e){const t=new Uint8Array(e),s=(new TextDecoder).decode(t.slice(0,10240)),n="end_header\n",r=s.indexOf(n);if(r<0||!s)return null;const i=parseInt(/element vertex (\d+)\n/.exec(s)[1]),o=/element chunk (\d+)\n/.exec(s);let a=0;o&&(a=parseInt(o[1]));let c=0,l=0;const u={double:8,int:4,uint:4,float:4,short:2,ushort:2,uchar:1,list:0};let h;!function(e){e[e.Vertex=0]="Vertex",e[e.Chunk=1]="Chunk",e[e.SH=2]="SH"}(h||(h={}));let _=1;const d=[],p=[],f=s.slice(0,r).split("\n");let m=0;for(const e of f)if(e.startsWith("property ")){const[,t,s]=e.split(" "),n=Ee._ValueNameToEnum(s);n>=84?m=3:n>=64?m=2:n>=48&&(m=1);const r=Ee._TypeNameToEnum(t);1==_?(p.push({value:n,type:r,offset:l}),l+=u[t]):0==_?(d.push({value:n,type:r,offset:c}),c+=u[t]):2==_&&d.push({value:n,type:r,offset:c}),u[t]||T.Warn(`Unsupported property type: ${t}.`)}else if(e.startsWith("element ")){const[,t]=e.split(" ");"chunk"==t?_=1:"vertex"==t?_=0:"sh"==t&&(_=2)}const x=new DataView(e,r+11),v=new ArrayBuffer(Ee._RowOutputLength*i);let S=null,y=0;if(m){y=3*((m+1)*(m+1)-1),S=new ArrayBuffer(y*i)}return{vertexCount:i,chunkCount:a,rowVertexLength:c,rowChunkLength:l,vertexProperties:d,chunkProperties:p,dataView:x,buffer:v,shDegree:m,shCoefficientCount:y,shBuffer:S}}static _GetCompressedChunks(e,t){if(!e.chunkCount)return null;const s=e.dataView,n=new Array(e.chunkCount);for(let r=0;r<e.chunkCount;r++){const i={min:new y,max:new y,minScale:new y,maxScale:new y,minColor:new y(0,0,0),maxColor:new y(1,1,1)};n[r]=i;for(let n=0;n<e.chunkProperties.length;n++){const r=e.chunkProperties[n];let o;if(0===r.type)switch(o=s.getFloat32(r.offset+t.value,!0),r.value){case 0:i.min.x=o;break;case 1:i.min.y=o;break;case 2:i.min.z=o;break;case 3:i.max.x=o;break;case 4:i.max.y=o;break;case 5:i.max.z=o;break;case 6:i.minScale.x=o;break;case 7:i.minScale.y=o;break;case 8:i.minScale.z=o;break;case 9:i.maxScale.x=o;break;case 10:i.maxScale.y=o;break;case 11:i.maxScale.z=o;break;case 34:i.minColor.x=o;break;case 35:i.minColor.y=o;break;case 36:i.minColor.z=o;break;case 37:i.maxColor.x=o;break;case 38:i.maxColor.y=o;break;case 39:i.maxColor.z=o}}t.value+=e.rowChunkLength}return n}static _GetSplat(e,t,s,n){const r=w.Quaternion[0],i=w.Vector3[0],o=Ee._RowOutputLength,a=e.buffer,c=e.dataView,l=new Float32Array(a,t*o,3),u=new Float32Array(a,t*o+12,3),h=new Uint8ClampedArray(a,t*o+24,4),_=new Uint8ClampedArray(a,t*o+28,4);let d=null;e.shBuffer&&(d=new Uint8ClampedArray(e.shBuffer,t*e.shCoefficientCount,e.shCoefficientCount));const p=t>>8;let f=255,m=0,x=0,v=0;const S=[];for(let o=0;o<e.vertexProperties.length;o++){const a=e.vertexProperties[o];let _;switch(a.type){case 0:_=c.getFloat32(n.value+a.offset,!0);break;case 1:_=c.getInt32(n.value+a.offset,!0);break;case 2:_=c.getUint32(n.value+a.offset,!0);break;case 3:_=c.getFloat64(n.value+a.offset,!0);break;case 4:_=c.getUint8(n.value+a.offset);break;default:continue}switch(a.value){case 12:{const e=s[p];ve(_,i),l[0]=me.Lerp(e.min.x,e.max.x,i.x),l[1]=me.Lerp(e.min.y,e.max.y,i.y),l[2]=me.Lerp(e.min.z,e.max.z,i.z)}break;case 13:ye(_,r),f=r.x,m=r.y,x=r.z,v=r.w;break;case 14:{const e=s[p];ve(_,i),u[0]=Math.exp(me.Lerp(e.minScale.x,e.maxScale.x,i.x)),u[1]=Math.exp(me.Lerp(e.minScale.y,e.maxScale.y,i.y)),u[2]=Math.exp(me.Lerp(e.minScale.z,e.maxScale.z,i.z))}break;case 15:{const e=s[p];Se(_,h),h[0]=255*me.Lerp(e.minColor.x,e.maxColor.x,h[0]/255),h[1]=255*me.Lerp(e.minColor.y,e.maxColor.y,h[1]/255),h[2]=255*me.Lerp(e.minColor.z,e.maxColor.z,h[2]/255)}break;case 16:l[0]=_;break;case 17:l[1]=-_;break;case 18:l[2]=-_;break;case 19:u[0]=Math.exp(_);break;case 20:u[1]=Math.exp(_);break;case 21:u[2]=Math.exp(_);break;case 22:h[0]=_;break;case 23:h[1]=_;break;case 24:h[2]=_;break;case 26:h[0]=255*(.5+Ee._SH_C0*_);break;case 27:h[1]=255*(.5+Ee._SH_C0*_);break;case 28:h[2]=255*(.5+Ee._SH_C0*_);break;case 29:h[3]=255*(.5+Ee._SH_C0*_);break;case 25:h[3]=1/(1+Math.exp(-_))*255;break;case 30:f=_;break;case 31:m=_;break;case 32:x=-_;break;case 33:v=-_}if(d&&a.value>=40&&a.value<=84){const s=a.value-40;if(4==a.type&&e.chunkCount){const n=c.getUint8(e.rowChunkLength*e.chunkCount+e.vertexCount*e.rowVertexLength+t*e.shCoefficientCount+s);S[s]=127.5*(n*(8/255)-4)+127.5}else{const e=me.Clamp(127.5*_+127.5,0,255);S[s]=e}}}if(d){const t=1==e.shDegree?3:2==e.shDegree?8:15;for(let e=0;e<t;e++)d[3*e+0]=S[e],d[3*e+1]=S[e+t],d[3*e+2]=S[e+2*t]}r.set(m,x,v,f),r.normalize(),_[0]=127.5*r.w+127.5,_[1]=127.5*r.x+127.5,_[2]=127.5*r.y+127.5,_[3]=127.5*r.z+127.5,n.value+=e.rowVertexLength}static*ConvertPLYWithSHToSplat(e,t=!1){const s=Ee.ParseHeader(e);if(!s)return{buffer:e};const n={value:0},r=Ee._GetCompressedChunks(s,n);for(let e=0;e<s.vertexCount;e++)Ee._GetSplat(s,e,r,n),e%Ee._PlyConversionBatchSize===0&&t&&(yield);let i=null;if(s.shDegree&&s.shBuffer){const e=Math.ceil(s.shCoefficientCount/16);let t=0;const n=new Uint8Array(s.shBuffer);i=[];const r=s.vertexCount,o=E.LastCreatedEngine;if(o){const a=o.getCaps().maxTextureSize,c=Math.ceil(r/a);for(let t=0;t<e;t++){const e=new Uint8Array(c*a*4*4);i.push(e)}for(let e=0;e<r;e++)for(let r=0;r<s.shCoefficientCount;r++){const s=n[t++];i[Math.floor(r/16)][r%16+16*e]=s}}}return{buffer:s.buffer,sh:i}}static*ConvertPLYToSplat(e,t=!1){const s=Ee.ParseHeader(e);if(!s)return e;const n={value:0},r=Ee._GetCompressedChunks(s,n);for(let e=0;e<s.vertexCount;e++)Ee._GetSplat(s,e,r,n),e%Ee._PlyConversionBatchSize===0&&t&&(yield);return s.buffer}static async ConvertPLYToSplatAsync(e){return await A(Ee.ConvertPLYToSplat(e,!0),P())}static async ConvertPLYWithSHToSplatAsync(e){return await A(Ee.ConvertPLYWithSHToSplat(e,!0),P())}async loadDataAsync(e){return await this.updateDataAsync(e)}async loadFileAsync(e){const t=await z.LoadFileAsync(e,!0),s=await Ee.ConvertPLYWithSHToSplatAsync(t);await this.updateDataAsync(s.buffer,s.sh)}dispose(e){if(this._covariancesATexture?.dispose(),this._covariancesBTexture?.dispose(),this._centersTexture?.dispose(),this._colorsTexture?.dispose(),this._shTextures)for(const e of this._shTextures)e.dispose();this._covariancesATexture=null,this._covariancesBTexture=null,this._centersTexture=null,this._colorsTexture=null,this._shTextures=null,this._worker?.terminate(),this._worker=null,super.dispose(e,!0)}_copyTextures(e){if(this._covariancesATexture=e.covariancesATexture?.clone(),this._covariancesBTexture=e.covariancesBTexture?.clone(),this._centersTexture=e.centersTexture?.clone(),this._colorsTexture=e.colorsTexture?.clone(),e._shTextures){this._shTextures=[];for(const e of this._shTextures)this._shTextures?.push(e.clone())}}clone(e=""){const t=new Ee(e,void 0,this.getScene());t._copySource(this),t.makeGeometryUnique(),t._vertexCount=this._vertexCount,t._copyTextures(this),t._modelViewMatrix=S.Identity(),t._splatPositions=this._splatPositions,t._readyToDisplay=!1,t._instanciateWorker();const s=this.getBoundingInfo();return t.getBoundingInfo().reConstruct(s.minimum,s.maximum,this.getWorldMatrix()),t.forcedInstanceCount=t._vertexCount,t.setEnabled(!0),t}_makeSplat(e,t,s,n,r,i,o,a){const c=w.Matrix[0],l=w.Matrix[1],u=w.Quaternion[0],h=this._useRGBACovariants?4:2,_=t[8*e+0],d=-t[8*e+1],p=t[8*e+2];this._splatPositions[4*e+0]=_,this._splatPositions[4*e+1]=d,this._splatPositions[4*e+2]=p,o.minimizeInPlaceFromFloats(_,d,p),a.maximizeInPlaceFromFloats(_,d,p),u.set((s[32*e+28+1]-127.5)/127.5,(s[32*e+28+2]-127.5)/127.5,(s[32*e+28+3]-127.5)/127.5,-(s[32*e+28+0]-127.5)/127.5),u.toRotationMatrix(c),S.ScalingToRef(2*t[8*e+3+0],2*t[8*e+3+1],2*t[8*e+3+2],l);const f=c.multiplyToRef(l,w.Matrix[0]).m,m=this._tmpCovariances;m[0]=f[0]*f[0]+f[1]*f[1]+f[2]*f[2],m[1]=f[0]*f[4]+f[1]*f[5]+f[2]*f[6],m[2]=f[0]*f[8]+f[1]*f[9]+f[2]*f[10],m[3]=f[4]*f[4]+f[5]*f[5]+f[6]*f[6],m[4]=f[4]*f[8]+f[5]*f[9]+f[6]*f[10],m[5]=f[8]*f[8]+f[9]*f[9]+f[10]*f[10];let x=-1e4;for(let e=0;e<6;e++)x=Math.max(x,Math.abs(m[e]));this._splatPositions[4*e+3]=x;const v=x;n[4*e+0]=b(m[0]/v),n[4*e+1]=b(m[1]/v),n[4*e+2]=b(m[2]/v),n[4*e+3]=b(m[3]/v),r[e*h+0]=b(m[4]/v),r[e*h+1]=b(m[5]/v),i[4*e+0]=s[32*e+24+0],i[4*e+1]=s[32*e+24+1],i[4*e+2]=s[32*e+24+2],i[4*e+3]=s[32*e+24+3]}_updateTextures(e,t,s,n){const r=this._getTextureSize(this._vertexCount),i=(e,t,s,n)=>new O(e,t,s,n,this._scene,!1,!1,D.TEXTURE_BILINEAR_SAMPLINGMODE,D.TEXTURETYPE_FLOAT),o=(e,t,s,n)=>new O(e,t,s,n,this._scene,!1,!1,D.TEXTURE_BILINEAR_SAMPLINGMODE,D.TEXTURETYPE_UNSIGNED_BYTE),a=(e,t,s,n)=>new O(e,t,s,n,this._scene,!1,!1,D.TEXTURE_NEAREST_SAMPLINGMODE,D.TEXTURETYPE_UNSIGNED_INTEGER),c=(e,t,s,n)=>new O(e,t,s,n,this._scene,!1,!1,D.TEXTURE_BILINEAR_SAMPLINGMODE,D.TEXTURETYPE_HALF_FLOAT);if(this._covariancesATexture){this._delayedTextureUpdate={covA:e,covB:t,colors:s,centers:this._splatPositions,sh:n};const r=Float32Array.from(this._splatPositions),i=this._vertexCount;this._worker.postMessage({positions:r,vertexCount:i},[r.buffer]),this._postToWorker(!0)}else{if(this._covariancesATexture=c(e,r.x,r.y,D.TEXTUREFORMAT_RGBA),this._covariancesBTexture=c(t,r.x,r.y,this._useRGBACovariants?D.TEXTUREFORMAT_RGBA:D.TEXTUREFORMAT_RG),this._centersTexture=i(this._splatPositions,r.x,r.y,D.TEXTUREFORMAT_RGBA),this._colorsTexture=o(s,r.x,r.y,D.TEXTUREFORMAT_RGBA),n){this._shTextures=[];for(const e of n){const t=a(new Uint32Array(e.buffer),r.x,r.y,D.TEXTUREFORMAT_RGBA_INTEGER);t.wrapU=D.TEXTURE_CLAMP_ADDRESSMODE,t.wrapV=D.TEXTURE_CLAMP_ADDRESSMODE,this._shTextures.push(t)}}this._instanciateWorker()}}*_updateData(e,t,s){this._covariancesATexture||(this._readyToDisplay=!1);const n=new Uint8Array(e),r=new Float32Array(n.buffer);this._keepInRam&&(this._splatsData=e,s&&(this._sh=s));const i=n.length/Ee._RowOutputLength;i!=this._vertexCount&&this._updateSplatIndexBuffer(i),this._vertexCount=i,this._shDegree=s?s.length:0;const o=this._getTextureSize(i),a=o.x*o.y,c=Ee.ProgressiveUpdateAmount??o.y,l=o.x*c;this._splatPositions=new Float32Array(4*a);const u=new Uint16Array(4*a),h=new Uint16Array((this._useRGBACovariants?4:2)*a),_=new Uint8Array(4*a),d=new y(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),p=new y(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);if(Ee.ProgressiveUpdateAmount){this._updateTextures(u,h,_,s),this.setEnabled(!0);const e=Math.ceil(o.y/c);for(let s=0;s<e;s++){const e=s*c,i=e*o.x;for(let e=0;e<l;e++)this._makeSplat(i+e,r,n,u,h,_,d,p);this._updateSubTextures(this._splatPositions,u,h,_,e,Math.min(c,o.y-e)),this.getBoundingInfo().reConstruct(d,p,this.getWorldMatrix()),t&&(yield)}const i=Float32Array.from(this._splatPositions),a=this._vertexCount;this._worker.postMessage({positions:i,vertexCount:a},[i.buffer]),this._sortIsDirty=!0}else{for(let e=0;e<i;e++)this._makeSplat(e,r,n,u,h,_,d,p),t&&e%Ee._SplatBatchSize===0&&(yield);this._updateTextures(u,h,_,s),this.getBoundingInfo().reConstruct(d,p,this.getWorldMatrix()),this.setEnabled(!0)}this._postToWorker(!0)}async updateDataAsync(e,t){return await A(this._updateData(e,!0,t),P())}updateData(e,t){H(this._updateData(e,!1,t))}refreshBoundingInfo(){return this.thinInstanceRefreshBoundingInfo(!1),this}_updateSplatIndexBuffer(e){(!this._splatIndex||e>this._splatIndex.length)&&(this._splatIndex=new Float32Array(e),this.thinInstanceSetBuffer("splatIndex",this._splatIndex,1,!1)),this.forcedInstanceCount=e}_updateSubTextures(e,t,s,n,r,i,o){const a=(e,t,s,n,r)=>{this.getEngine().updateTextureData(e.getInternalTexture(),t,0,n,s,r,0,0,!1)},c=this._getTextureSize(this._vertexCount),l=this._useRGBACovariants?4:2,u=r*c.x,h=i*c.x,_=new Uint16Array(t.buffer,4*u*Uint16Array.BYTES_PER_ELEMENT,4*h),d=new Uint16Array(s.buffer,u*l*Uint16Array.BYTES_PER_ELEMENT,h*l),p=new Uint8Array(n.buffer,4*u,4*h),f=new Float32Array(e.buffer,4*u*Float32Array.BYTES_PER_ELEMENT,4*h);if(a(this._covariancesATexture,_,c.x,r,i),a(this._covariancesBTexture,d,c.x,r,i),a(this._centersTexture,f,c.x,r,i),a(this._colorsTexture,p,c.x,r,i),o)for(let e=0;e<o.length;e++){const t=4,s=new Uint8Array(this._sh[e].buffer,u*t,h*t);a(this._shTextures[e],s,c.x,r,i)}}_instanciateWorker(){if(!this._vertexCount)return;this._updateSplatIndexBuffer(this._vertexCount),this._worker?.terminate(),this._worker=new Worker(URL.createObjectURL(new Blob(["(",Ee._CreateWorker.toString(),")(self)"],{type:"application/javascript"}))),this._depthMix=new BigInt64Array(this._vertexCount);const e=Float32Array.from(this._splatPositions),t=this._vertexCount;this._worker.postMessage({positions:e,vertexCount:t},[e.buffer]),this._worker.onmessage=e=>{this._depthMix=e.data.depthMix;const s=new Uint32Array(e.data.depthMix.buffer);if(this._splatIndex)for(let e=0;e<this._vertexCount;e++)this._splatIndex[e]=s[2*e];if(this._delayedTextureUpdate){const e=this._getTextureSize(t);this._updateSubTextures(this._delayedTextureUpdate.centers,this._delayedTextureUpdate.covA,this._delayedTextureUpdate.covB,this._delayedTextureUpdate.colors,0,e.y,this._delayedTextureUpdate.sh),this._delayedTextureUpdate=null}this.thinInstanceBufferUpdated("splatIndex"),this._canPostToWorker=!0,this._readyToDisplay=!0,this._sortIsDirty&&(this._postToWorker(!0),this._sortIsDirty=!1)}}_getTextureSize(e){const t=this._scene.getEngine(),s=t.getCaps().maxTextureSize;let n=1;if(1!==t.version||t.isWebGPU)n=Math.ceil(e/s);else for(;s*n<e;)n*=2;return n>s&&(T.Error("GaussianSplatting texture size: ("+s+", "+n+"), maxTextureSize: "+s),n=s),new M(s,n)}}Ee._RowOutputLength=32,Ee._SH_C0=.28209479177387814,Ee._SplatBatchSize=327680,Ee._PlyConversionBatchSize=32768,Ee.ProgressiveUpdateAmount=0,Ee._CreateWorker=function(e){let t,s,n,r,i=0;e.onmessage=o=>{if(o.data.positions)t=o.data.positions,i=o.data.vertexCount;else{const a=o.data.view;if(!t||!a)throw new Error("positions or view is not defined!");s=o.data.depthMix,n=new Uint32Array(s.buffer),r=new Float32Array(s.buffer);for(let e=0;e<i;e++)n[2*e]=e;let c=-1;o.data.useRightHandedSystem&&(c=1);for(let e=0;e<i;e++)r[2*e+1]=1e4+(a[2]*t[4*e+0]+a[6]*t[4*e+1]+a[10]*t[4*e+2])*c;s.sort(),e.postMessage({depthMix:s},[s.buffer])}}};class Ae{constructor(e,t,s,n,r){this.idx=0,this.color=new I(1,1,1,1),this.position=y.Zero(),this.rotation=y.Zero(),this.uv=new M(0,0),this.velocity=y.Zero(),this.pivot=y.Zero(),this.translateFromPivot=!1,this._pos=0,this._ind=0,this.groupId=0,this.idxInGroup=0,this._stillInvisible=!1,this._rotationMatrix=[1,0,0,0,1,0,0,0,1],this.parentId=null,this._globalPosition=y.Zero(),this.idx=e,this._group=t,this.groupId=s,this.idxInGroup=n,this._pcs=r}get size(){return this.size}set size(e){this.size=e}get quaternion(){return this.rotationQuaternion}set quaternion(e){this.rotationQuaternion=e}intersectsMesh(e,t){if(!e.hasBoundingInfo)return!1;if(!this._pcs.mesh)throw new Error("Point Cloud System doesnt contain the Mesh");if(t)return e.getBoundingInfo().boundingSphere.intersectsPoint(this.position.add(this._pcs.mesh.position));const s=e.getBoundingInfo().boundingBox,n=s.maximumWorld.x,r=s.minimumWorld.x,i=s.maximumWorld.y,o=s.minimumWorld.y,a=s.maximumWorld.z,c=s.minimumWorld.z,l=this.position.x+this._pcs.mesh.position.x,u=this.position.y+this._pcs.mesh.position.y,h=this.position.z+this._pcs.mesh.position.z;return r<=l&&l<=n&&o<=u&&u<=i&&c<=h&&h<=a}getRotationMatrix(e){let t;if(this.rotationQuaternion)t=this.rotationQuaternion;else{t=w.Quaternion[0];const e=this.rotation;R.RotationYawPitchRollToRef(e.y,e.x,e.z,t)}t.toRotationMatrix(e)}}class Pe{get groupID(){return this.groupId}set groupID(e){this.groupId=e}constructor(e,t){this.groupId=e,this._positionFunction=t}}!function(e){e[e.Color=2]="Color",e[e.UV=1]="UV",e[e.Random=0]="Random",e[e.Stated=3]="Stated"}(we||(we={}));class ze{get positions(){return this._positions32}get colors(){return this._colors32}get uvs(){return this._uvs32}constructor(e,t,s,n){this.particles=new Array,this.nbParticles=0,this.counter=0,this.vars={},this._promises=[],this._positions=new Array,this._indices=new Array,this._normals=new Array,this._colors=new Array,this._uvs=new Array,this._updatable=!0,this._isVisibilityBoxLocked=!1,this._alwaysVisible=!1,this._groups=new Array,this._groupCounter=0,this._computeParticleColor=!0,this._computeParticleTexture=!0,this._computeParticleRotation=!0,this._computeBoundingBox=!1,this._isReady=!1,this.name=e,this._size=t,this._scene=s||E.LastCreatedScene,n&&void 0!==n.updatable?this._updatable=n.updatable:this._updatable=!0}async buildMeshAsync(e){return await Promise.all(this._promises),this._isReady=!0,await this._buildMeshAsync(e)}async _buildMeshAsync(e){0===this.nbParticles&&this.addPoints(1),this._positions32=new Float32Array(this._positions),this._uvs32=new Float32Array(this._uvs),this._colors32=new Float32Array(this._colors);const t=new g;t.set(this._positions32,o.PositionKind),this._uvs32.length>0&&t.set(this._uvs32,o.UVKind);let s=0;this._colors32.length>0&&(s=1,t.set(this._colors32,o.ColorKind));const n=new v(this.name,this._scene);t.applyToMesh(n,this._updatable),this.mesh=n,this._positions=null,this._uvs=null,this._colors=null,this._updatable||(this.particles.length=0);let r=e;return r||(r=new W("point cloud material",this._scene),r.emissiveColor=new U(s,s,s),r.disableLighting=!0,r.pointsCloud=!0,r.pointSize=this._size),n.material=r,n}_addParticle(e,t,s,n){const r=new Ae(e,t,s,n,this);return this.particles.push(r),r}_randomUnitVector(e){e.position=new y(Math.random(),Math.random(),Math.random()),e.color=new I(1,1,1,1)}_getColorIndicesForCoord(e,t,s,n){const r=e._groupImageData,i=s*(4*n)+4*t,o=[i,i+1,i+2,i+3],a=o[1],c=o[2],l=o[3],u=r[o[0]],h=r[a],_=r[c],d=r[l];return new I(u/255,h/255,_/255,d)}_setPointsColorOrUV(e,t,s,n,r,i,a,c){c=c??0,s&&e.updateFacetData();const l=2*e.getBoundingInfo().boundingSphere.radius;let u=e.getVerticesData(o.PositionKind);const h=e.getIndices(),_=e.getVerticesData(o.UVKind+(c?c+1:"")),d=e.getVerticesData(o.ColorKind),p=y.Zero();e.computeWorldMatrix();const f=e.getWorldMatrix();if(!f.isIdentity()){u=u.slice(0);for(let e=0;e<u.length/3;e++)y.TransformCoordinatesFromFloatsToRef(u[3*e],u[3*e+1],u[3*e+2],f,p),u[3*e]=p.x,u[3*e+1]=p.y,u[3*e+2]=p.z}let m=0,x=0,v=0,S=0,g=0,C=0,w=0,T=0,E=0,A=0,P=0,z=0,b=0;const D=y.Zero(),H=y.Zero(),R=y.Zero(),B=y.Zero(),L=y.Zero();let k=0,O=0,N=0,W=0,X=0,j=0;const Z=M.Zero(),Y=M.Zero(),K=M.Zero(),q=M.Zero(),Q=M.Zero();let J=0,$=0,ee=0,te=0,se=0,ne=0,re=0,ie=0,oe=0,ae=0,ce=0,le=0;const ue=V.Zero(),he=V.Zero(),_e=V.Zero(),de=V.Zero(),pe=V.Zero();let fe,me,xe=0,ve=0;a=a||0;let Se=new V(0,0,0,0),ye=y.Zero(),ge=y.Zero(),Ce=y.Zero(),we=0,Te=y.Zero(),Ee=0,Ae=0;const Pe=new G(y.Zero(),new y(1,0,0));let ze,be=y.Zero();for(let o=0;o<h.length/3;o++){let c,p,f,M,V,G,De,He;x=h[3*o],v=h[3*o+1],S=h[3*o+2],g=u[3*x],C=u[3*x+1],w=u[3*x+2],T=u[3*v],E=u[3*v+1],A=u[3*v+2],P=u[3*S],z=u[3*S+1],b=u[3*S+2],D.set(g,C,w),H.set(T,E,A),R.set(P,z,b),H.subtractToRef(D,B),R.subtractToRef(H,L),_&&(k=_[2*x],O=_[2*x+1],N=_[2*v],W=_[2*v+1],X=_[2*S],j=_[2*S+1],Z.set(k,O),Y.set(N,W),K.set(X,j),Y.subtractToRef(Z,q),K.subtractToRef(Y,Q)),d&&n&&(J=d[4*x],$=d[4*x+1],ee=d[4*x+2],te=d[4*x+3],se=d[4*v],ne=d[4*v+1],re=d[4*v+2],ie=d[4*v+3],oe=d[4*S],ae=d[4*S+1],ce=d[4*S+2],le=d[4*S+3],ue.set(J,$,ee,te),he.set(se,ne,re,ie),_e.set(oe,ae,ce,le),he.subtractToRef(ue,de),_e.subtractToRef(he,pe));const Me=new U(0,0,0),Ie=new U(0,0,0);let Re,Ue;for(let u=0;u<t._groupDensity[o];u++)m=this.particles.length,this._addParticle(m,t,this._groupCounter,o+u),Ue=this.particles[m],xe=Math.sqrt(F(0,1)),ve=F(0,1),fe=D.add(B.scale(xe)).add(L.scale(xe*ve)),s&&(ye=e.getFacetNormal(o).normalize().scale(-1),ge=B.clone().normalize(),Ce=y.Cross(ye,ge),we=F(0,2*Math.PI),Te=ge.scale(Math.cos(we)).add(Ce.scale(Math.sin(we))),we=F(.1,Math.PI/2),be=Te.scale(Math.cos(we)).add(ye.scale(Math.sin(we))),Pe.origin=fe.add(be.scale(1e-5)),Pe