PageSourceSearch

https://ysharma-qwen21-rgba-orbit-lora-trackio.hf.space/assets/splatFileLoader-DT1fm5j0.js

js ysharma-qwen21-rgba-orbit-lora-trackio.hf.space collected 2026-10-04 17:33:46 UTC 105,586 bytes, 564 lines download raw bytes

1import{ImportMeshAsync as Gt,RegisterSceneLoaderPlugin as Xt}from"./sceneLoader-CutT-qCn.js";import{S as ke}from"./dynamic-FJPaSIUH.js";import{B as jt,S as Zt}from"./subMesh-UWDo5wjI.js";import{C as Ue,M as me}from"./mesh-mPmzf9d2.js";import{V as Ze,a as He,r as $t,c as Fe}from"./mesh.vertexData-Cr3zcPIw.js";import{E as Ee,V as D,M as Me,a as te,T as j,Q as Ft,b as ue}from"./math.vector-C1xyPDEl.js";import{L as ae}from"./bufferUtils-DTRdUD8L.js";import{_ as Ce}from"./index-DNAb5ghs.js";import{R as qt,E as Lt,i as B,S as vt}from"./decorators.serialization-C7d7ykGG.js";import{V as K}from"./buffer-DqKlo1ts.js";import{b as Kt}from"./imageProcessing-2WziWti-.js";import{P as Qt,B as Jt}from"./pushMaterial-B8MG1fVH.js";import{R as Yt,f as es,H as ts,a as ne}from"./math.scalar.functions-DkeaWAWz.js";import{m as ss,n as rs,o as is,q as ns,u as os,A as as,d as cs,e as ls,M as hs}from"./material-CrEsrP1R.js";import{D as gt}from"./drawWrapper-CZVk0xN-.js";import{S as St}from"./shaderMaterial-TD7H474q.js";import"./fogFragment-BipfZYze.js";import"./logDepthDeclaration-HIOxXXVm.js";import"./logDepthFragment-BWY-hMrf.js";import"./fogVertex-BALyqiCG.js";import"./helperFunctions-WQmx9NIl.js";import"./logDepthVertex-D80sdmdR.js";import"./fogFragment-iUGZBHjw.js";import"./logDepthDeclaration-BahBC74I.js";import"./logDepthFragment-BaiKWVSS.js";import"./helperFunctions-BABR42FV.js";import"./fogVertex-C2jSPOsq.js";import"./logDepthVertex-gbg7kMkf.js";import{R as be}from"./rawTexture-Cp8_XuDs.js";import"./thinInstanceMesh-BG8-058t.js";import{T as L}from"./textureTools-l0BtJBZL.js";import{P as fs}from"./sceneComponent-Dflhczui.js";import{A as us}from"./assetContainer-CQBIw-F6.js";import"./math.axis-Ck7JfPPj.js";import{Color4 as Y,Color3 as Te}from"./math.color-CzLaKyb6.js";import"./math.plane-Ce_75-g5.js";import"./math.path-DFucxaHn.js";import{R as ds}from"./ray-DaGFNizV.js";import{StandardMaterial as ps}from"./standardMaterial-eYtywjIC.js";import{B as _s}from"./baseTexture-CgAggsey.js";import{T as ms}from"./tools-D01N7ptR.js";import"./scene-gn_hoGMy.js";import"./smartArray-CO6iJ0u5.js";import"./lightConstants-B1TSTh-k.js";import"./renderingManager-CiY2OUrf.js";import"./deviceInputEvents-BTza-zoR.js";import"./perfCounter-DusmGz8t.js";import"./sceneLoaderFlags-wywyb9ml.js";import"./dataBuffer-CgoqiUzT.js";import"./node-C-Iu0ALa.js";import"./math.viewport-CgkTt1RS.js";import"./texture-BEqhDl5Y.js";import"./drawWrapper.functions-Dzz0ghog.js";import"./renderTargetTexture-BfAwifLK.js";import"./passPostProcess-BpF-jhzE.js";import"./effectRenderer-CSz5fi0n.js";import"./engine-CUAgB63E.js";import"./thinEngine-D5ynu8Dd.js";import"./instancedMesh-Bbh37yAW.js";import"./light-DT53MGnW.js";import"./material.detailMapConfiguration-D1Pl6X8T.js";class xs{constructor(){this.mm=new Map}get(e,t){const s=this.mm.get(e);if(s!==void 0)return s.get(t)}set(e,t,s){let o=this.mm.get(e);o===void 0&&this.mm.set(e,o=new Map),o.set(t,s)}}class vs{get standalone(){var e;return((e=this._options)==null?void 0:e.standalone)??!1}get baseMaterial(){return this._baseMaterial}get doNotInjectCode(){var e;return((e=this._options)==null?void 0:e.doNotInjectCode)??!1}constructor(e,t,s){this._baseMaterial=e,this._scene=t??Ee.LastCreatedScene,this._options=s,this._subMeshToEffect=new Map,this._subMeshToDepthWrapper=new xs,this._meshes=new Map,this._onEffectCreatedObserver=this._baseMaterial.onEffectCreatedObservable.add(o=>{var i,l;const r=(i=o.subMesh)==null?void 0:i.getMesh();r&&!this._meshes.has(r)&&this._meshes.set(r,r.onDisposeObservable.add(d=>{const a=this._subMeshToEffect.keys();for(let u=a.next();u.done!==!0;u=a.next()){const m=u.value;(m==null?void 0:m.getMesh())===d&&(this._subMeshToEffect.delete(m),this._deleteDepthWrapperEffect(m))}})),((l=this._subMeshToEffect.get(o.subMesh))==null?void 0:l[0])!==o.effect&&(this._subMeshToEffect.set(o.subMesh,[o.effect,this._scene.getEngine().currentRenderPassId]),this._deleteDepthWrapperEffect(o.subMesh))})}_deleteDepthWrapperEffect(e){const t=this._subMeshToDepthWrapper.mm.get(e);t&&(t.forEach(s=>{var o;(o=s.mainDrawWrapper.effect)==null||o.dispose()}),this._subMeshToDepthWrapper.mm.delete(e))}getEffect(e,t,s){var i;const o=(i=this._subMeshToDepthWrapper.mm.get(e))==null?void 0:i.get(t);if(!o)return null;let r=o.drawWrapper[s];return r||(r=o.drawWrapper[s]=new gt(this._scene.getEngine()),r.setEffect(o.mainDrawWrapper.effect,o.mainDrawWrapper.defines)),r}isReadyForSubMesh(e,t,s,o,r){var i;return this.standalone&&!this._baseMaterial.isReadyForSubMesh(e.getMesh(),e,o)?!1:((i=this._makeEffect(e,t,s,r))==null?void 0:i.isReady())??!1}dispose(){this._baseMaterial.onEffectCreatedObservable.remove(this._onEffectCreatedObserver),this._onEffectCreatedObserver=null;const e=this._meshes.entries();for(let t=e.next();t.done!==!0;t=e.next()){const[s,o]=t.value;s.onDisposeObservable.remove(o)}}_makeEffect(e,t,s,o){var h,p;const r=this._scene.getEngine(),i=this._subMeshToEffect.get(e);if(!i)return null;const[l,d]=i;if(!l.isReady())return null;let a=this._subMeshToDepthWrapper.get(e,s);if(!a){const w=new gt(r),c=(h=e._getDrawWrapper(d))==null?void 0:h.defines;w.defines=typeof c=="string"?null:c??null,a={drawWrapper:[],mainDrawWrapper:w,depthDefines:"",token:qt()},a.drawWrapper[o]=w,this._subMeshToDepthWrapper.set(e,s,a)}
1const u=t.join(`
2`);if(a.mainDrawWrapper.effect&&u===a.depthDefines)return a.mainDrawWrapper.effect;a.depthDefines=u;const m=l.getUniformNames().slice();let f=l.vertexSourceCodeBeforeMigration,_=l.fragmentSourceCodeBeforeMigration;if(!f&&!_)return null;if(!this.doNotInjectCode){const w=this._options&&this._options.remappedVariables?`#include<shadowMapVertexNormalBias>(${this._options.remappedVariables.join(",")})`:"#include<shadowMapVertexNormalBias>",c=this._options&&this._options.remappedVariables?`#include<shadowMapVertexMetric>(${this._options.remappedVariables.join(",")})`:"#include<shadowMapVertexMetric>",y=this._options&&this._options.remappedVariables?`#include<shadowMapFragmentSoftTransparentShadow>(${this._options.remappedVariables.join(",")})`:"#include<shadowMapFragmentSoftTransparentShadow>",v="#include<shadowMapFragment>",C="#include<shadowMapVertexExtraDeclaration>";l.shaderLanguage===0?f=f.replace(/void\s+?main/g,`
3${C}
4void main`):f=f.replace(/@vertex/g,`
5${C}
6@vertex`),f=f.replace(/#define SHADOWDEPTH_NORMALBIAS|#define CUSTOM_VERTEX_UPDATE_WORLDPOS/g,w),f.indexOf("#define SHADOWDEPTH_METRIC")!==-1?f=f.replace(/#define SHADOWDEPTH_METRIC/g,c):f=f.replace(/}\s*$/g,c+`
7}`),f=f.replace(/#define SHADER_NAME.*?\n|out vec4 glFragColor;\n/g,"");const I=_.indexOf("#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW")>=0||_.indexOf("#define CUSTOM_FRAGMENT_BEFORE_FOG")>=0,g=_.indexOf("#define SHADOWDEPTH_FRAGMENT")!==-1;let x="";I?_=_.replace(/#define SHADOWDEPTH_SOFTTRANSPARENTSHADOW|#define CUSTOM_FRAGMENT_BEFORE_FOG/g,y):x=y+`
8`,_=_.replace(/void\s+?main/g,Lt.IncludesShadersStore.shadowMapFragmentExtraDeclaration+`
9void main`),g?_=_.replace(/#define SHADOWDEPTH_FRAGMENT/g,v):x+=v+`
10`,x&&(_=_.replace(/}\s*$/g,x+"}")),m.push("biasAndScaleSM","depthValuesSM","lightDataSM","softTransparentShadowSM")}a.mainDrawWrapper.effect=r.createEffect({vertexSource:f,fragmentSource:_,vertexToken:a.token,fragmentToken:a.token},{attributes:l.getAttributesNames(),uniformsNames:m,uniformBuffersNames:l.getUniformBuffersNames(),samplers:l.getSamplers(),defines:u+`
11`+l.defines.replace("#define SHADOWS","").replace(/#define SHADOW\d/g,""),indexParameters:l.getIndexParameters(),shaderLanguage:l.shaderLanguage},r);for(let w=0;w<a.drawWrapper.length;++w)w!==o&&((p=a.drawWrapper[w])==null||p.setEffect(a.mainDrawWrapper.effect,a.mainDrawWrapper.defines));return a.mainDrawWrapper.effect}}const yt="gaussianSplattingFragmentDeclaration",gs=`vec4 gaussianColor(vec4 inColor)
12{float A=-dot(vPosition,vPosition);if (A<-4.0) discard;float B=exp(A)*inColor.a;
13#include<logDepthFragment>
14vec3 color=inColor.rgb;
15#ifdef FOG
16#include<fogFragment>
17#endif
18return vec4(color,B);}
19`;B.IncludesShadersStore[yt]||(B.IncludesShadersStore[yt]=gs);const Ne="gaussianSplattingPixelShader",Bt=`#include<clipPlaneFragmentDeclaration>
20#include<logDepthDeclaration>
21#include<fogFragmentDeclaration>
22varying vec4 vColor;varying vec2 vPosition;
23#define CUSTOM_FRAGMENT_DEFINITIONS
24#include<gaussianSplattingFragmentDeclaration>
25void main () {
26#define CUSTOM_FRAGMENT_MAIN_BEGIN
27#include<clipPlaneFragment>
28vec4 finalColor=gaussianColor(vColor);
29#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
30gl_FragColor=finalColor;
31#define CUSTOM_FRAGMENT_MAIN_END
32}
33`;B.ShadersStore[Ne]||(B.ShadersStore[Ne]=Bt);const Ss={name:Ne,shader:Bt},ys=Object.freeze(Object.defineProperty({__proto__:null,gaussianSplattingPixelShader:Ss},Symbol.toStringTag,{value:"Module"})),wt="gaussianSplattingVertexDeclaration",ws="attribute vec3 position;attribute vec4 splatIndex0;attribute vec4 splatIndex1;attribute vec4 splatIndex2;attribute vec4 splatIndex3;uniform mat4 view;uniform mat4 projection;uniform mat4 world;uniform vec4 vEyePosition;";B.IncludesShadersStore[wt]||(B.IncludesShadersStore[wt]=ws);const It="gaussianSplattingUboDeclaration",Is=`#include<sceneUboDeclaration>
34#include<meshUboDeclaration>
35attribute vec3 position;attribute vec4 splatIndex0;attribute vec4 splatIndex1;attribute vec4 splatIndex2;attribute vec4 splatIndex3;
36`;B.IncludesShadersStore[It]||(B.IncludesShadersStore[It]=Is);const Ct="gaussianSplatting",Cs=`#if !defined(WEBGL2) && !defined(WEBGPU) && !defined(NATIVE)
37mat3 transpose(mat3 matrix) {return mat3(matrix[0][0],matrix[1][0],matrix[2][0],
38matrix[0][1],matrix[1][1],matrix[2][1],
39matrix[0][2],matrix[1][2],matrix[2][2]);}
40#endif
41vec2 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);}
42#if SH_DEGREE>0 || IS_COMPOUND
43ivec2 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));}
44#endif
45struct Splat {vec4 center;vec4 color;vec4 covA;vec4 covB;
46#if SH_DEGREE>0
47uvec4 sh0; 
48#endif
49#if SH_DEGREE>1
50uvec4 sh1;
51#endif
52#if SH_DEGREE>2
53uvec4 sh2;
54#endif
55#if IS_COMPOUND
56uint partIndex;
57#endif
58};float getSplatIndex(int localIndex)
59{float splatIndex;switch (localIndex)
60{case 0: splatIndex=splatIndex0.x; break;case 1: splatIndex=splatIndex0.y; break;case 2: splatIndex=splatIndex0.z; break;case 3: splatIndex=splatIndex0.w; break;case 4: splatIndex=splatIndex1.x; break;case 5: splatIndex=splatIndex1.y; break;case 6: splatIndex=splatIndex1.z; break;case 7: splatIndex=splatIndex1.w; break;case 8: splatIndex=splatIndex2.x; break;case 9: splatIndex=splatIndex2.y; break;case 10: splatIndex=splatIndex2.z; break;case 11: splatIndex=splatIndex2.w; break;case 12: splatIndex=splatIndex3.x; break;case 13: splatIndex=splatIndex3.y; break;case 14: splatIndex=splatIndex3.z; break;case 15: splatIndex=splatIndex3.w; break;}
61return splatIndex;}
62Splat readSplat(float splatIndex)
63{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;
64#if SH_DEGREE>0 || IS_COMPOUND
65ivec2 splatUVint=getDataUVint(splatIndex,dataTextureSize);
66#endif
67#if SH_DEGREE>0
68splat.sh0=texelFetch(shTexture0,splatUVint,0);
69#endif
70#if SH_DEGREE>1
71splat.sh1=texelFetch(shTexture1,splatUVint,0);
72#endif
73#if SH_DEGREE>2
74splat.sh2=texelFetch(shTexture2,splatUVint,0);
75#endif
76#if IS_COMPOUND
77splat.partIndex=uint(texture2D(partIndicesTexture,splatUV).r*255.0+0.5);
78#endif
79return splat;}
80#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)
81vec3 computeColorFromSHDegree(vec3 dir,const vec3 sh[16])
82{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];
83#if SH_DEGREE>0
84float 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];
85#if SH_DEGREE>1
86float xx=x*x,yy=y*y,zz=z*z;float xy=x*y,yz=y*z,xz=x*z;result+=
87SH_C2[0]*xy*sh[4] +
88SH_C2[1]*yz*sh[5] +
89SH_C2[2]*(2.0*zz-xx-yy)*sh[6] +
90SH_C2[3]*xz*sh[7] +
91SH_C2[4]*(xx-yy)*sh[8];
92#if SH_DEGREE>2
93result+=
94SH_C3[0]*y*(3.0*xx-yy)*sh[9] +
95SH_C3[1]*xy*z*sh[10] +
96SH_C3[2]*y*(4.0*zz-xx-yy)*sh[11] +
97SH_C3[3]*z*(2.0*zz-3.0*xx-3.0*yy)*sh[12] +
98SH_C3[4]*x*(4.0*zz-xx-yy)*sh[13] +
99SH_C3[5]*z*(xx-yy)*sh[14] +
100SH_C3[6]*x*(xx-3.0*yy)*sh[15];
101#endif
102#endif
103#endif
104return result;}
105vec4 decompose(uint value)
106{vec4 components=vec4(
107float((value ) & 255u),
108float((value>>uint( 8)) & 255u),
109float((value>>uint(16)) & 255u),
110float((value>>uint(24)) & 255u));return components*vec4(2./255.)-vec4(1.);}
111vec3 computeSH(Splat splat,vec3 dir)
112{vec3 sh[16];sh[0]=vec3(0.,0.,0.);
113#if SH_DEGREE>0
114vec4 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);
115#endif
116#if SH_DEGREE>1
117vec4 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);
118#endif
119#if SH_DEGREE>2
120vec4 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); 
121#endif
122return computeColorFromSHDegree(dir,sh);}
123#else
124vec3 computeSH(Splat splat,vec3 dir)
125{return vec3(0.,0.,0.);}
126#endif
127vec4 gaussianSplatting(vec2 meshPos,vec3 worldPos,vec2 scale,vec3 covA,vec3 covB,mat4 worldMatrix,mat4 viewMatrix,mat4 projectionMatrix)
128{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
129|| pos2d.y<-bounds || pos2d.y>bounds) {return vec4(0.0,0.0,2.0,1.0);}
130mat3 Vrk=mat3(
131covA.x,covA.y,covA.z,
132covA.y,covB.x,covB.y,
133covA.z,covB.y,covB.z
134);bool isOrtho=abs(projectionMatrix[3][3]-1.0)<0.001;mat3 J;if (isOrtho) {J=mat3(
135focal.x,0.,0.,
1360.,focal.y,0.,
1370.,0.,0.
138);} else {J=mat3(
139focal.x/camspace.z,0.,-(focal.x*camspace.x)/(camspace.z*camspace.z),
1400.,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),
1410.,0.,0.
142);}
143mat3 T=transpose(mat3(modelView))*J;mat3 cov2d=transpose(T)*Vrk*T;
144#if COMPENSATION
145float c00=cov2d[0][0];float c11=cov2d[1][1];float c01=cov2d[0][1];float detOrig=c00*c11-c01*c01;
146#endif
147cov2d[0][0]+=kernelSize;cov2d[1][1]+=kernelSize;
148#if COMPENSATION
149vec3 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;
150#endif
151float 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;
151float lambda1=mid+radius+epsilon,lambda2=mid-radius+epsilon;if (lambda2<0.0)
152{return vec4(0.0,0.0,2.0,1.0);}
153vec2 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);float scaleFactor=isOrtho ? 1.0 : pos2d.w;return vec4(
154vCenter 
155+ ((meshPos.x*majorAxis
156+ meshPos.y*minorAxis)*invViewport*scaleFactor)*scale,pos2d.zw);}
157#if IS_COMPOUND
158mat4 getPartWorld(uint partIndex) {return partWorld[partIndex];}
159#endif
160`;B.IncludesShadersStore[Ct]||(B.IncludesShadersStore[Ct]=Cs);const We="gaussianSplattingVertexShader",Nt=`#include<__decl__gaussianSplattingVertex>
161#ifdef LOGARITHMICDEPTH
162#extension GL_EXT_frag_depth : enable
163#endif
164#include<clipPlaneVertexDeclaration>
165#include<fogVertexDeclaration>
166#include<logDepthDeclaration>
167#include<helperFunctions>
168uniform vec2 invViewport;uniform vec2 dataTextureSize;uniform vec2 focal;uniform float kernelSize;uniform vec3 eyePosition;uniform float alpha;
169#if IS_COMPOUND
170uniform mat4 partWorld[MAX_PART_COUNT];uniform float partVisibility[MAX_PART_COUNT];
171#endif
172uniform sampler2D covariancesATexture;uniform sampler2D covariancesBTexture;uniform sampler2D centersTexture;uniform sampler2D colorsTexture;
173#if SH_DEGREE>0
174uniform highp usampler2D shTexture0;
175#endif
176#if SH_DEGREE>1
177uniform highp usampler2D shTexture1;
178#endif
179#if SH_DEGREE>2
180uniform highp usampler2D shTexture2;
181#endif
182#if IS_COMPOUND
183uniform sampler2D partIndicesTexture;
184#endif
185varying vec4 vColor;varying vec2 vPosition;
186#define CUSTOM_VERTEX_DEFINITIONS
187#include<gaussianSplatting>
188void main () {
189#define CUSTOM_VERTEX_MAIN_BEGIN
190float splatIndex=getSplatIndex(int(position.z+0.5));Splat splat=readSplat(splatIndex);vec3 covA=splat.covA.xyz;vec3 covB=vec3(splat.covA.w,splat.covB.xy);
191#if IS_COMPOUND
192mat4 splatWorld=getPartWorld(splat.partIndex);
193#else
194mat4 splatWorld=world;
195#endif
196vec4 worldPos=splatWorld*vec4(splat.center.xyz,1.0);vColor=splat.color;vPosition=position.xy;
197#if SH_DEGREE>0
198mat3 worldRot=mat3(splatWorld);mat3 normWorldRot=inverseMat3(worldRot);vec3 eyeToSplatLocalSpace=normalize(normWorldRot*(worldPos.xyz-eyePosition));vColor.xyz=splat.color.xyz+computeSH(splat,eyeToSplatLocalSpace);
199#endif
200vColor.w*=alpha;
201#if IS_COMPOUND
202vColor.w*=partVisibility[splat.partIndex];
203#endif
204vec2 scale=vec2(1.,1.);
205#define CUSTOM_VERTEX_UPDATE
206gl_Position=gaussianSplatting(position.xy,worldPos.xyz,scale,covA,covB,splatWorld,view,projection);
207#include<clipPlaneVertex>
208#include<fogVertex>
209#include<logDepthVertex>
210#define CUSTOM_VERTEX_MAIN_END
211}
212`;B.ShadersStore[We]||(B.ShadersStore[We]=Nt);const bs={name:We,shader:Nt},Ts=Object.freeze(Object.defineProperty({__proto__:null,gaussianSplattingVertexShader:bs},Symbol.toStringTag,{value:"Module"})),bt="gaussianSplattingFragmentDeclaration",Ms=`fn gaussianColor(inColor: vec4f,inPosition: vec2f)->vec4f
213{var A : f32=-dot(inPosition,inPosition);if (A>-4.0)
214{var B: f32=exp(A)*inColor.a;
215#include<logDepthFragment>
216var color: vec3f=inColor.rgb;
217#ifdef FOG
218#include<fogFragment>
219#endif
220return vec4f(color,B);} else {return vec4f(0.0);}}
221`;B.IncludesShadersStoreWGSL[bt]||(B.IncludesShadersStoreWGSL[bt]=Ms);const Ve="gaussianSplattingPixelShader",Wt=`#include<clipPlaneFragmentDeclaration>
222#include<logDepthDeclaration>
223#include<fogFragmentDeclaration>
224varying vColor: vec4f;varying vPosition: vec2f;
225#define CUSTOM_FRAGMENT_DEFINITIONS
226#include<gaussianSplattingFragmentDeclaration>
227@fragment
228fn main(input: FragmentInputs)->FragmentOutputs {
229#define CUSTOM_FRAGMENT_MAIN_BEGIN
230#include<clipPlaneFragment>
231var finalColor: vec4f=gaussianColor(input.vColor,input.vPosition);
232#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
233fragmentOutputs.color=finalColor;
234#define CUSTOM_FRAGMENT_MAIN_END
235}
236`;B.ShadersStoreWGSL[Ve]||(B.ShadersStoreWGSL[Ve]=Wt);const Es={name:Ve,shader:Wt},Ds=Object.freeze(Object.defineProperty({__proto__:null,gaussianSplattingPixelShaderWGSL:Es},Symbol.toStringTag,{value:"Module"})),Tt="gaussianSplatting",As=`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));}
237struct Splat {center: vec4f,
238color: vec4f,
239covA: vec4f,
240covB: vec4f,
241#if SH_DEGREE>0
242sh0: vec4<u32>,
243#endif
244#if SH_DEGREE>1
245sh1: vec4<u32>,
246#endif
247#if SH_DEGREE>2
248sh2: vec4<u32>,
249#endif
250#if IS_COMPOUND
251partIndex: u32,
252#endif
253};fn getSplatIndex(localIndex: i32,splatIndex0: vec4f,splatIndex1: vec4f,splatIndex2: vec4f,splatIndex3: vec4f)->f32 {var splatIndex: f32;switch (localIndex)
254{case 0:
255{splatIndex=splatIndex0.x;break;}
256case 1:
257{splatIndex=splatIndex0.y;break;}
258case 2:
259{splatIndex=splatIndex0.z;break;}
260case 3:
261{splatIndex=splatIndex0.w;break;}
262case 4:
263{splatIndex=splatIndex1.x;break;}
264case 5:
265{splatIndex=splatIndex1.y;break;}
266case 6:
267{splatIndex=splatIndex1.z;break;}
268case 7:
269{splatIndex=splatIndex1.w;break;}
270case 8:
271{splatIndex=splatIndex2.x;break;}
272case 9:
273{splatIndex=splatIndex2.y;break;}
274case 10:
275{splatIndex=splatIndex2.z;break;}
276case 11:
277{splatIndex=splatIndex2.w;break;}
278case 12:
279{splatIndex=splatIndex3.x;break;}
280case 13:
281{splatIndex=splatIndex3.y;break;}
282case 14:
283{splatIndex=splatIndex3.z;break;}
284default:
285{splatIndex=splatIndex3.w;break;}}
286return splatIndex;}
287fn readSplat(splatIndex: f32,dataTextureSize: vec2f)->Splat {var splat: Splat;let splatUV=getDataUV(splatIndex,dataTextureSize);let splatUVi32=vec2<i32>
287(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;
288#if SH_DEGREE>0
289splat.sh0=textureLoad(shTexture0,splatUVi32,0);
290#endif
291#if SH_DEGREE>1
292splat.sh1=textureLoad(shTexture1,splatUVi32,0);
293#endif
294#if SH_DEGREE>2
295splat.sh2=textureLoad(shTexture2,splatUVi32,0);
296#endif
297#if IS_COMPOUND
298splat.partIndex=u32(textureLoad(partIndicesTexture,splatUVi32,0).r*255.0+0.5);
299#endif
300return splat;}
301fn computeColorFromSHDegree(dir: vec3f,sh: array<vec3<f32>,16>)->vec3f
302{let SH_C0: f32=0.28209479;let SH_C1: f32=0.48860251;var SH_C2: array<f32,5>=array<f32,5>(
3031.092548430,
304-1.09254843,
3050.315391565,
306-1.09254843,
3070.546274215
308);var SH_C3: array<f32,7>=array<f32,7>(
309-0.59004358,
3102.890611442,
311-0.45704579,
3120.373176332,
313-0.45704579,
3141.445305721,
315-0.59004358
316);var result: vec3f=/*SH_C0**/sh[0];
317#if SH_DEGREE>0
318let 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];
319#if SH_DEGREE>1
320let 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+=
321SH_C2[0]*xy*sh[4] +
322SH_C2[1]*yz*sh[5] +
323SH_C2[2]*(2.0f*zz-xx-yy)*sh[6] +
324SH_C2[3]*xz*sh[7] +
325SH_C2[4]*(xx-yy)*sh[8];
326#if SH_DEGREE>2
327result+=
328SH_C3[0]*y*(3.0f*xx-yy)*sh[9] +
329SH_C3[1]*xy*z*sh[10] +
330SH_C3[2]*y*(4.0f*zz-xx-yy)*sh[11] +
331SH_C3[3]*z*(2.0f*zz-3.0f*xx-3.0f*yy)*sh[12] +
332SH_C3[4]*x*(4.0f*zz-xx-yy)*sh[13] +
333SH_C3[5]*z*(xx-yy)*sh[14] +
334SH_C3[6]*x*(xx-3.0f*yy)*sh[15];
335#endif
336#endif
337#endif
338return result;}
339fn decompose(value: u32)->vec4f
340{let components : vec4f=vec4f(
341f32((value ) & 255u),
342f32((value>>u32( 8)) & 255u),
343f32((value>>u32(16)) & 255u),
344f32((value>>u32(24)) & 255u));return components*vec4f(2./255.)-vec4f(1.);}
345fn computeSH(splat: Splat,dir: vec3f)->vec3f
346{var sh: array<vec3<f32>,16>;sh[0]=vec3f(0.,0.,0.);
347#if SH_DEGREE>0
348let 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);
349#endif
350#if SH_DEGREE>1
351let 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);
352#endif
353#if SH_DEGREE>2
354let 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); 
355#endif
356return computeColorFromSHDegree(dir,sh);}
357fn gaussianSplatting(
358meshPos: vec2<f32>,
359worldPos: vec3<f32>,
360scale: vec2<f32>,
361covA: vec3<f32>,
362covB: vec3<f32>,
363worldMatrix: mat4x4<f32>,
364viewMatrix: mat4x4<f32>,
365projectionMatrix: mat4x4<f32>,
366focal: vec2f,
367invViewport: vec2f,
368kernelSize: f32
369)->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);}
370let Vrk=mat3x3<f32>(
371covA.x,covA.y,covA.z,
372covA.y,covB.x,covB.y,
373covA.z,covB.y,covB.z
374);let isOrtho=abs(projectionMatrix[3][3]-1.0)<0.001;var J: mat3x3<f32>;if (isOrtho) {J=mat3x3<f32>(
375focal.x,0.0,0.0,
3760.0,focal.y,0.0,
3770.0,0.0,0.0
378);} else {J=mat3x3<f32>(
379focal.x/camspace.z,0.0,-(focal.x*camspace.x)/(camspace.z*camspace.z),
3800.0,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),
3810.0,0.0,0.0
382);}
383let T=transpose(mat3x3<f32>(
384modelView[0].xyz,
385modelView[1].xyz,
386modelView[2].xyz))*J;var cov2d=transpose(T)*Vrk*T;
387#if COMPENSATION
388let c00: f32=cov2d[0][0];let c11: f32=cov2d[1][1];let c01: f32=cov2d[0][1];let detOrig: f32=c00*c11-c01*c01;
389#endif
390cov2d[0][0]+=kernelSize;cov2d[1][1]+=kernelSize;
391#if COMPENSATION
392let 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;
393#endif
394let 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]));
394let lambda1=mid+radius;let lambda2=mid-radius;if (lambda2<0.0) {return vec4f(0.0,0.0,2.0,1.0);}
395let 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);let scaleFactor=select(pos2d.w,1.0,isOrtho);return vec4f(
396vCenter+((meshPos.x*majorAxis+meshPos.y*minorAxis)*invViewport*scaleFactor)*scale,
397pos2d.z,
398pos2d.w
399);}
400#if IS_COMPOUND
401fn getPartWorld(partIndex: u32)->mat4x4<f32> {return uniforms.partWorld[partIndex];}
402#endif
403`;B.IncludesShadersStoreWGSL[Tt]||(B.IncludesShadersStoreWGSL[Tt]=As);const Ge="gaussianSplattingVertexShader",Vt=`#include<sceneUboDeclaration>
404#include<meshUboDeclaration>
405#include<helperFunctions>
406#include<clipPlaneVertexDeclaration>
407#include<fogVertexDeclaration>
408#include<logDepthDeclaration>
409attribute splatIndex0: vec4f;attribute splatIndex1: vec4f;attribute splatIndex2: vec4f;attribute splatIndex3: vec4f;attribute position: vec3f;uniform invViewport: vec2f;uniform dataTextureSize: vec2f;uniform focal: vec2f;uniform kernelSize: f32;uniform eyePosition: vec3f;uniform alpha: f32;
410#if IS_COMPOUND
411uniform partWorld: array<mat4x4<f32>,MAX_PART_COUNT>;uniform partVisibility: array<f32,MAX_PART_COUNT>;
412#endif
413var covariancesATexture: texture_2d<f32>;var covariancesBTexture: texture_2d<f32>;var centersTexture: texture_2d<f32>;var colorsTexture: texture_2d<f32>;
414#if SH_DEGREE>0
415var shTexture0: texture_2d<u32>;
416#endif
417#if SH_DEGREE>1
418var shTexture1: texture_2d<u32>;
419#endif
420#if SH_DEGREE>2
421var shTexture2: texture_2d<u32>;
422#endif
423#if IS_COMPOUND
424var partIndicesTexture: texture_2d<f32>;
425#endif
426varying vColor: vec4f;varying vPosition: vec2f;
427#define CUSTOM_VERTEX_DEFINITIONS
428#include<gaussianSplatting>
429@vertex
430fn main(input : VertexInputs)->FragmentInputs {
431#define CUSTOM_VERTEX_MAIN_BEGIN
432let splatIndex: f32=getSplatIndex(i32(vertexInputs.position.z+0.5),vertexInputs.splatIndex0,vertexInputs.splatIndex1,vertexInputs.splatIndex2,vertexInputs.splatIndex3);var splat: Splat=readSplat(splatIndex,uniforms.dataTextureSize);var covA: vec3f=splat.covA.xyz;var covB: vec3f=vec3f(splat.covA.w,splat.covB.xy);
433#if IS_COMPOUND
434let splatWorld: mat4x4f=getPartWorld(splat.partIndex);
435#else
436let splatWorld: mat4x4f=mesh.world;
437#endif
438let worldPos: vec4f=splatWorld*vec4f(splat.center.xyz,1.0);vertexOutputs.vPosition=vertexInputs.position.xy;
439#if SH_DEGREE>0
440let worldRot: mat3x3f= mat3x3f(splatWorld[0].xyz,splatWorld[1].xyz,splatWorld[2].xyz);let normWorldRot: mat3x3f=inverseMat3(worldRot);var eyeToSplatLocalSpace: vec3f=normalize(normWorldRot*(worldPos.xyz-uniforms.eyePosition.xyz));vertexOutputs.vColor=vec4f(splat.color.xyz+computeSH(splat,eyeToSplatLocalSpace),splat.color.w*uniforms.alpha);
441#else
442vertexOutputs.vColor=vec4f(splat.color.xyz,splat.color.w*uniforms.alpha);
443#endif
444#if IS_COMPOUND
445vertexOutputs.vColor.w*=uniforms.partVisibility[splat.partIndex];
446#endif
447let scale: vec2f=vec2f(1.,1.);
448#define CUSTOM_VERTEX_UPDATE
449vertexOutputs.position=gaussianSplatting(vertexInputs.position.xy,worldPos.xyz,scale,covA,covB,splatWorld,scene.view,scene.projection,uniforms.focal,uniforms.invViewport,uniforms.kernelSize);
450#include<clipPlaneVertex>
451#include<fogVertex>
452#include<logDepthVertex>
453#define CUSTOM_VERTEX_MAIN_END
454}
455`;B.ShadersStoreWGSL[Ge]||(B.ShadersStoreWGSL[Ge]=Vt);const zs={name:Ge,shader:Vt},Os=Object.freeze(Object.defineProperty({__proto__:null,gaussianSplattingVertexShaderWGSL:zs},Symbol.toStringTag,{value:"Module"})),Mt="gaussianSplattingDepthPixelShader",Rs=`precision highp float;varying vec2 vPosition;varying vec4 vColor;
456#ifdef DEPTH_RENDER
457varying float vDepthMetric;
458#endif
459void main(void) {float A=-dot(vPosition,vPosition);
460#if (defined(SM_SOFTTRANSPARENTSHADOW) && SM_SOFTTRANSPARENTSHADOW==1) || (defined(DEPTH_RENDER) && defined(ALPHA_BLENDED_DEPTH))
461float alpha=exp(A)*vColor.a;if (A<-4.)
462discard;
463#else
464if (A<-vColor.a)
465discard;
466#endif
467#ifdef DEPTH_RENDER
468float opacity=1.0;
469#ifdef ALPHA_BLENDED_DEPTH
470opacity=alpha;
471#endif
472gl_FragColor=vec4(vDepthMetric,0.0,0.0,opacity);
473#endif
474}`;B.ShadersStore[Mt]||(B.ShadersStore[Mt]=Rs);const Et="gaussianSplattingDepthVertexShader",Ps=`#include<__decl__gaussianSplattingVertex>
475uniform vec2 invViewport;uniform vec2 dataTextureSize;uniform vec2 focal;uniform float kernelSize;uniform float alpha;uniform sampler2D covariancesATexture;uniform sampler2D covariancesBTexture;uniform sampler2D centersTexture;uniform sampler2D colorsTexture;
476#if IS_COMPOUND
477uniform mat4 partWorld[MAX_PART_COUNT];uniform float partVisibility[MAX_PART_COUNT];uniform sampler2D partIndicesTexture;
478#endif
479varying vec2 vPosition;varying vec4 vColor;
480#include<gaussianSplatting>
481#ifdef DEPTH_RENDER
482uniform vec2 depthValues;varying float vDepthMetric;
483#endif
484void main(void) {float splatIndex=getSplatIndex(int(position.z+0.5));Splat splat=readSplat(splatIndex);vec3 covA=splat.covA.xyz;vec3 covB=vec3(splat.covA.w,splat.covB.xy);
485#if IS_COMPOUND
486mat4 splatWorld=getPartWorld(splat.partIndex);
487#else
488mat4 splatWorld=world;
489#endif
490vec4 worldPosGS=splatWorld*vec4(splat.center.xyz,1.0);vPosition=position.xy;vColor=splat.color;vColor.w*=alpha;
491#if IS_COMPOUND
492vColor.w*=partVisibility[splat.partIndex];
493#endif
494gl_Position=gaussianSplatting(position.xy,worldPosGS.xyz,vec2(1.,1.),covA,covB,splatWorld,view,projection);
495#ifdef DEPTH_RENDER
496#ifdef USE_REVERSE_DEPTHBUFFER
497vDepthMetric=((-gl_Position.z+depthValues.x)/(depthValues.y));
498#else
499vDepthMetric=((gl_Position.z+depthValues.x)/(depthValues.y));
500#endif
501#endif
502}`;B.ShadersStore[Et]||(B.ShadersStore[Et]=Ps);const Dt="gaussianSplattingDepthPixelShader",ks=`#include<gaussianSplattingFragmentDeclaration>
503varying vPosition: vec2f;varying vColor: vec4f;
504#ifdef DEPTH_RENDER
505varying vDepthMetric: f32;
506#endif
507fn checkDiscard(inPosition: vec2f,inColor: vec4f)->vec4f {var A : f32=-dot(inPosition,inPosition);var alpha : f32=exp(A)*inColor.a;
508#if (defined(SM_SOFTTRANSPARENTSHADOW) && SM_SOFTTRANSPARENTSHADOW==1) || (defined(DEPTH_RENDER) && defined(ALPHA_BLENDED_DEPTH))
509if (A<-4.) {discard;}
510#else
511if (A<-inColor.a) {discard;}
512#endif
513#ifdef DEPTH_RENDER
514var opacity : f32=1.0;
515#ifdef ALPHA_BLENDED_DEPTH
516opacity=alpha;
517#endif
518return vec4f(fragmentInputs.vDepthMetric,0.0,0.0,opacity);
519#else
520return vec4f(inColor.rgb,alpha);
521#endif
522}
523#define CUSTOM_FRAGMENT_DEFINITIONS
524@fragment
525fn main(input: FragmentInputs)->FragmentOutputs {fragmentOutputs.color=checkDiscard(fragmentInputs.vPosition,fragmentInputs.vColor);
526#if (defined(SM_SOFTTRANSPARENTSHADOW) && SM_SOFTTRANSPARENTSHADOW==1) || (defined(DEPTH_RENDER) && defined(ALPHA_BLENDED_DEPTH))
527var alpha : f32=fragmentOutputs.color.a;
528#endif
529}
530`;B.ShadersStoreWGSL[Dt]||(B.ShadersStoreWGSL[Dt]=ks);
530const At="gaussianSplattingDepthVertexShader",Us=`#include<sceneUboDeclaration>
531#include<meshUboDeclaration>
532attribute splatIndex0: vec4f;attribute splatIndex1: vec4f;attribute splatIndex2: vec4f;attribute splatIndex3: vec4f;attribute position: vec3f;uniform invViewport: vec2f;uniform dataTextureSize: vec2f;uniform focal: vec2f;uniform kernelSize: f32;uniform alpha: f32;var covariancesATexture: texture_2d<f32>;var covariancesBTexture: texture_2d<f32>;var centersTexture: texture_2d<f32>;var colorsTexture: texture_2d<f32>;
533#if IS_COMPOUND
534uniform partWorld: array<mat4x4<f32>,MAX_PART_COUNT>;uniform partVisibility: array<f32,MAX_PART_COUNT>;var partIndicesTexture: texture_2d<f32>;
535#endif
536varying vPosition: vec2f;varying vColor: vec4f;
537#ifdef DEPTH_RENDER
538uniform depthValues: vec2f;varying vDepthMetric: f32;
539#endif
540#include<gaussianSplatting>
541@vertex
542fn main(input : VertexInputs)->FragmentInputs {let splatIndex: f32=getSplatIndex(i32(vertexInputs.position.z+0.5),vertexInputs.splatIndex0,vertexInputs.splatIndex1,vertexInputs.splatIndex2,vertexInputs.splatIndex3);var splat: Splat=readSplat(splatIndex,uniforms.dataTextureSize);var covA: vec3f=splat.covA.xyz;var covB: vec3f=vec3f(splat.covA.w,splat.covB.xy);
543#if IS_COMPOUND
544let splatWorld: mat4x4f=getPartWorld(splat.partIndex);
545#else
546let splatWorld: mat4x4f=mesh.world;
547#endif
548let worldPos: vec4f=splatWorld*vec4f(splat.center.xyz,1.0);vertexOutputs.vPosition=vertexInputs.position.xy;vertexOutputs.vColor=splat.color;vertexOutputs.vColor.w*=uniforms.alpha;
549#if IS_COMPOUND
550vertexOutputs.vColor.w*=uniforms.partVisibility[splat.partIndex];
551#endif
552vertexOutputs.position=gaussianSplatting(vertexInputs.position.xy,worldPos.xyz,vec2f(1.0,1.0),covA,covB,splatWorld,scene.view,scene.projection,uniforms.focal,uniforms.invViewport,uniforms.kernelSize);
553#ifdef DEPTH_RENDER
554#ifdef USE_REVERSE_DEPTHBUFFER
555vertexOutputs.vDepthMetric=((-vertexOutputs.position.z+uniforms.depthValues.x)/(uniforms.depthValues.y));
556#else
557vertexOutputs.vDepthMetric=((vertexOutputs.position.z+uniforms.depthValues.x)/(uniforms.depthValues.y));
558#endif
559#endif
560}`;B.ShadersStoreWGSL[At]||(B.ShadersStoreWGSL[At]=Us);function Xe(n){const o=n.getCaps().maxVertexUniformVectors,r=Math.max(o-40,0),i=Math.floor(r/5);return Math.min(Math.max(i,1),256)}const Hs=128;class Fs extends Kt{constructor(e){super(e),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.IS_COMPOUND=!1,this.MAX_PART_COUNT=Hs,this.rebuild()}}class z extends Qt{constructor(e,t){super(e,t),this.kernelSize=z.KernelSize,this._compensation=z.Compensation,this._isDirty=!1,this._sourceMesh=null,this.backFaceCulling=!1,this.shadowDepthWrapper=z._MakeGaussianSplattingShadowDepthWrapper(t,this.shaderLanguage)}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 o=t._drawWrapper;let r=t.materialDefines;if(r&&this._isDirty&&r.markAsUnprocessed(),o.effect&&this.isFrozen&&o._wasPreviouslyReady&&o._wasPreviouslyUsingInstances===!0)return!0;t.materialDefines||(this._callbackPluginEventGeneric(4,this._eventInfo),r=t.materialDefines=new Fs(this._eventInfo.defineNames));const i=this.getScene();if(this._isReadyForSubMesh(t))return!0;if(this._eventInfo.isReadyForSubMesh=!0,this._eventInfo.defines=r,this._eventInfo.subMesh=t,this._callbackPluginEventIsReadyForSubMesh(this._eventInfo),!this._eventInfo.isReadyForSubMesh||!this._sourceMesh)return!1;const l=i.getEngine(),d=this._sourceMesh;ss(e,i,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,!1,r,void 0,void 0,void 0,this._isVertexOutputInvariant),rs(i,l,this,r,!0,null,!0),is(e,r,!1,!1),(l.version>1||l.isWebGPU)&&(r.SH_DEGREE=d.shDegree),r.IS_COMPOUND=d.isCompound,r.MAX_PART_COUNT=Xe(l);const a=d.material;if(r.COMPENSATION=a&&a.compensation?a.compensation:z.Compensation,r.isDirty){r.markAsProcessed(),i.resetCachedMaterial(),ns(z._Attribs,r);const u=z._Attribs.slice(),m=z._Uniforms.slice(),f=z._Samplers.slice(),_=z._UniformBuffers.slice();os({uniformsNames:m,uniformBuffersNames:_,samplers:f,defines:r}),as(m),this._uniformBufferLayoutBuilt||this.buildUniformLayout(),this._eventInfo.fallbackRank=0,this._eventInfo.defines=r,this._eventInfo.attributes=u,this._eventInfo.uniforms=m,this._eventInfo.samplers=f,this._eventInfo.uniformBuffersNames=_,this._eventInfo.customCode=void 0,this._eventInfo.mesh=e,this._callbackPluginEventGeneric(128,this._eventInfo);
560const h=r.toString(),p=i.getEngine().createEffect("gaussianSplatting",{attributes:u,uniformsNames:m,uniformBuffersNames:_,samplers:f,defines:h,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{},processCodeAfterIncludes:this._eventInfo.customCode,shaderLanguage:this._shaderLanguage,extraInitializationsAsync:async()=>{this._shaderLanguage===1?await Promise.all([Ce(()=>Promise.resolve().then(()=>Ds),void 0),Ce(()=>Promise.resolve().then(()=>Os),void 0)]):await Promise.all([Ce(()=>Promise.resolve().then(()=>ys),void 0),Ce(()=>Promise.resolve().then(()=>Ts),void 0)])}},l);t.setEffect(p,r,this._materialContext)}return!t.effect||!t.effect.isReady()?!1:(r._renderId=i.getRenderId(),o._wasPreviouslyReady=!0,o._wasPreviouslyUsingInstances=!0,this._isDirty=!1,!0)}setSourceMesh(e){this._sourceMesh=e}getSourceMesh(){return this._sourceMesh}static BindEffect(e,t,s){var f,_;const o=s.getEngine(),r=s.activeCamera,i=o.getRenderWidth()*r.viewport.width,l=o.getRenderHeight()*r.viewport.height,d=e.material;if(!d._sourceMesh)return;const a=d._sourceMesh,u=((f=r==null?void 0:r.rigParent)==null?void 0:f.rigCameras.length)||1;t.setFloat2("invViewport",1/(i/u),1/l);let m=1e3;if(r){const h=r.getProjectionMatrix().m[5];r.fovMode==Ue.FOVMODE_VERTICAL_FIXED?m=l*h/2:m=i*h/2}if(t.setFloat2("focal",m,m),t.setFloat("kernelSize",d&&d.kernelSize?d.kernelSize:z.KernelSize),t.setFloat("alpha",d.alpha),s.bindEyePosition(t,"eyePosition",!0),a.covariancesATexture){const h=a.covariancesATexture.getSize();if(t.setFloat2("dataTextureSize",h.width,h.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 p=0;p<((_=a.shTextures)==null?void 0:_.length);p++)t.setTexture(`shTexture${p}`,a.shTextures[p]);if(a.partIndicesTexture){t.setTexture("partIndicesTexture",a.partIndicesTexture);const p=new Float32Array(a.partCount*16);for(let c=0;c<a.partCount;c++)a.getWorldMatrixForPart(c).toArray(p,c*16);t.setMatrices("partWorld",p);const w=[];for(let c=0;c<a.partCount;c++)w.push(a.partVisibility[c]??1);t.setArray("partVisibility",w)}}}bindForSubMesh(e,t,s){const o=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(o,i,s,t.visibility)?(this.bindView(i),this.bindViewProjection(i),z.BindEffect(t,this._activeEffect,o),cs(i,this,o)):o.getEngine()._features.needToAlwaysBindUniformBuffers&&(this._needToBindSceneUbo=!0),ls(o,t,i),this.useLogarithmicDepth&&Jt(r,i,o),this._eventInfo.subMesh=s,this._callbackPluginEventBindForSubMesh(this._eventInfo),this._afterBind(t,this._activeEffect,s)}static _BindEffectUniforms(e,t,s,o){const r=o.getEngine(),i=s.getEffect(),l=o.activeCamera;if(!l)return;e.getMeshUniformBuffer().bindToEffect(i,"Mesh"),s.bindView(i),s.bindViewProjection(i);const d=r.getRenderWidth()*l.viewport.width,a=r.getRenderHeight()*l.viewport.height;i.setFloat2("invViewport",1/d,1/a);let u=1e3;if(l){const h=l.getProjectionMatrix().m[5];l.fovMode==Ue.FOVMODE_VERTICAL_FIXED?u=a*h/2:u=d*h/2}i.setFloat2("focal",u,u),i.setFloat("kernelSize",t&&t.kernelSize?t.kernelSize:z.KernelSize),i.setFloat("alpha",t.alpha);let m,f;if(l.mode===Ue.ORTHOGRAPHIC_CAMERA?(m=!r.useReverseDepthBuffer&&r.isNDCHalfZRange?0:1,f=r.useReverseDepthBuffer&&r.isNDCHalfZRange?0:1):(m=r.useReverseDepthBuffer&&r.isNDCHalfZRange?l.minZ:r.isNDCHalfZRange?0:l.minZ,f=r.useReverseDepthBuffer&&r.isNDCHalfZRange?0:l.maxZ),i.setFloat2("depthValues",m,m+f),e.covariancesATexture){const h=e.covariancesATexture.getSize();if(i.setFloat2("dataTextureSize",h.width,h.height),i.setTexture("covariancesATexture",e.covariancesATexture),i.setTexture("covariancesBTexture",e.covariancesBTexture),i.setTexture("centersTexture",e.centersTexture),i.setTexture("colorsTexture",e.colorsTexture),e.partIndicesTexture){i.setTexture("partIndicesTexture",e.partIndicesTexture);const p=new Float32Array(e.partCount*16);for(let c=0;c<e.partCount;c++)e.getWorldMatrixForPart(c).toArray(p,c*16);i.setMatrices("partWorld",p);const w=[];for(let c=0;c<e.partCount;c++)w.push(e.partVisibility[c]??1);i.setArray("partVisibility",w)}}}makeDepthRenderingMaterial(e,t,s=!1,o=!1){const r=["#define DEPTH_RENDER"];s&&r.push("#define ALPHA_BLENDED_DEPTH"),o&&(r.push("#define IS_COMPOUND"),r.push(`#define MAX_PART_COUNT ${Xe(e.getEngine())}`));const i=new St("gaussianSplattingDepthRender",e,{vertex:"gaussianSplattingDepth",fragment:"gaussianSplattingDepth"},{attributes:z._Attribs,uniforms:z._Uniforms,samplers:z._Samplers,uniformBuffers:z._UniformBuffers,shaderLanguage:t,defines:r,needAlphaBlending:s});return i.onBindObservable.add(l=>{const d=l.material,a=l;z._BindEffectUniforms(a,d,i,e)}),i}static _MakeGaussianSplattingShadowDepthWrapper(e,t){const s=new St("gaussianSplattingDepth",e,{vertex:"gaussianSplattingDepth",fragment:"gaussianSplattingDepth"},{attributes:z._Attribs,uniforms:z._Uniforms,samplers:z._Samplers,uniformBuffers:z._UniformBuffers,shaderLanguage:t}),o=new vs(s,e,{standalone:!0});return s.onBindObservable.add(r=>{const i=r.material,l=r;z._BindEffectUniforms(l,i,s,e)}),o}clone(e){const t=vt.Clone(()=>
560new z(e,this.getScene()),this);return t.id=e,t.name=e,this._clonePlugins(t,""),t}serialize(){const e=super.serialize();return e.customType="BABYLON.GaussianSplattingMaterial",e}getClassName(){return"GaussianSplattingMaterial"}static Parse(e,t,s){const o=vt.Parse(()=>new z(e.name,t),e,t,s);return hs._ParsePlugins(e,o,t,s),o}}z.KernelSize=.3;z.Compensation=!1;z._Attribs=[K.PositionKind,"splatIndex0","splatIndex1","splatIndex2","splatIndex3"];z._Samplers=["covariancesATexture","covariancesBTexture","centersTexture","colorsTexture","shTexture0","shTexture1","shTexture2","partIndicesTexture"];z._UniformBuffers=["Scene","Mesh"];z._Uniforms=["world","view","projection","vFogInfos","vFogColor","logarithmicDepthConstant","invViewport","dataTextureSize","focal","eyePosition","kernelSize","alpha","depthValues","partWorld","partVisibility"];Yt("BABYLON.GaussianSplattingMaterial",z);const Bs=ts,Z={...es,TwoPi:Math.PI*2,Sign:Math.sign,Log2:Math.log2,HCF:Bs};class Ns extends me{get partIndex(){return this._partIndex}constructor(e,t,s,o,r){super(e,t),this.proxiedMesh=o,this._partIndex=r,this.compoundSplatMesh=s,this.updateBoundingInfoFromProxiedMesh(),this.compoundSplatMesh.setWorldMatrixForPart(this.partIndex,this.getWorldMatrix()),this.onAfterWorldMatrixUpdateObservable.add(()=>{this.compoundSplatMesh.setWorldMatrixForPart(this.partIndex,this.getWorldMatrix()),this.updateBoundingInfoFromProxiedMesh()})}updateBoundingInfoFromProxiedMesh(){const e=this.proxiedMesh.getBoundingInfo();this.setBoundingInfo(new jt(e.minimum.clone(),e.maximum.clone()))}getClassName(){return"GaussianSplattingPartProxyMesh"}updatePartIndex(e){this._partIndex=e}get isVisible(){return this.compoundSplatMesh.getPartVisibility(this.partIndex)>0}set isVisible(e){this.compoundSplatMesh.setPartVisibility(this.partIndex,e?1:0)}get visibility(){return this.compoundSplatMesh.getPartVisibility(this.partIndex)}set visibility(e){this.compoundSplatMesh.setPartVisibility(this.partIndex,e)}intersects(e){const t=new fs,s=this.getBoundingInfo();return!s||!e.intersectsSphere(s.boundingSphere)||!e.intersectsBox(s.boundingBox)||(t.hit=!0,t.pickedMesh=this,t.distance=D.Distance(e.origin,s.boundingSphere.center),t.subMeshId=0),t}}const je=typeof _native<"u",oe=je?_native:null,J=(n,e)=>{const t=(1<<e)-1;return(n&t)/t},zt=(n,e)=>{e.x=J(n>>>21,11),e.y=J(n>>>11,10),e.z=J(n,11)},Ws=(n,e)=>{e[0]=J(n>>>24,8)*255,e[1]=J(n>>>16,8)*255,e[2]=J(n>>>8,8)*255,e[3]=J(n,8)*255},Vs=(n,e)=>{const t=1/(Math.sqrt(2)*.5),s=(J(n>>>20,10)-.5)*t,o=(J(n>>>10,10)-.5)*t,r=(J(n,10)-.5)*t,i=Math.sqrt(1-(s*s+o*o+r*r));switch(n>>>30){case 0:e.set(i,s,o,r);break;case 1:e.set(s,i,o,r);break;case 2:e.set(s,o,i,r);break;case 3:e.set(s,o,r,i);break}};var Ot;(function(n){n[n.FLOAT=0]="FLOAT",n[n.INT=1]="INT",n[n.UINT=2]="UINT",n[n.DOUBLE=3]="DOUBLE",n[n.UCHAR=4]="UCHAR",n[n.UNDEFINED=5]="UNDEFINED"})(Ot||(Ot={}));var Rt;(function(n){n[n.MIN_X=0]="MIN_X",n[n.MIN_Y=1]="MIN_Y",n[n.MIN_Z=2]="MIN_Z",n[n.MAX_X=3]="MAX_X",n[n.MAX_Y=4]="MAX_Y",n[n.MAX_Z=5]="MAX_Z",n[n.MIN_SCALE_X=6]="MIN_SCALE_X",n[n.MIN_SCALE_Y=7]="MIN_SCALE_Y",n[n.MIN_SCALE_Z=8]="MIN_SCALE_Z",n[n.MAX_SCALE_X=9]="MAX_SCALE_X",n[n.MAX_SCALE_Y=10]="MAX_SCALE_Y",n[n.MAX_SCALE_Z=11]="MAX_SCALE_Z",n[n.PACKED_POSITION=12]="PACKED_POSITION",n[n.PACKED_ROTATION=13]="PACKED_ROTATION",n[n.PACKED_SCALE=14]="PACKED_SCALE",n[n.PACKED_COLOR=15]="PACKED_COLOR",n[n.X=16]="X",n[n.Y=17]="Y",n[n.Z=18]="Z",n[n.SCALE_0=19]="SCALE_0",n[n.SCALE_1=20]="SCALE_1",n[n.SCALE_2=21]="SCALE_2",n[n.DIFFUSE_RED=22]="DIFFUSE_RED",n[n.DIFFUSE_GREEN=23]="DIFFUSE_GREEN",n[n.DIFFUSE_BLUE=24]="DIFFUSE_BLUE",n[n.OPACITY=25]="OPACITY",n[n.F_DC_0=26]="F_DC_0",n[n.F_DC_1=27]="F_DC_1",n[n.F_DC_2=28]="F_DC_2",n[n.F_DC_3=29]="F_DC_3",n[n.ROT_0=30]="ROT_0",n[n.ROT_1=31]="ROT_1",n[n.ROT_2=32]="ROT_2",n[n.ROT_3=33]="ROT_3",n[n.MIN_COLOR_R=34]="MIN_COLOR_R",n[n.MIN_COLOR_G=35]="MIN_COLOR_G",n[n.MIN_COLOR_B=36]="MIN_COLOR_B",n[n.MAX_COLOR_R=37]="MAX_COLOR_R",n[n.MAX_COLOR_G=38]="MAX_COLOR_G",n[n.MAX_COLOR_B=39]="MAX_COLOR_B",n[n.SH_0=40]="SH_0",n[n.SH_1=41]="SH_1",n[n.SH_2=42]="SH_2",n[n.SH_3=43]="SH_3",n[n.SH_4=44]="SH_4",n[n.SH_5=45]="SH_5",n[n.SH_6=46]="SH_6",n[n.SH_7=47
560]="SH_7",n[n.SH_8=48]="SH_8",n[n.SH_9=49]="SH_9",n[n.SH_10=50]="SH_10",n[n.SH_11=51]="SH_11",n[n.SH_12=52]="SH_12",n[n.SH_13=53]="SH_13",n[n.SH_14=54]="SH_14",n[n.SH_15=55]="SH_15",n[n.SH_16=56]="SH_16",n[n.SH_17=57]="SH_17",n[n.SH_18=58]="SH_18",n[n.SH_19=59]="SH_19",n[n.SH_20=60]="SH_20",n[n.SH_21=61]="SH_21",n[n.SH_22=62]="SH_22",n[n.SH_23=63]="SH_23",n[n.SH_24=64]="SH_24",n[n.SH_25=65]="SH_25",n[n.SH_26=66]="SH_26",n[n.SH_27=67]="SH_27",n[n.SH_28=68]="SH_28",n[n.SH_29=69]="SH_29",n[n.SH_30=70]="SH_30",n[n.SH_31=71]="SH_31",n[n.SH_32=72]="SH_32",n[n.SH_33=73]="SH_33",n[n.SH_34=74]="SH_34",n[n.SH_35=75]="SH_35",n[n.SH_36=76]="SH_36",n[n.SH_37=77]="SH_37",n[n.SH_38=78]="SH_38",n[n.SH_39=79]="SH_39",n[n.SH_40=80]="SH_40",n[n.SH_41=81]="SH_41",n[n.SH_42=82]="SH_42",n[n.SH_43=83]="SH_43",n[n.SH_44=84]="SH_44",n[n.UNDEFINED=85]="UNDEFINED"})(Rt||(Rt={}));class E extends me{get disableDepthSort(){return this._disableDepthSort}set disableDepthSort(e){var t;!this._disableDepthSort&&e?((t=this._worker)==null||t.terminate(),this._worker=null,this._disableDepthSort=!0):this._disableDepthSort&&!e&&(this._disableDepthSort=!1,this._sortIsDirty=!0,this._instanciateWorker())}get viewDirectionFactor(){return D.OneReadOnly}get shDegree(){return this._shDegree}get splatCount(){var e;return(e=this._splatIndex)==null?void 0:e.length}get splatsData(){return this._splatsData}get shData(){return this._shData}get isCompound(){return this._partMatrices.length>0}get partIndices(){return this._partIndices}get partIndicesTexture(){return this._partIndicesTexture}get partVisibility(){return this._partVisibility}get covariancesATexture(){return this._covariancesATexture}
560get covariancesBTexture(){return this._covariancesBTexture}get centersTexture(){return this._centersTexture}get colorsTexture(){return this._colorsTexture}get shTextures(){return this._shTextures}get kernelSize(){return this._material instanceof z?this._material.kernelSize:0}get compensation(){return this._material instanceof z?this._material.compensation:!1}set material(e){this._material=e,this._material.backFaceCulling=!1,this._material.cullBackFaces=!1,e.resetDrawCache()}get material(){return this._material}static _MakeSplatGeometryForMesh(e){const t=new Ze,s=[-2,-2,0,2,-2,0,2,2,0,-2,2,0],o=[0,1,2,0,2,3],r=[],i=[];for(let l=0;l<E._BatchSize;l++){for(let d=0;d<12;d++)d==2||d==5||d==8||d==11?r.push(l):r.push(s[d]);i.push(o.map(d=>d+l*4))}t.positions=r,t.indices=i.flat(),t.applyToMesh(e)}constructor(e,t=null,s=null,o=!1){super(e,s),this._vertexCount=0,this._worker=null,this._modelViewProjectionMatrix=Me.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._shData=null,this._partIndicesTexture=null,this._partIndices=null,this._partMatrices=[],this._partVisibility=[],this._partProxies=new Map,this._textureSize=new te(0,0),this._keepInRam=!1,this._delayedTextureUpdate=null,this._useRGBACovariants=!1,this._material=null,this._tmpCovariances=[0,0,0,0,0,0],this._sortIsDirty=!1,this._shDegree=0,this._cameraViewInfos=new Map,this.viewUpdateThreshold=E._DefaultViewUpdateThreshold,this._disableDepthSort=!1,this._loadingPromise=null,this.subMeshes=[],new Zt(0,0,4*E._BatchSize,0,6*E._BatchSize,this),this.setEnabled(!1),this._useRGBACovariants=!this.getEngine().isWebGPU&&this.getEngine().version===1,this._keepInRam=o,t&&(this._loadingPromise=this.loadFileAsync(t));const r=new z(this.name+"_material",this._scene);r.setSourceMesh(this),this._material=r,this._scene.onCameraRemovedObservable.add(i=>{const l=i.uniqueId;if(this._cameraViewInfos.has(l)){const d=this._cameraViewInfos.get(l);d==null||d.mesh.dispose(),this._cameraViewInfos.delete(l)}})}getLoadingPromise(){return this._loadingPromise}getClassName(){return"GaussianSplattingMesh"}getTotalVertices(){return this._vertexCount}isReady(e=!1){return super.isReady(e,!0)?this._readyToDisplay?!0:(this._postToWorker(!0),!1):!1}_getCameraDirection(e){const t=e.getViewMatrix(),s=e.getProjectionMatrix(),o=j.Matrix[0];t.multiplyToRef(s,o);const r=this.getWorldMatrix(),i=j.Matrix[1];r.multiplyToRef(t,i),r.multiplyToRef(o,this._modelViewProjectionMatrix);const l=j.Vector3[1];return l.set(i.m[2],i.m[6],i.m[10]),l.normalize(),l}_postToWorker(e=!1){var d,a;const s=this._scene.getFrameId();let o=!1;this._cameraViewInfos.forEach(u=>{u.frameIdLastUpdate!==s&&(o=!0)});const r=(d=this._scene.activeCameras)!=null&&d.length?this._scene.activeCameras:[this._scene.activeCamera],i=[];r.forEach(u=>{if(!u)return;const m=u.uniqueId,f=this._cameraViewInfos.get(m);if(f)i.push(f);else{const _=new me(this.name+"_cameraMesh_"+m,this._scene);if(_.reservedDataStore={hidden:!0},_.setEnabled(!1),_.material=this.material,_.material&&_.material instanceof z){const p=_.material;p.getSourceMesh()||p.setSourceMesh(this)}E._MakeSplatGeometryForMesh(_);const h={camera:u,cameraDirection:new D(0,0,0),mesh:_,frameIdLastUpdate:s,splatIndexBufferSet:!1};i.push(h),this._cameraViewInfos.set(m,h)}}),i.sort((u,m)=>u.frameIdLastUpdate-m.frameIdLastUpdate);const l=this._worker||(oe==null?void 0:oe.sortSplats)||this._disableDepthSort;(e||o)&&l&&((a=this._scene.activeCameras)!=null&&a.length||this._scene.activeCamera)&&this._canPostToWorker?i.forEach(u=>{const m=u.camera,f=this._getCameraDirection(m),_=u.cameraDirection,h=D.Dot(f,_);if((e||Math.abs(h-1)>=this.viewUpdateThreshold)&&this._canPostToWorker)if(u.cameraDirection.copyFrom(f),u.frameIdLastUpdate=s,this._canPostToWorker=!1,this._worker){const p=m.getViewMatrix();this._worker.postMessage({worldMatrix:this.getWorldMatrix().m,cameraForward:[p.m[2],p.m[6],p.m[10]],cameraPosition:[m.globalPosition.x,m.globalPosition.y,m.globalPosition.z],depthMix:this._depthMix,cameraId:m.uniqueId},[this._depthMix.buffer])}else oe!=null&&oe.sortSplats&&(oe.sortSplats(this._modelViewProjectionMatrix,this._splatPositions,this._splatIndex,this._scene.useRightHandedSystem),u.splatIndexBufferSet?u.mesh.thinInstanceBufferUpdated("splatIndex"):(u.mesh.thinInstanceSetBuffer("splatIndex",this._splatIndex,16,!1),u.splatIndexBufferSet=!0),this._canPostToWorker=!0,this._readyToDisplay=!0)}):this._disableDepthSort&&(i.forEach(u=>{u.splatIndexBufferSet||(u.mesh.thinInstanceSetBuffer("splatIndex",this._splatIndex,16,!1),u.splatIndexBufferSet=!0)}),this._canPostToWorker=!0,this._readyToDisplay=!0)}render(e,t,s){this._postToWorker(),!this._geometry&&this._cameraViewInfos.size&&(this._geometry=this._cameraViewInfos.values().next().value.mesh.geometry);const o=this._scene.activeCamera.uniqueId,r=this._cameraViewInfos.get(o);if(!r||!r.splatIndexBufferSet)return this;this.onBeforeRenderObservable&&this.onBeforeRenderObservable.notifyObservers(this);const i=r.mesh;i.getWorldMatrix().copyFrom(this.getWorldMatrix());const d=this._scene.getEngine().currentRenderPassId,a=this.getMaterialForRenderPass(d);a&&i.setMaterialForRenderPass(d,a);const u=i.render(e,t,s);return a&&i.setMaterialForRenderPass(d,void 0),this.onAfterRenderObservable&&this.onAfterRenderObservable.notifyObservers(this),u}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;
560case"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,1024*10)),o=`end_header
561`,r=s.indexOf(o);if(r<0||!s)return null;const i=parseInt(/element vertex (\d+)\n/.exec(s)[1]),l=/element chunk (\d+)\n/.exec(s);let d=0;l&&(d=parseInt(l[1]));let a=0,u=0;const m={double:8,int:4,uint:4,float:4,short:2,ushort:2,uchar:1,list:0};let f;(function(g){g[g.Vertex=0]="Vertex",g[g.Chunk=1]="Chunk",g[g.SH=2]="SH",g[g.Unused=3]="Unused"})(f||(f={}));let _=1;const h=[],p=[],w=s.slice(0,r).split(`
562`);let c=0;for(const g of w)if(g.startsWith("property ")){const[,x,S]=g.split(" "),T=E._ValueNameToEnum(S);T!=85&&(T>=84?c=3:T>=64?c=Math.max(c,2):T>=48&&(c=Math.max(c,1)));const O=E._TypeNameToEnum(x);_==1?(p.push({value:T,type:O,offset:u}),u+=m[x]):_==0?(h.push({value:T,type:O,offset:a}),a+=m[x]):_==2&&h.push({value:T,type:O,offset:a}),m[x]||ae.Warn(`Unsupported property type: ${x}.`)}else if(g.startsWith("element ")){const[,x]=g.split(" ");x=="chunk"?_=1:x=="vertex"?_=0:x=="sh"?_=2:_=3}const y=new DataView(e,r+o.length),v=new ArrayBuffer(E._RowOutputLength*i);let C=null,I=0;return c&&(I=((c+1)*(c+1)-1)*3,C=new ArrayBuffer(I*i)),{vertexCount:i,chunkCount:d,rowVertexLength:a,rowChunkLength:u,vertexProperties:h,chunkProperties:p,dataView:y,buffer:v,shDegree:c,shCoefficientCount:I,shBuffer:C}}static _GetCompressedChunks(e,t){if(!e.chunkCount)return null;const s=e.dataView,o=new Array(e.chunkCount);for(let r=0;r<e.chunkCount;r++){const i={min:new D,max:new D,minScale:new D,maxScale:new D,minColor:new D(0,0,0),maxColor:new D(1,1,1)};o[r]=i;for(let l=0;l<e.chunkProperties.length;l++){const d=e.chunkProperties[l];let a;switch(d.type){case 0:a=s.getFloat32(d.offset+t.value,!0);break;default:continue}switch(d.value){case 0:i.min.x=a;break;case 1:i.min.y=a;break;case 2:i.min.z=a;break;case 3:i.max.x=a;break;case 4:i.max.y=a;break;case 5:i.max.z=a;break;case 6:i.minScale.x=a;break;case 7:i.minScale.y=a;break;case 8:i.minScale.z=a;break;case 9:i.maxScale.x=a;break;case 10:i.maxScale.y=a;break;case 11:i.maxScale.z=a;break;case 34:i.minColor.x=a;break;case 35:i.minColor.y=a;break;case 36:i.minColor.z=a;break;case 37:i.maxColor.x=a;break;case 38:i.maxColor.y=a;break;case 39:i.maxColor.z=a;break}}t.value+=e.rowChunkLength}return o}static _GetSplat(e,t,s,o){const r=j.Quaternion[0],i=j.Vector3[0],l=E._RowOutputLength,d=e.buffer,a=e.dataView,u=new Float32Array(d,t*l,3),m=new Float32Array(d,t*l+12,3),f=new Uint8ClampedArray(d,t*l+24,4),_=new Uint8ClampedArray(d,t*l+28,4);let h=null;e.shBuffer&&(h=new Uint8ClampedArray(e.shBuffer,t*e.shCoefficientCount,e.shCoefficientCount));const p=t>>8;let w=255,c=0,y=0,v=0;const C=[];for(let I=0;I<e.vertexProperties.length;I++){const g=e.vertexProperties[I];let x;switch(g.type){case 0:x=a.getFloat32(o.value+g.offset,!0);break;case 1:x=a.getInt32(o.value+g.offset,!0);break;case 2:x=a.getUint32(o.value+g.offset,!0);break;case 3:x=a.getFloat64(o.value+g.offset,!0);break;case 4:x=a.getUint8(o.value+g.offset);break;default:continue}switch(g.value){case 12:{const S=s[p];zt(x,i),u[0]=Z.Lerp(S.min.x,S.max.x,i.x),u[1]=Z.Lerp(S.min.y,S.max.y,i.y),u[2]=Z.Lerp(S.min.z,S.max.z,i.z)}break;case 13:Vs(x,r),w=r.x,c=r.y,y=r.z,v=r.w;break;case 14:{const S=s[p];zt(x,i),m[0]=Math.exp(Z.Lerp(S.minScale.x,S.maxScale.x,i.x)),m[1]=Math.exp(Z.Lerp(S.minScale.y,S.maxScale.y,i.y)),m[2]=Math.exp(Z.Lerp(S.minScale.z,S.maxScale.z,i.z))}break;case 15:{const S=s[p];Ws(x,f),f[0]=Z.Lerp(S.minColor.x,S.maxColor.x,f[0]/255)*255,f[1]=Z.Lerp(S.minColor.y,S.maxColor.y,f[1]/255)*255,f[2]=Z.Lerp(S.minColor.z,S.maxColor.z,f[2]/255)*255}break;case 16:u[0]=x;break;case 17:u[1]=x;break;case 18:u[2]=x;break;case 19:m[0]=Math.exp(x);break;case 20:m[1]=Math.exp(x);break;case 21:m[2]=Math.exp(x);break;case 22:f[0]=x;break;case 23:f[1]=x;break;case 24:f[2]=x;break;case 26:f[0]=(.5+E._SH_C0*x)*255;break;case 27:f[1]=(.5+E._SH_C0*x)*255;break;case 28:f[2]=(.5+E._SH_C0*x)*255;break;case 29:f[3]=(.5+E._SH_C0*x)*255;break;case 25:f[3]=1/(1+Math.exp(-x))*255;break;case 30:w=x;break;case 31:c=x;break;case 32:y=x;break;case 33:v=x;break}if(h&&g.value>=40&&g.value<=84){const S=g.value-40;if(g.type==4&&e.chunkCount){const T=a.getUint8(e.rowChunkLength*e.chunkCount+e.vertexCount*e.rowVertexLength+t*e.shCoefficientCount+S);C[S]=(T*(8/255)-4)*127.5+127.5}else{const T=Z.Clamp(x*127.5+127.5,0,255);C[S]=T}}}if(h){const I=e.shDegree==1?3:e.shDegree==2?8:15;for(let g=0;g<I;g++)h[g*3+0]=C[g],h[g*3+1]=C[g+I],h[g*3+2]=C[g+I*2]}r.set(c,y,v,w),r.normalize(),_[0]=r.w*127.5+127.5,_[1]=r.x*127.5+127.5,_[2]=r.y*127.5+127.5,_[3]=r.z*127.5+127.5,o.value+=e.rowVertexLength}static*ConvertPLYWithSHToSplat(e,t=!1){const s=E.ParseHeader(e);if(!s)return{buffer:e};const o={value:0},r=E._GetCompressedChunks(s,o);for(let l=0;l<s.vertexCount;l++)E._GetSplat(s,l,r,o),l%E._PlyConversionBatchSize===0&&t&&(yield);let i=null;if(s.shDegree&&s.shBuffer){const l=Math.ceil(s.shCoefficientCount/16);let d=0;const a=new Uint8Array(s.shBuffer);i=[];const u=s.vertexCount,m=Ee.LastCreatedEngine;if(m){const f=m.getCaps().maxTextureSize,_=Math.ceil(u/f);for(let h=0;h<l;h++){const p=new Uint8Array(_*f*4*4);i.push(p)}for(let h=0;h<u;h++)for(let p=0;p<s.shCoefficientCount;p++){const w=a[d++],c=Math.floor(p/16),y=i[c],v=p%16,C=h*16;y[v+C]=w}}}return{buffer:s.buffer,sh:i}}static*ConvertPLYToSplat(e,t=!1){const s=E.ParseHeader(e);if(!s)return e;const o={value:0},r=E._GetCompressedChunks(s,o);for(let i=0;i<s.vertexCount;i++)E._GetSplat(s,i,r,o),i%E._PlyConversionBatchSize===0&&t&&(yield);return s.buffer}static async ConvertPLYToSplatAsync(e){return await He(E.ConvertPLYToSplat(e,!0),Fe()
562)}static async ConvertPLYWithSHToSplatAsync(e){return await He(E.ConvertPLYWithSHToSplat(e,!0),Fe())}async loadDataAsync(e){return await this.updateDataAsync(e)}async loadFileAsync(e,t){await Gt(e,t||Ee.LastCreatedScene,{pluginOptions:{splat:{gaussianSplattingMesh:this}}})}dispose(e){var t,s,o,r,i;if((t=this._covariancesATexture)==null||t.dispose(),(s=this._covariancesBTexture)==null||s.dispose(),(o=this._centersTexture)==null||o.dispose(),(r=this._colorsTexture)==null||r.dispose(),this._shTextures)for(const l of this._shTextures)l.dispose();this._partIndicesTexture&&this._partIndicesTexture.dispose(),this._covariancesATexture=null,this._covariancesBTexture=null,this._centersTexture=null,this._colorsTexture=null,this._shTextures=null,this._partIndicesTexture=null,this._partMatrices=[],(i=this._worker)==null||i.terminate(),this._worker=null,this._cameraViewInfos.forEach(l=>{l.mesh.dispose()}),this._partProxies.forEach(l=>{l.dispose()}),this._partProxies.clear(),super.dispose(e,!0)}_copyTextures(e){var t,s,o,r,i,l;if(this._covariancesATexture=(t=e.covariancesATexture)==null?void 0:t.clone(),this._covariancesBTexture=(s=e.covariancesBTexture)==null?void 0:s.clone(),this._centersTexture=(o=e.centersTexture)==null?void 0:o.clone(),this._colorsTexture=(r=e.colorsTexture)==null?void 0:r.clone(),this._partIndicesTexture=(i=e._partIndicesTexture)==null?void 0:i.clone(),e._shTextures){this._shTextures=[];for(const d of e._shTextures)(l=this._shTextures)==null||l.push(d.clone())}}
562clone(e=""){const t=new E(e,void 0,this.getScene());t._copySource(this),t.makeGeometryUnique(),t._vertexCount=this._vertexCount,t._copyTextures(this),t._modelViewProjectionMatrix=Me.Identity(),t._splatPositions=this._splatPositions,t._readyToDisplay=!1,t._disableDepthSort=this._disableDepthSort,t._partMatrices=this._partMatrices.map(o=>o.clone()),t._instanciateWorker();const s=this.getBoundingInfo();return t.getBoundingInfo().reConstruct(s.minimum,s.maximum,this.getWorldMatrix()),t.forcedInstanceCount=this.forcedInstanceCount,t.setEnabled(!0),t}_makeEmptySplat(e,t,s,o){const r=this._useRGBACovariants?4:2;this._splatPositions[4*e+0]=0,this._splatPositions[4*e+1]=0,this._splatPositions[4*e+2]=0,t[e*4+0]=L(0),t[e*4+1]=L(0),t[e*4+2]=L(0),t[e*4+3]=L(0),s[e*r+0]=L(0),s[e*r+1]=L(0),o[e*4+3]=0}_makeSplat(e,t,s,o,r,i,l,d,a){const u=j.Matrix[0],m=j.Matrix[1],f=j.Quaternion[0],_=this._useRGBACovariants?4:2,h=t[8*e+0],p=t[8*e+1]*(a.flipY?-1:1),w=t[8*e+2];this._splatPositions[4*e+0]=h,this._splatPositions[4*e+1]=p,this._splatPositions[4*e+2]=w,l.minimizeInPlaceFromFloats(h,p,w),d.maximizeInPlaceFromFloats(h,p,w),f.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),f.normalize(),f.toRotationMatrix(u),Me.ScalingToRef(t[8*e+3+0]*2,t[8*e+3+1]*2,t[8*e+3+2]*2,m);const c=u.multiplyToRef(m,j.Matrix[0]).m,y=this._tmpCovariances;y[0]=c[0]*c[0]+c[1]*c[1]+c[2]*c[2],y[1]=c[0]*c[4]+c[1]*c[5]+c[2]*c[6],y[2]=c[0]*c[8]+c[1]*c[9]+c[2]*c[10],y[3]=c[4]*c[4]+c[5]*c[5]+c[6]*c[6],y[4]=c[4]*c[8]+c[5]*c[9]+c[6]*c[10],y[5]=c[8]*c[8]+c[9]*c[9]+c[10]*c[10];let v=-1e4;for(let I=0;I<6;I++)v=Math.max(v,Math.abs(y[I]));this._splatPositions[4*e+3]=v;const C=v;o[e*4+0]=L(y[0]/C),o[e*4+1]=L(y[1]/C),o[e*4+2]=L(y[2]/C),o[e*4+3]=L(y[3]/C),r[e*_+0]=L(y[4]/C),r[e*_+1]=L(y[5]/C),i[e*4+0]=s[32*e+24+0],i[e*4+1]=s[32*e+24+1],i[e*4+2]=s[32*e+24+2],i[e*4+3]=s[32*e+24+3]}_updateTextures(e,t,s,o,r){const i=this._getTextureSize(this._vertexCount),l=(_,h,p,w)=>new be(_,h,p,w,this._scene,!1,!1,2,1),d=(_,h,p,w)=>new be(_,h,p,w,this._scene,!1,!1,2,0),a=(_,h,p,w)=>new be(_,h,p,w,this._scene,!1,!1,1,7),u=(_,h,p,w)=>new be(_,h,p,w,this._scene,!1,!1,2,2),m=this._covariancesATexture===null,f=this._textureSize.y!=i.y;if(!m&&!f){this._delayedTextureUpdate={covA:e,covB:t,colors:s,centers:this._splatPositions,sh:o,partIndices:r};const _=Float32Array.from(this._splatPositions),h=this._vertexCount;if(this._worker&&this._worker.postMessage({positions:_,vertexCount:h},[_.buffer]),o&&!this._shTextures){this._shTextures=[];for(const p of o){const w=new Uint32Array(p.buffer),c=a(w,i.x,i.y,11);c.wrapU=0,c.wrapV=0,this._shTextures.push(c)}}if(r&&!this._partIndicesTexture){const p=new Uint8Array(r);this._partIndicesTexture=d(p,i.x,i.y,6),this._partIndicesTexture.wrapU=0,this._partIndicesTexture.wrapV=0}this._worker&&this._worker.postMessage({partIndices:r??null}),this._postToWorker(!0)}else{if(this._textureSize=i,this._covariancesATexture=u(e,i.x,i.y,5),this._covariancesBTexture=u(t,i.x,i.y,this._useRGBACovariants?5:7),this._centersTexture=l(this._splatPositions,i.x,i.y,5),this._colorsTexture=d(s,i.x,i.y,5),o){this._shTextures=[];for(const _ of o){const h=new Uint32Array(_.buffer),p=a(h,i.x,i.y,11);p.wrapU=0,p.wrapV=0,this._shTextures.push(p)}}if(r){const _=new Uint8Array(r);this._partIndicesTexture=d(_,i.x,i.y,6),this._partIndicesTexture.wrapU=0,this._partIndicesTexture.wrapV=0}if(m)this._instanciateWorker();else{if(this._worker){const _=Float32Array.from(this._splatPositions),h=this._vertexCount;this._worker.postMessage({positions:_,vertexCount:h},[_.buffer]),this._worker.postMessage({partIndices:r??null})}this._postToWorker(!0)}}}*_updateData(e,t,s,o,r={flipY:!1}){this._covariancesATexture||(this._readyToDisplay=!1);const i=new Uint8Array(e),l=new Float32Array(i.buffer);this._keepInRam&&(this._splatsData=e,this._shData=s?s.map(y=>new Uint8Array(y)):null);const d=i.length/E._RowOutputLength;d!=this._vertexCount&&this._updateSplatIndexBuffer(d),this._vertexCount=d,this._shDegree=s?s.length:0;const a=this._getTextureSize(d),u=a.x*a.y,m=E.ProgressiveUpdateAmount??a.y,f=a.x*m;this._splatPositions=new Float32Array(4*u);const _=new Uint16Array(u*4),h=new Uint16Array((this._useRGBACovariants?4:2)*u),p=new Uint8Array(u*4);if(o){this._partIndices=new Uint8Array(u),this._partIndices.set(o);let y=-1;for(let v=0;v<o.length;v++)y=Math.max(y,o[v]);this._ensureMinimumPartMatricesLength(y+1)}const w=new D(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),c=new D(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);if(E.ProgressiveUpdateAmount){this._updateTextures(_,h,p,s,this._partIndices?this._partIndices:void 0),this.setEnabled(!0);const y=Math.ceil(a.y/m);for(let I=0;I<y;I++){const g=I*m,x=g*a.x;for(let S=0;S<f;S++)this._makeSplat(x+S,l,i,_,h,p,w,c,r);this._updateSubTextures(this._splatPositions,_,h,p,g,Math.min(m,a.y-g)),this.getBoundingInfo().reConstruct(w,c,this.getWorldMatrix()),t&&(yield)}const v=Float32Array.from(this._splatPositions),C=this._vertexCount;this._worker&&(this._worker.postMessage({positions:v,vertexCount:C},[v.buffer]),this._worker.postMessage({partIndices:o})),this._sortIsDirty=!0}else{const y=d+15&-16;for(let v=0;v<d;v++)this._makeSplat(v,l,i,_,h,p,w,c,r),t&&v%E._SplatBatchSize===0&&(yield);for(let v=d;v<y;v++)this._makeEmptySplat(v,_,h,p);this._updateTextures(_,h,p,s,this._partIndices?this._partIndices:void 0),this.getBoundingInfo().reConstruct(w,c,this.getWorldMatrix()),this.setEnabled(!0),this._sortIsDirty=!0}this._postToWorker(!0)}async updateDataAsync(e,t,s){return await He(this._updateData(e,!0,t,s),Fe())}updateData(e,t,s={flipY:!0},o){$t(this._updateData(e,!1,t,o,s))}refreshBoundingInfo(){return this.thinInstanceRefreshBoundingInfo(!1),this}_updateSplatIndexBuffer(e){const t=e+15&-16;if(!this._splatIndex||e!=this._splatIndex.length){this._splatIndex=new Float32Array(t);for(let s=0;s<t;s++)this._splatIndex[s]=s;this._cameraViewInfos.forEach(s=>{s.mesh.thinInstanceSetBuffer("splatIndex",this._splatIndex,16,!1)})}(!this._depthMix||e!=this._depthMix.length)&&!je&&(this._depthMix=new BigInt64Array(t)),this.forcedInstanceCount=Math.max(t>>4,1)}_updateSubTextures(e,t,s,o,r,i,l,d){const a=(y,v,C,I,g)=>{this.getEngine().updateTextureData(y.getInternalTexture(),v,0,I,C,g,0,0,!1)},u=this._getTextureSize(this._vertexCount),m=this._useRGBACovariants?4:2,f=r*u.x,_=i*u.x,h=new Uint16Array(t.buffer,f*4*Uint16Array.BYTES_PER_ELEMENT,_*4),p=new Uint16Array(s.buffer,f*m*Uint16Array.BYTES_PER_ELEMENT,_*m),w=new Uint8Array(o.buffer,f*4,_*4),c=new Float32Array(e.buffer,f*4*Float32Array.BYTES_PER_ELEMENT,_*4);if(a(this._covariancesATexture,h,u.x,r,i),a(this._covariancesBTexture,p,u.x,r,i),a(this._centersTexture,c,u.x,r,i),a(this._colorsTexture,w,u.x,r,i),l)for(let y=0;y<l.length;y++){const C=new Uint32Array(l[y].buffer,f*4*4,_*4);a(this._shTextures[y],C,u.x,r,i)}if(d&&this._partIndicesTexture){const y=new Uint8Array(d.buffer,f,_);a(this._partIndicesTexture,y,u.x,r,i)}}_instanciateWorker(){var o;if(!this._vertexCount||this._disableDepthSort||(this._updateSplatIndexBuffer(this._vertexCount),je))return;(o=this._worker)==null||o.terminate(),this._worker=new Worker(URL.createObjectURL(new Blob(["(",
562E._CreateWorker.toString(),")(self)"],{type:"application/javascript"})));const e=Float32Array.from(this._splatPositions),t=this._partIndices?new Uint8Array(this._partIndices):null,s=this._partMatrices.map(r=>new Float32Array(r.m));this._worker.postMessage({positions:e},[e.buffer]),this._worker.postMessage({partIndices:t}),this._worker.postMessage({partMatrices:s}),this._worker.onmessage=r=>{const i=this._vertexCount+15&-16;if(r.data.depthMix.length!=i){this._canPostToWorker=!0,this._postToWorker(!0),this._sortIsDirty=!1;return}this._depthMix=r.data.depthMix;const l=r.data.cameraId,d=new Uint32Array(r.data.depthMix.buffer);if(this._splatIndex)for(let u=0;u<i;u++)this._splatIndex[u]=d[2*u];if(this._delayedTextureUpdate){const u=this._getTextureSize(i);this._updateSubTextures(this._delayedTextureUpdate.centers,this._delayedTextureUpdate.covA,this._delayedTextureUpdate.covB,this._delayedTextureUpdate.colors,0,u.y,this._delayedTextureUpdate.sh,this._delayedTextureUpdate.partIndices),this._delayedTextureUpdate=null}const a=this._cameraViewInfos.get(l);a&&(a.splatIndexBufferSet?a.mesh.thinInstanceBufferUpdated("splatIndex"):(a.mesh.thinInstanceSetBuffer("splatIndex",this._splatIndex,16,!1),a.splatIndexBufferSet=!0)),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 o=1;if(t.version===1&&!t.isWebGPU)for(;s*o<e;)o*=2;else o=Math.ceil(e/s);return o>s&&(ae.Error("GaussianSplatting texture size: ("+s+", "+o+"), maxTextureSize: "+s),o=s),new te(s,o)}get partCount(){return this._partMatrices.length}setWorldMatrixForPart(e,t){this._partMatrices[e].copyFrom(t),this._worker&&this._worker.postMessage({partMatrices:this._partMatrices.map(s=>new Float32Array(s.m))}),this._postToWorker(!0)}getWorldMatrixForPart(e){return this._partMatrices[e]??this.getWorldMatrix()}getPartVisibility(e){return this._partVisibility[e]??1}setPartVisibility(e,t){this._partVisibility[e]=Math.max(0,Math.min(1,t))}_ensureMinimumPartMatricesLength(e){this._partMatrices.length<e&&this._resizePartMatrices(e)}_resizePartMatrices(e){if(this._partMatrices.length!=e){if(this._partMatrices.length>e)this._partMatrices=this._partMatrices.slice(0,e),this._partVisibility=this._partVisibility.slice(0,e);else{this.computeWorldMatrix(!0);const t=this.getWorldMatrix();for(;this._partMatrices.length<e;)this._partMatrices.push(t.clone()),this._partVisibility.push(1)}this._worker&&this._worker.postMessage({partMatrices:this._partMatrices.map(t=>new Float32Array(t.m))}),this._postToWorker(!0)}}addPart(e,t=!0){const s=Xe(this._scene.getEngine());if(this.partCount>=s)throw new Error(`Cannot add part, as the maximum part count (${s}) has been reached`);const o=this._vertexCount,r=o==0?new ArrayBuffer(0):this.splatsData,i=this.shData,l=e._vertexCount,d=e.splatsData,a=e.shData,u=Math.max((i==null?void 0:i.length)||0,(a==null?void 0:a.length)||0),m=i!==null&&a!==null;if(!r)throw new Error("To call addPart(), the current mesh must be loaded with keepInRam: true");const f=o*E._RowOutputLength;if(r.byteLength!==f)throw new Error(`splatsDataA size (${r.byteLength}) does not match expected size (${f})`);if(!d)throw new Error("To call addPart(), the other mesh must be loaded with keepInRam: true");const _=l*E._RowOutputLength;if(d.byteLength!==_)throw new Error(`splatsDataB size (${d.byteLength}) does not match expected size (${_})`);if(e.partIndices)throw new Error("To call addPart(), the other mesh must not be a compound");const h=new Uint8Array(r.byteLength+d.byteLength);h.set(new Uint8Array(r),0),h.set(new Uint8Array(d),r.byteLength);let p;if(m){const S=o+l;p=[];for(let T=0;T<u;T++){const O=new Uint8Array(S*16);if(T<((i==null?void 0:i.length)??0)&&O.set(i[T],0),T<((a==null?void 0:a.length)??0)){const P=16*o;O.set(a[T],P)}p.push(O)}}let w=this.partCount,c=this.partIndices;if(c||(c=new Uint8Array(o),w=o>0?1:0),c.length<o)throw new Error(`partIndices length (${c.length}) should be at least vertexCount (${o}) in the current mesh`);const y=new Uint8Array(l).fill(w),v=new Uint8Array(o+l);v.set(c.slice(0,o),0),v.set(y,o),this.updateData(h.buffer,p,{flipY:!1},v);const C=e.getWorldMatrix();this.setWorldMatrixForPart(w,C);
562const I=new Ns(e.name,this.getScene(),this,e,w);t&&e.dispose();const g=new Ft;return C.decompose(I.scaling,g,I.position),I.rotationQuaternion=g,I.computeWorldMatrix(!0),this._partProxies.set(w,I),I}removePart(e){if(e<0||e>=this.partCount)throw new Error(`Part index ${e} is out of range [0, ${this.partCount})`);const t=this.splatsData,s=this.shData,o=this.partIndices;if(!t||!o)throw new Error("Cannot remove part from a non-compound mesh or mesh without keepInRam");const r=this._vertexCount,i=E._RowOutputLength;let l=0;for(let h=0;h<r;h++)o[h]!==e&&l++;const d=new Uint8Array(l*i),a=new Uint8Array(l);let u;if(s){u=[];for(let p=0;p<s.length;p++)u.push(new Uint8Array(l*16))}let m=0;for(let h=0;h<r;h++){const p=o[h];if(p===e)continue;const w=h*i,c=m*i;if(d.set(new Uint8Array(t,w,i),c),a[m]=p>e?p-1:p,s&&u)for(let v=0;v<s.length;v++){const C=h*16,I=m*16;u[v].set(new Uint8Array(s[v].buffer,C,16),I)}m++}this._partMatrices.splice(e,1),this._partVisibility.splice(e,1),this._worker&&this._worker.postMessage({partMatrices:this._partMatrices.map(h=>new Float32Array(h.m))}),this.updateData(d.buffer,u,{flipY:!1},a);const f=this._partProxies.get(e);f&&(f.dispose(),this._partProxies.delete(e));const _=[];this._partProxies.forEach((h,p)=>{p>e&&_.push([p,h])});for(const[h,p]of _)this._partProxies.delete(h),p.updatePartIndex(h-1),this._partProxies.set(h-1,p)}bakeTransformIntoVertices(e){const t=this.splatsData;if(!t)return ae.Error("Cannot bake transform into vertices if splatsData is not kept in RAM"),this;const s=e.m,o=Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]),r=Math.sqrt(s[4]*s[4]+s[5]*s[5]+s[6]*s[6]),i=Math.sqrt(s[8]*s[8]+s[9]*s[9]+s[10]*s[10]),l=.001;if(Math.abs(o-r)>l||Math.abs(o-i)>l)return ae.Error("Gaussian Splatting bakeTransformIntoVertices does not support non-uniform scaling"),this;const d=new Uint8Array(t),a=new Float32Array(t),u=j.Vector3[0];let m;const f=j.Quaternion[0],_=j.Quaternion[1];for(e.decompose(u,_,u),m=0;m<this._vertexCount;m++){const h=m*8;D.TransformCoordinatesFromFloatsToRef(a[h],a[h+1],a[h+2],e,u),a[h]=u.x,a[h+1]=u.y,a[h+2]=u.z,a[h+3]*=o,a[h+4]*=o,a[h+5]*=o,f.set((d[32*m+28+1]-127.5)/127.5,(d[32*m+28+2]-127.5)/127.5,(d[32*m+28+3]-127.5)/127.5,(d[32*m+28+0]-127.5)/127.5),f.normalize(),this.scaling.x<0&&(f.x=-f.x,f.w=-f.w),this.scaling.y<0&&(f.y=-f.y,f.w=-f.w),this.scaling.z<0&&(f.z=-f.z,f.w=-f.w),_.multiplyToRef(f,f),f.normalize(),d[32*m+28+0]=Math.round(f.w*127.5+127.5),d[32*m+28+1]=Math.round(f.x*127.5+127.5),d[32*m+28+2]=Math.round(f.y*127.5+127.5),d[32*m+28+3]=Math.round(f.z*127.5+127.5)}return this.updateData(t,this.shData??void 0,{flipY:!1}),this}}E._RowOutputLength=32;E._SH_C0=.28209479177387814;E._SplatBatchSize=327680;E._PlyConversionBatchSize=32768;E._BatchSize=16;E._DefaultViewUpdateThreshold=1e-4;E.ProgressiveUpdateAmount=0;E._CreateWorker=function(n){let e,t,s,o,r,i;n.onmessage=l=>{if(l.data.positions)e=l.data.positions;else if(l.data.partMatrices)i=l.data.partMatrices;else if(l.data.partIndices!==void 0)r=l.data.partIndices;else{const d=l.data.cameraId,a=l.data.worldMatrix,u=l.data.cameraForward,m=l.data.cameraPosition,f=e.length/4+15&-16;if(!e||!u)throw new Error("positions or camera info is not defined!");t=l.data.depthMix,s=new Uint32Array(t.buffer),o=new Float32Array(t.buffer);for(let p=0;p<f;p++)s[2*p]=p;const _=u[0]*m[0]+u[1]*m[1]+u[2]*m[2],h=p=>[u[0]*p[0]+u[1]*p[1]+u[2]*p[2],u[0]*p[4]+u[1]*p[5]+u[2]*p[6],u[0]*p[8]+u[1]*p[9]+u[2]*p[10],u[0]*p[12]+u[1]*p[13]+u[2]*p[14]-_];if(i&&r){const p=i.map(c=>h(c)),w=r.length;for(let c=0;c<f;c++){const y=r[Math.min(c,w-1)],v=p[y];o[2*c+1]=v[0]*e[4*c+0]+v[1]*e[4*c+1]+v[2]*e[4*c+2]+v[3],s[2*c+1]=~s[2*c+1]}}else{const[p,w,c,y]=h(a);for(let v=0;v<f;v++)o[2*v+1]=p*e[4*v+0]+w*e[4*v+1]+c*e[4*v+2]+y,s[2*v+1]=~s[2*v+1]}t.sort(),n.postMessage({depthMix:t,cameraId:d},[t.buffer])}}};class Gs{constructor(e,t,s,o,r){this.idx=0,this.color=new Y(1,1,1,1),this.position=D.Zero(),this.rotation=D.Zero(),this.uv=new te(0,0),this.velocity=D.Zero(),this.pivot=D.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=D.Zero(),this.idx=e,this._group=t,this.groupId=s,this.idxInGroup=o,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,o=s.maximumWorld.x,r=s.minimumWorld.x,i=s.maximumWorld.y,l=s.minimumWorld.y,d=s.maximumWorld.z,a=s.minimumWorld.z,u=this.position.x+this._pcs.mesh.position.x,m=this.position.y+this._pcs.mesh.position.y,f=this.position.z+this._pcs.mesh.position.z;return r<=u&&u<=o&&l<=m&&m<=i&&a<=f&&f<=d}getRotationMatrix(e){let t;if(this.rotationQuaternion)t=this.rotationQuaternion;else{t=j.Quaternion[0];const s=this.rotation;Ft.RotationYawPitchRollToRef(s.y,s.x,s.z,t)}t.toRotationMatrix(e)}}class Be{get groupID(){return this.groupId}set groupID(e){this.groupId=e}constructor(e,t){this.groupId=e,this._positionFunction=t}}var Pt;(function(n){n[n.Color=2]="Color",n[n.UV=1]="UV",n[n.Random=0]="Random",n[n.Stated=3]="Stated"})(Pt||(Pt={}));class Xs{get positions(){return this._positions32}get colors(){return this._colors32}get uvs(){return this._uvs32}constructor(e,t,s,o){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||Ee.LastCreatedScene,o&&o.updatable!==void 0?this._updatable=o.updatable:this._updatable=!0}async buildMeshAsync(e){return await Promise.all(this._promises),this._isReady=!0,await this._buildMeshAsync(e)}async _buildMeshAsync(e){this.nbParticles===0&&this.addPoints(1),this._positions32=new Float32Array(this._positions),this._uvs32=new Float32Array(this._uvs),this._colors32=new Float32Array(this._colors);const t=new Ze;t.set(this._positions32,K.PositionKind),this._uvs32.length>0&&t.set(this._uvs32,K.UVKind);let s=0;this._colors32.length>0&&(s=1,t.set(this._colors32,K.ColorKind));const o=new me(this.name,this._scene);t.applyToMesh(o,this._updatable),this.mesh=o,this._positions=null,this._uvs=null,this._colors=null,this._updatable||(this.particles.length=0);let r=e;return r||(r=new ps("point cloud material",this._scene),r.emissiveColor=new Te(s,s,s),r.disableLighting=!0,r.pointsCloud=!0,r.pointSize=this._size),o.material=r,o}
562_addParticle(e,t,s,o){const r=new Gs(e,t,s,o,this);return this.particles.push(r),r}_randomUnitVector(e){e.position=new D(Math.random(),Math.random(),Math.random()),e.color=new Y(1,1,1,1)}_getColorIndicesForCoord(e,t,s,o){const r=e._groupImageData,i=s*(o*4)+t*4,l=[i,i+1,i+2,i+3],d=l[0],a=l[1],u=l[2],m=l[3],f=r[d],_=r[a],h=r[u],p=r[m];return new Y(f/255,_/255,h/255,p)}_setPointsColorOrUV(e,t,s,o,r,i,l,d){d=d??0,s&&e.updateFacetData();const u=2*e.getBoundingInfo().boundingSphere.radius;let m=e.getVerticesData(K.PositionKind);const f=e.getIndices(),_=e.getVerticesData(K.UVKind+(d?d+1:"")),h=e.getVerticesData(K.ColorKind),p=D.Zero();e.computeWorldMatrix();const w=e.getWorldMatrix();if(!w.isIdentity()){m=m.slice(0);for(let X=0;X<m.length/3;X++)D.TransformCoordinatesFromFloatsToRef(m[3*X],m[3*X+1],m[3*X+2],w,p),m[3*X]=p.x,m[3*X+1]=p.y,m[3*X+2]=p.z}let c,y,v,C,I,g,x,S,T,O,P,b,H;const V=D.Zero(),A=D.Zero(),k=D.Zero(),W=D.Zero(),R=D.Zero();let G,$,Q,N,M,ee;const re=te.Zero(),de=te.Zero(),xe=te.Zero(),U=te.Zero(),$e=te.Zero();let qe,Le,Ke,Qe,Je,Ye,et,tt,st,rt,it,nt;const pe=ue.Zero(),De=ue.Zero(),ot=ue.Zero(),at=ue.Zero(),ct=ue.Zero();let ie,ve;l=l||0;let _e,ge,F=new ue(0,0,0,1),Ae,ze,lt,ce,ht,ft,ut;const Se=new ds(D.Zero(),new D(1,0,0));let Oe,ye;for(let X=0;X<f.length/3;X++){y=f[3*X],v=f[3*X+1],C=f[3*X+2],I=m[3*y],g=m[3*y+1],x=m[3*y+2],S=m[3*v],T=m[3*v+1],O=m[3*v+2],P=m[3*C],b=m[3*C+1],H=m[3*C+2],V.set(I,g,x),A.set(S,T,O),k.set(P,b,H),A.subtractToRef(V,W),k.subtractToRef(A,R),_&&(G=_[2*y],$=_[2*y+1],Q=_[2*v],N=_[2*v+1],M=_[2*C],ee=_[2*C+1],re.set(G,$),de.set(Q,N),xe.set(M,ee),de.subtractToRef(re,U),xe.subtractToRef(de,$e)),h&&o&&(qe=h[4*y],Le=h[4*y+1],Ke=h[4*y+2],Qe
vendor: 5,399 bytes, line 562
562=h[4*y+3],Je=h[4*v],Ye=h[4*v+1],et=h[4*v+2],tt=h[4*v+3],st=h[4*C],rt=h[4*C+1],it=h[4*C+2],nt=h[4*C+3],pe.set(qe,Le,Ke,Qe),De.set(Je,Ye,et,tt),ot.set(st,rt,it,nt),De.subtractToRef(pe,at),ot.subtractToRef(De,ct));let Re,dt,pt,_t,mt,le,he,we;const xt=new Te(0,0,0),Ie=new Te(0,0,0);let fe,q;for(let Pe=0;Pe<t._groupDensity[X];Pe++)c=this.particles.length,this._addParticle(c,t,this._groupCounter,X+Pe),q=this.particles[c],ie=Math.sqrt(ne(0,1)),ve=ne(0,1),_e=V.add(W.scale(ie)).add(R.scale(ie*ve)),s&&(Ae=e.getFacetNormal(X).normalize().scale(-1),ze=W.clone().normalize(),lt=D.Cross(Ae,ze),ce=ne(0,2*Math.PI),ht=ze.scale(Math.cos(ce)).add(lt.scale(Math.sin(ce))),ce=ne(.1,Math.PI/2),ye=ht.scale(Math.cos(ce)).add(Ae.scale(Math.sin(ce))),Se.origin=_e.add(ye.scale(1e-5)),Se.direction=ye,Se.length=u,Oe=Se.intersectsMesh(e),Oe.hit&&(ut=Oe.pickedPoint.subtract(_e).length(),ft=ne(0,1)*ut,_e.addInPlace(ye.scale(ft)))),q.position=_e.clone(),this._positions.push(q.position.x,q.position.y,q.position.z),o!==void 0?_&&(ge=re.add(U.scale(ie)).add($e.scale(ie*ve)),o?r&&t._groupImageData!==null?(Re=t._groupImgWidth,dt=t._groupImgHeight,fe=this._getColorIndicesForCoord(t,Math.round(ge.x*Re),Math.round(ge.y*dt),Re),q.color=fe,this._colors.push(fe.r,fe.g,fe.b,fe.a)):h?(F=pe.add(at.scale(ie)).add(ct.scale(ie*ve)),q.color=new Y(F.x,F.y,F.z,F.w),this._colors.push(F.x,F.y,F.z,F.w)):(F=pe.set(Math.random(),Math.random(),Math.random(),1),q.color=new Y(F.x,F.y,F.z,F.w),this._colors.push(F.x,F.y,F.z,F.w)):(q.uv=ge.clone(),this._uvs.push(q.uv.x,q.uv.y))):(i?(xt.set(i.r,i.g,i.b),pt=ne(-l,l),_t=ne(-l,l),we=xt.toHSV(),mt=we.r,le=we.g+pt,he=we.b+_t,le<0&&(le=0),le>1&&(le=1),he<0&&(he=0),he>1&&(he=1),Te.HSVtoRGBToRef(mt,le,he,Ie),F.set(Ie.r,Ie.g,Ie.b,1)):F=pe.set(Math.random(),Math.random(),Math.random(),1),q.color=new Y(F.x,F.y,F.z,F.w),this._colors.push(F.x,F.y,F.z,F.w))}}_colorFromTexture(e,t,s){if(e.material===null){ae.Warn(e.name+"has no material."),t._groupImageData=null,this._setPointsColorOrUV(e,t,s,!0,!1);return}const r=e.material.getActiveTextures();if(r.length===0){ae.Warn(e.name+"has no usable texture."),t._groupImageData=null,this._setPointsColorOrUV(e,t,s,!0,!1);return}const i=e.clone();i.setEnabled(!1),this._promises.push(new Promise(l=>{_s.WhenAllReady(r,()=>{let d=t._textureNb;d<0&&(d=0),d>r.length-1&&(d=r.length-1);const a=()=>{t._groupImgWidth=r[d].getSize().width,t._groupImgHeight=r[d].getSize().height,this._setPointsColorOrUV(i,t,s,!0,!0,void 0,void 0,r[d].coordinatesIndex),i.dispose(),l()};t._groupImageData=null;const u=r[d].readPixels();u?u.then(m=>{t._groupImageData=m,a()}):a()})}))}_calculateDensity(e,t,s){let o,r,i,l,d,a,u,m,f,_,h,p;const w=D.Zero(),c=D.Zero(),y=D.Zero(),v=D.Zero(),C=D.Zero(),I=D.Zero();let g;const x=[];let S=0;const T=s.length/3;for(let b=0;b<T;b++)o=s[3*b],r=s[3*b+1],i=s[3*b+2],l=t[3*o],d=t[3*o+1],a=t[3*o+2],u=t[3*r],m=t[3*r+1],f=t[3*r+2],_=t[3*i],h=t[3*i+1],p=t[3*i+2],w.set(l,d,a),c.set(u,m,f),y.set(_,h,p),c.subtractToRef(w,v),y.subtractToRef(c,C),D.CrossToRef(v,C,I),g=.5*I.length(),S+=g,x[b]=S;const O=new Array(T);let P=e;for(let b=T-1;b>0;b--){const H=x[b];if(H===0)O[b]=0;else{const A=(H-x[b-1])/H*P,k=Math.floor(A),W=A-k,R=+(Math.random()<W),G=k+R;O[b]=G,P-=G}}return O[0]=P,O}addPoints(e,t=this._randomUnitVector){const s=new Be(this._groupCounter,t);let o,r=this.nbParticles;for(let i=0;i<e;i++)o=this._addParticle(r,s,this._groupCounter,i),s&&s._positionFunction&&s._positionFunction(o,r,i),this._positions.push(o.position.x,o.position.y,o.position.z),o.color&&this._colors.push(o.color.r,o.color.g,o.color.b,o.color.a),o.uv&&this._uvs.push(o.uv.x,o.uv.y),r++;return this.nbParticles+=e,this._groupCounter++,this._groupCounter}addSurfacePoints(e,t,s,o,r){let i=s||0;(isNaN(i)||i<0||i>3)&&(i=0);const l=e.getVerticesData(K.PositionKind),d=e.getIndices();this._groups.push(this._groupCounter);const a=new Be(this._groupCounter,null);switch(a._groupDensity=this._calculateDensity(t,l,d),i===2?a._textureNb=o||0:o=o||new Y(1,1,1,1),i){case 2:this._colorFromTexture(e,a,!1);break;case 1:this._setPointsColorOrUV(e,a,!1,!1,!1);break;case 0:this._setPointsColorOrUV(e,a,!1);break;case 3:this._setPointsColorOrUV(e,a,!1,void 0,void 0,o,r);break}return this.nbParticles+=t,this._groupCounter++,this._groupCounter-1}addVolumePoints(e,t,s,o,r){let i=s||0;(isNaN(i)||i<0||i>3)&&(i=0);const l=e.getVerticesData(K.PositionKind),d=e.getIndices();this._groups.push(this._groupCounter);const a=new Be(this._groupCounter,null);switch(a._groupDensity=this._calculateDensity(t,l,d),i===2?a._textureNb=o||0:o=o||new Y(1,1,1,1),i){case 2:this._colorFromTexture(e,a,!0);break;case 1:this._setPointsColorOrUV(e,a,!0,!1,!1);break;case 0:this._setPointsColorOrUV(e,a,!0);break;case 3:this._setPointsColorOrUV(e,a,!0,void 0,void 0,o,r);break}return this.nbParticles+=t,this._groupCounter++,this._groupCounter-1}setParticles(e=0,t=this.nbParticles-1,s=!0){var v,C;if(!this._updatable||!this._isReady)return this;this.beforeUpdateParticles(e,t,s);const o=j.Matrix[0],r=this.mesh,i=this._colors32,l=this._positions32,d=this._uvs32,a=j.Vector3,u=a[5].copyFromFloats(1,0,0),m=a[6].copyFromFloats(0,1,0),f=a[7].copyFromFloats(0,0,1),_=a[8].setAll(Number.MAX_VALUE),h=a[9].setAll(-Number.MAX_VALUE);Me.IdentityToRef(o);let p;if((v=this.mesh)!=null&&v.isFacetDataEnabled&&(this._computeBoundingBox=!0),t=t>=this.nbParticles?this.nbParticles-1:t,this._computeBoundingBox&&
562(e!=0||t!=this.nbParticles-1)){const I=(C=this.mesh)==null?void 0:C.getBoundingInfo();I&&(_.copyFrom(I.minimum),h.copyFrom(I.maximum))}let w,c,y;for(let I=e;I<=t;I++){const g=this.particles[I];p=g.idx,w=3*p,c=4*p,y=2*p,this.updateParticle(g);const x=g._rotationMatrix,S=g.position,T=g._globalPosition;if(this._computeParticleRotation&&g.getRotationMatrix(o),g.parentId!==null){const N=this.particles[g.parentId],M=N._rotationMatrix,ee=N._globalPosition,re=S.x*M[1]+S.y*M[4]+S.z*M[7],de=S.x*M[0]+S.y*M[3]+S.z*M[6],xe=S.x*M[2]+S.y*M[5]+S.z*M[8];if(T.x=ee.x+de,T.y=ee.y+re,T.z=ee.z+xe,this._computeParticleRotation){const U=o.m;x[0]=U[0]*M[0]+U[1]*M[3]+U[2]*M[6],x[1]=U[0]*M[1]+U[1]*M[4]+U[2]*M[7],x[2]=U[0]*M[2]+U[1]*M[5]+U[2]*M[8],x[3]=U[4]*M[0]+U[5]*M[3]+U[6]*M[6],x[4]=U[4]*M[1]+U[5]*M[4]+U[6]*M[7],x[5]=U[4]*M[2]+U[5]*M[5]+U[6]*M[8],x[6]=U[8]*M[0]+U[9]*M[3]+U[10]*M[6],x[7]=U[8]*M[1]+U[9]*M[4]+U[10]*M[7],x[8]=U[8]*M[2]+U[9]*M[5]+U[10]*M[8]}}else if(T.x=0,T.y=0,T.z=0,this._computeParticleRotation){const N=o.m;x[0]=N[0],x[1]=N[1],x[2]=N[2],x[3]=N[4],x[4]=N[5],x[5]=N[6],x[6]=N[8],x[7]=N[9],x[8]=N[10]}const P=a[11];g.translateFromPivot?P.setAll(0):P.copyFrom(g.pivot);const b=a[0];b.copyFrom(g.position);const H=b.x-g.pivot.x,V=b.y-g.pivot.y,A=b.z-g.pivot.z;let k=H*x[0]+V*x[3]+A*x[6],W=H*x[1]+V*x[4]+A*x[7],R=H*x[2]+V*x[5]+A*x[8];k+=P.x,W+=P.y,R+=P.z;const G=l[w]=T.x+u.x*k+m.x*W+f.x*R,$=l[w+1]=T.y+u.y*k+m.y*W+f.y*R,Q=l[w+2]=T.z+u.z*k+m.z*W+f.z*R;if(this._computeBoundingBox&&(_.minimizeInPlaceFromFloats(G,$,Q),h.maximizeInPlaceFromFloats(G,$,Q)),this._computeParticleColor&&g.color){const N=g.color,M=this._colors32;M[c]=N.r,M[c+1]=N.g,M[c+2]=N.b,M[c+3]=N.a}if(this._computeParticleTexture&&g.uv){const N=g.uv,M=this._uvs32;M[y]=N.x,M[y+1]=N.y}}return r&&(s&&(this._computeParticleColor&&r.updateVerticesData(K.ColorKind,i,!1,!1),this._computeParticleTexture&&r.updateVerticesData(K.UVKind,d,!1,!1),r.updateVerticesData(K.PositionKind,l,!1,!1)),this._computeBoundingBox&&(r.hasBoundingInfo?r.getBoundingInfo().reConstruct(_,h,r._worldMatrix):r.buildBoundingInfo(_,h,r._worldMatrix))),this.afterUpdateParticles(e,t,s),this}dispose(){var e;(e=this.mesh)==null||e.dispose(),this.vars=null,this._positions=null,this._indices=null,this._normals=null,this._uvs=null,this._colors=null,this._indices32=null,this._positions32=null,this._uvs32=null,this._colors32=null}refreshVisibleSize(){var e;return this._isVisibilityBoxLocked||(e=this.mesh)==null||e.refreshBoundingInfo(),this}setVisibilityBox(e){if(!this.mesh)return;const t=e/2;this.mesh.buildBoundingInfo(new D(-t,-t,-t),new D(t,t,t))}get isAlwaysVisible(){return this._alwaysVisible}set isAlwaysVisible(e){this.mesh&&(this._alwaysVisible=e,this.mesh.alwaysSelectAsActiveMesh=e)}set computeParticleRotation(e){this._computeParticleRotation=e}set computeParticleColor(e){this._computeParticleColor=e}set computeParticleTexture(e){this._computeParticleTexture=e}get computeParticleColor(){return this._computeParticleColor}get computeParticleTexture(){return this._computeParticleTexture}set computeBoundingBox(e){this._computeBoundingBox=e}get computeBoundingBox(){return this._computeBoundingBox}initParticles(){}recycleParticle(e){return e}updateParticle(e){return e}beforeUpdateParticles(e,t,s){}afterUpdateParticles(e,t,s){}}function js(n,e,t){const s=new Uint8Array(n),o=new Uint32Array(n.slice(0,12)),r=o[2],i=s[12],l=s[13],d=s[14],a=s[15],u=o[1];if(a||o[0]!=1347635022||u!=2&&u!=3)return new Promise(x=>{x({mode:3,data:f,hasVertexColors:!1})});const m=32,f=new ArrayBuffer(m*r),_=1/(1<<l),h=new Int32Array(1),p=new Uint8Array(h.buffer),w=function(x,S){return p[0]=x[S+0],p[1]=x[S+1],p[2]=x[S+2],p[3]=x[S+2]&128?255:0,h[0]*_};let c=16;const y=new Float32Array(f),v=new Float32Array(f),C=new Uint8ClampedArray(f),I=new Uint8ClampedArray(f);for(let x=0;x<r;x++)y[x*8+0]=w(s,c+0),y[x*8+1]=w(s,c+3),y[x*8+2]=w(s,c+6),c+=9;const g=.282;for(let x=0;x<r;x++){for(let S=0;S<3;S++){const O=(s[c+r+x*3+S]-127.5)/(.15*255);C[x*32+24+S]=Z.Clamp((.5+g*O)*255,0,255)}C[x*32+24+3]=s[c+x]}c+=r*4;for(let x=0;x<r;x++)v[x*8+3+0]=Math.exp(s[c+0]/16-10),v[x*8+3+1]=Math.exp(s[c+1]/16-10),v[x*8+3+2]=Math.exp(s[c+2]/16-10),c+=3;if(u>=3){const x=Math.SQRT1_2;for(let S=0;S<r;S++){const T=[s[c+0],s[c+1],s[c+2],s[c+3]],O=T[0]+(T[1]<<8)+(T[2]<<16)+(T[3]<<24),P=511,b=[],H=O>>>30;let V=O,A=0;for(let R=3;R>=0;--R)if(R!==H){const G=V&P,$=V>>>9&1;V=V>>>10,b[R]=x*(G/P),$===1&&(b[R]=-b[R]),A+=b[R]*b[R]}const k=1-A;b[H]=Math.sqrt(Math.max(k,0));const W=[3,0,1,2];for(let R=0;R<4;R++)I[S*32+28+R]=Math.round(127.5+b[W[R]]*127.5);c+=4}}else for(let x=0;x<r;x++){const S=s[c+0],T=s[c+1],O=s[c+2],P=S/127.5-1,b=T/127.5-1,H=O/127.5-1;I[x*32+28+1]=S,I[x*32+28+2]=T,I[x*32+28+3]=O;const V=1-(P*P+b*b+H*H);I[x*32+28+0]=127.5+Math.sqrt(V<0?0:V)*127.5,c+=3}if(i){const S=((i+1)*(i+1)-1)*3,T=Math.ceil(S/16);let O=c;const P=[],H=e.getEngine().getCaps().maxTextureSize,V=Math.ceil(r/H);for(let A=0;A<T;A++){const k=new Uint8Array(V*H*4*4);P.push(k)}for(let A=0;A<r;A++)for(let k=0;k<S;k++){const W=s[O++],R=Math.floor(k/16),G=P[R],$=k%16,Q=A*16;G[$+Q]=W}return new Promise(A=>{A({mode:0,data:f,hasVertexColors:!1,sh:P,trainedWithAntialiasing:!!d})})}return new Promise(x=>{x({mode:0,data:f,hasVertexColors:!1,trainedWithAntialiasing:!!d})})}const kt=.28209479177387814;async function Ut(n,e,t){return await new Promise((o,r)=>{const i=t.createCanvasImage();if(!i)throw new Error("Failed to create ImageBitmap");i.onload=()=>{try{const d=t.createCanvas(i.width,i.height);if(!d)throw new Error("Failed to create canvas");const a=d.getContext("2d");if(!a)throw new Error("Failed to get 2D context");a.drawImage(i,0,0);const u=a.getImageData(0,0,d.width,d.height);o({bits:new Uint8Array(u.data.buffer),width:u.width})}catch(d){r(`Error loading image ${i.src} with exception: ${d}`)}},i.onerror=d=>{r(`Error loading image ${i.src} with exception: ${d}`)},i.crossOrigin="anonymous";let l;if(typeof n=="string"){if(!e)throw new Error("filename is required when using a URL");i.src=n+e}else{const d=new Blob([n],{type:"image/webp"});l=URL.createObjectURL(d),i.src=l}})}async function Zs(n,e,t){const s=n.count?n.count:n.means.shape[0],o=32,r=new ArrayBuffer(o*s),i=new Float32Array(r),l=new Float32Array(r),d=new Uint8ClampedArray(r),a=new Uint8ClampedArray(r),u=c=>
562Math.sign(c)*(Math.exp(Math.abs(c))-1),m=e[0].bits,f=e[1].bits;if(!Array.isArray(n.means.mins)||!Array.isArray(n.means.maxs))throw new Error("Missing arrays in SOG data.");for(let c=0;c<s;c++){const y=c*4;for(let v=0;v<3;v++){const C=n.means.mins[v],I=n.means.maxs[v],g=f[y+v],x=m[y+v],S=g<<8|x,T=Z.Lerp(C,I,S/65535);i[c*8+v]=u(T)}}const _=e[2].bits;if(n.version===2){if(!n.scales.codebook)throw new Error("Missing codebook in SOG version 2 scales data.");for(let c=0;c<s;c++){const y=c*4;for(let v=0;v<3;v++){const C=n.scales.codebook[_[y+v]],I=Math.exp(C);l[c*8+3+v]=I}}}else{if(!Array.isArray(n.scales.mins)||!Array.isArray(n.scales.maxs))throw new Error("Missing arrays in SOG scales data.");for(let c=0;c<s;c++){const y=c*4;for(let v=0;v<3;v++){const C=_[y+v],I=Z.Lerp(n.scales.mins[v],n.scales.maxs[v],C/255),g=Math.exp(I);l[c*8+3+v]=g}}}const h=e[4].bits;if(n.version===2){if(!n.sh0.codebook)throw new Error("Missing codebook in SOG version 2 sh0 data.");for(let c=0;c<s;c++){const y=c*4;for(let v=0;v<3;v++){const C=.5+n.sh0.codebook[h[y+v]]*kt;d[c*32+24+v]=Math.max(0,Math.min(255,Math.round(255*C)))}d[c*32+24+3]=h[y+3]}}else{if(!Array.isArray(n.sh0.mins)||!Array.isArray(n.sh0.maxs))throw new Error("Missing arrays in SOG sh0 data.");for(let c=0;c<s;c++){const y=c*4;for(let v=0;v<4;v++){const C=n.sh0.mins[v],I=n.sh0.maxs[v],g=h[y+v],x=Z.Lerp(C,I,g/255);let S;v<3?S=.5+x*kt:S=1/(1+Math.exp(-x)),d[c*32+24+v]=Math.max(0,Math.min(255,Math.round(255*S)))}}}const p=c=>(c/255-.5)*2/Math.SQRT2,w=e[3].bits;for(let c=0;c<s;c++){const y=w[c*4+0],v=w[c*4+1],C=w[c*4+2],I=w[c*4+3],g=p(y),x=p(v),S=p(C),T=I-252,O=g*g+x*x+S*S,P=Math.sqrt(Math.max(0,1-O));let b;switch(T){case 0:b=[P,g,x,S];break;case 1:b=[g,P,x,S];break;case 2:b=[g,x,P,S];break;case 3:b=[g,x,S,P];break;default:throw new Error("Invalid quaternion mode")}a[c*32+28+0]=b[0]*127.5+127.5,a[c*32+28+1]=b[1]*127.5+127.5,a[c*32+28+2]=b[2]*127.5+127.5,a[c*32+28+3]=b[3]*127.5+127.5}if(n.shN){const c=[0,3,8,15],y=n.shN.bands?c[n.shN.bands]:n.shN.shape[1]/3,v=e[5].bits,C=e[6].bits,I=e[5].width,g=y*3,x=Math.ceil(g/16),S=[],O=t.getEngine().getCaps().maxTextureSize,P=Math.ceil(s/O);for(let b=0;b<x;b++){const H=new Uint8Array(P*O*4*4);S.push(H)}if(n.version===2){if(!n.shN.codebook)throw new Error("Missing codebook in SOG version 2 shN data.");for(let b=0;b<s;b++){const H=C[b*4+0]+(C[b*4+1]<<8),V=H%64*y,A=Math.floor(H/64);for(let k=0;k<y;k++)for(let W=0;W<3;W++){const R=k*3+W,G=Math.floor(R/16),$=S[G],Q=R%16,N=b*16,M=n.shN.codebook[v[(V+k)*4+W+A*I*4]]*127.5+127.5;$[Q+N]=Math.max(0,Math.min(255,M))}}}else for(let b=0;b<s;b++){const H=C[b*4+0]+(C[b*4+1]<<8),V=H%64*y,A=Math.floor(H/64),k=n.shN.mins,W=n.shN.maxs;for(let R=0;R<3;R++)for(let G=0;G<y/3;G++){const $=G*3+R,Q=Math.floor($/16),N=S[Q],M=$%16,ee=b*16,re=Z.Lerp(k,W,v[(V+G)*4+R+A*I*4]/255)*127.5+127.5;N[M+ee]=Math.max(0,Math.min(255,re))}}return await new Promise(b=>{b({mode:0,data:r,hasVertexColors:!1,sh:S})})}return await new Promise(c=>{c({mode:0,data:r,hasVertexColors:!1})})}async function Ht(n,e,t){let s,o;if(n instanceof Map){o=n;const l=o.get("meta.json");if(!l)throw new Error("meta.json not found in files Map");s=JSON.parse(new TextDecoder().decode(l))}else s=n;const r=[...s.means.files,...s.scales.files,...s.quats.files,...s.sh0.files];s.shN&&r.push(...s.shN.files);const i=await Promise.all(r.map(async l=>{if(o&&o.has(l)){const d=o.get(l);return await Ut(d,l,t.getEngine())}else return await Ut(e,l,t.getEngine())}));return await Zs(s,i,t)}class se{constructor(e=se._DefaultLoadingOptions){this.name=ke.name,this._assetContainer=null,this.extensions=ke.extensions,this._loadingOptions=e}createPlugin(e){return new se(e[ke.name])}async importMeshAsync(e,t,s,o,r,i){return await this._parseAsync(e,t,s,o).then(l=>({meshes:l,particleSystems:[],skeletons:[],animationGroups:[],transformNodes:[],geometries:[],lights:[],spriteManagers:[]}))}static _BuildPointCloud(e,t){if(!t.byteLength)return!1;const s=new Uint8Array(t),o=new Float32Array(t),r=32,i=s.length/r,l=function(d,a){const u=o[8*a+0],m=o[8*a+1],f=o[8*a+2];d.position=new D(u,m,f);const _=s[r*a+24+0]/255,h=s[r*a+24+1]/255,p=s[r*a+24+2]/255;d.color=new Y(_,h,p,1)};return e.addPoints(i,l),!0}static _BuildMesh(e,t){const s=new me("PLYMesh",e),o=new Uint8Array(t.data),r=new Float32Array(t.data),i=32,l=o.length/i,d=[],a=new Ze;for(let u=0;u<l;u++){const m=r[8*u+0],f=r[8*u+1],_=r[8*u+2];d.push(m,f,_)}if(t.hasVertexColors){const u=new Float32Array(l*4);for(let m=0;m<l;
562m++){const f=o[i*m+24+0]/255,_=o[i*m+24+1]/255,h=o[i*m+24+2]/255;u[m*4+0]=f,u[m*4+1]=_,u[m*4+2]=h,u[m*4+3]=1}a.colors=u}return a.positions=d,a.indices=t.faces,a.applyToMesh(s),s}async _unzipWithFFlateAsync(e){let t=this._loadingOptions.fflate;t||(typeof window.fflate>"u"&&await ms.LoadScriptAsync(this._loadingOptions.deflateURL??"https://unpkg.com/fflate/umd/index.js"),t=window.fflate);const{unzipSync:s}=t,o=s(e),r=new Map;for(const[i,l]of Object.entries(o))r.set(i,l);return r}_parseAsync(e,t,s,o){const r=[],i=f=>{t._blockEntityCollection=!!this._assetContainer;const _=this._loadingOptions.gaussianSplattingMesh??new E("GaussianSplatting",null,t,this._loadingOptions.keepInRam);_._parentContainer=this._assetContainer,r.push(_),_.updateData(f.data,f.sh,{flipY:!1}),_.scaling.y*=-1,_.computeWorldMatrix(!0),t._blockEntityCollection=!1};if(typeof s=="string"){const f=JSON.parse(s);if(f&&f.means&&f.scales&&f.quats&&f.sh0)return new Promise(_=>{Ht(f,o,t).then(h=>{i(h),_(r)}).catch(()=>{throw new Error("Failed to parse SOG data.")})})}const l=s instanceof ArrayBuffer?new Uint8Array(s):s;if(l[0]===80&&l[1]===75)return new Promise(f=>{this._unzipWithFFlateAsync(l).then(_=>{Ht(_,o,t).then(h=>{i(h),f(r)}).catch(()=>{throw new Error("Failed to parse SOG zip data.")})})});const d=f=>{se._ConvertPLYToSplat(s).then(async _=>{switch(t._blockEntityCollection=!!this._assetContainer,_.mode){case 0:{const h=this._loadingOptions.gaussianSplattingMesh??new E("GaussianSplatting",null,t,this._loadingOptions.keepInRam);switch(h._parentContainer=this._assetContainer,r.push(h),h.updateData(_.data,_.sh,{flipY:!1}),h.scaling.y*=-1,_.chirality==="RightHanded"&&(h.scaling.y*=-1),_.upAxis){case"X":h.rotation=new D(0,0,Math.PI/2);break;case"Y":h.rotation=new D(0,0,Math.PI);break;case"Z":h.rotation=new D(-Math.PI/2,Math.PI,0);break}h.computeWorldMatrix(!0)}break;case 1:{const h=new Xs("PointCloud",1,t);se._BuildPointCloud(h,_.data)?await h.buildMeshAsync().then(p=>{r.push(p)}):h.dispose()}break;case 2:if(_.faces)r.push(se._BuildMesh(t,_));else throw new Error("PLY mesh doesn't contain face informations.");break;default:throw new Error("Unsupported Splat mode")}t._blockEntityCollection=!1,this.applyAutoCameraLimits(_,t),f(r)})};if(l[0]!==31||l[1]!==139)return new Promise(f=>{d(f)});const a=new ReadableStream({start(f){f.enqueue(new Uint8Array(s)),f.close()}}),u=new DecompressionStream("gzip"),m=a.pipeThrough(u);return new Promise(f=>{new Response(m).arrayBuffer().then(_=>{js(_,t,this._loadingOptions).then(h=>{t._blockEntityCollection=!!this._assetContainer;const p=this._loadingOptions.gaussianSplattingMesh??new E("GaussianSplatting",null,t,this._loadingOptions.keepInRam);if(h.trainedWithAntialiasing){const w=p.material;w.kernelSize=.1,w.compensation=!0}p._parentContainer=this._assetContainer,r.push(p),p.updateData(h.data,h.sh,{flipY:!1}),this._loadingOptions.flipY||(p.scaling.y*=-1,p.computeWorldMatrix(!0)),t._blockEntityCollection=!1,this.applyAutoCameraLimits(h,t),f(r)})}).catch(()=>{d(f)})})}applyAutoCameraLimits(e,t){var s;if(!this._loadingOptions.disableAutoCameraLimits&&(e.safeOrbitCameraRadiusMin!==void 0||e.safeOrbitCameraElevationMinMax!==void 0)&&((s=t.activeCamera)==null?void 0:s.getClassName())==="ArcRotateCamera"){const o=t.activeCamera;e.safeOrbitCameraElevationMinMax&&(o.lowerBetaLimit=Math.PI*.5-e.safeOrbitCameraElevationMinMax[1],o.upperBetaLimit=Math.PI*.5-e.safeOrbitCameraElevationMinMax[0]),e.safeOrbitCameraRadiusMin&&(o.lowerRadiusLimit=e.safeOrbitCameraRadiusMin)}}loadAssetContainerAsync(e,t,s){const o=new us(e);return this._assetContainer=o,this.importMeshAsync(null,e,t,s).then(r=>{for(const i of r.meshes)o.meshes.push(i);return this._assetContainer=null,o}).catch(r=>{throw this._assetContainer=null,r})}loadAsync(e,t,s){return this.importMeshAsync(null,e,t,s).then(()=>{})}static _ConvertPLYToSplat(e){const t=new Uint8Array(e),s=new TextDecoder().decode(t.slice(0,1024*10)),o=`end_header
563`,r=s.indexOf(o);if(r<0||!s)return new Promise(I=>{I({mode:0,data:e,rawSplat:!0})});const i=parseInt(/element vertex (\d+)\n/.exec(s)[1]),l=/element face (\d+)\n/.exec(s);let d=0;l&&(d=parseInt(l[1]));const a=/element chunk (\d+)\n/.exec(s);let u=0;a&&(u=parseInt(a[1]));let m=0,f=0;const _={double:8,int:4,uint:4,float:4,short:2,ushort:2,uchar:1,list:0},h={Vertex:0,Chunk:1,SH:2,Float_Tuple:3,Float:4,Uchar:5};let p=h.Chunk;const w=[],c=s.slice(0,r).split(`
564`),y={};for(const I of c)if(I.startsWith("property ")){const[,g,x]=I.split(" ");if(p==h.Chunk)f+=_[g];else if(p==h.Vertex)w.push({name:x,type:g,offset:m}),m+=_[g];else if(p==h.SH)w.push({name:x,type:g,offset:m});else if(p==h.Float_Tuple){const S=new DataView(e,f,_.float*2);y.safeOrbitCameraElevationMinMax=[S.getFloat32(0,!0),S.getFloat32(4,!0)]}else if(p==h.Float){const S=new DataView(e,f,_.float);y.safeOrbitCameraRadiusMin=S.getFloat32(0,!0)}else if(p==h.Uchar){const S=new DataView(e,f,_.uchar);x=="up_axis"?y.upAxis=S.getUint8(0)==0?"X":S.getUint8(0)==1?"Y":"Z":x=="chirality"&&(y.chirality=S.getUint8(0)==0?"LeftHanded":"RightHanded")}_[g]||ae.Warn(`Unsupported property type: ${g}.`)}else if(I.startsWith("element ")){const[,g]=I.split(" ");
564g=="chunk"?p=h.Chunk:g=="vertex"?p=h.Vertex:g=="sh"?p=h.SH:g=="safe_orbit_camera_elevation_min_max_radians"?p=h.Float_Tuple:g=="safe_orbit_camera_radius_min"?p=h.Float:(g=="up_axis"||g=="chirality")&&(p=h.Uchar)}const v=m,C=f;return E.ConvertPLYWithSHToSplatAsync(e).then(async I=>{const g=new DataView(e,r+o.length);let x=C*u+v*i;const S=[];if(d)for(let A=0;A<d;A++){const k=g.getUint8(x);if(k==3){x+=1;for(let W=0;W<k;W++){const R=g.getUint32(x+(2-W)*4,!0);S.push(R)}x+=12}}if(u)return await new Promise(A=>{A({mode:0,data:I.buffer,sh:I.sh,faces:S,hasVertexColors:!1,compressed:!0,rawSplat:!1})});let T=0,O=0;const P=["x","y","z","scale_0","scale_1","scale_2","opacity","rot_0","rot_1","rot_2","rot_3"],b=["red","green","blue","f_dc_0","f_dc_1","f_dc_2"];for(let A=0;A<w.length;A++){const k=w[A];P.includes(k.name)&&T++,b.includes(k.name)&&O++}const H=T==P.length&&O==3,V=d?2:H?0:1;return await new Promise(A=>{A({...y,mode:V,data:I.buffer,sh:I.sh,faces:S,hasVertexColors:!!O,compressed:!1,rawSplat:!1})})})}}se._DefaultLoadingOptions={keepInRam:!1,flipY:!1};Xt(new se);export{se as SPLATFileLoader};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.