@splnlss/3d-story-viewer 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/assets/viewer/{geojson.worker-QNi-d8kU.js → geojson.worker-D3uq_RbR.js} +1 -1
- package/build/assets/viewer/spark-a62bdfe36d20.wasm +0 -0
- package/build/assets/viewer/{spark-worker-5ec8a483b87c.js → spark-worker-c1a6c013b888.js} +194 -43
- package/build/computeElevation.cjs +1 -1
- package/build/computeElevation.js +2 -2
- package/build/index-D87IZDc6.cjs +1 -0
- package/build/{index-CsZhc21b.js → index-Hz3jbrou.js} +1302 -829
- package/build/main-Bdopx4KL.js +15819 -0
- package/build/main-CaYKxosA.cjs +1 -0
- package/build/spark.module-B1FWS-vq.js +18168 -0
- package/build/spark.module-BUdzSHba.cjs +1 -0
- package/build/types/src/viewer/ContentLayer/GaussianSplatLayer.d.ts +4 -6
- package/build/types/src/viewer/ContentLayer/MeshLayer.d.ts +1 -1
- package/build/types/src/viewer/ContentLayer/TilesLayer.d.ts +4 -2
- package/build/types/src/viewer/ContentLayer/gaussianSplatUtils.d.ts +2 -1
- package/build/types/src/viewer/ContentLayer/index.d.ts +5 -3
- package/build/types/src/viewer/EnvironmentControls.d.ts +18 -12
- package/build/types/src/viewer/GlobeControls.d.ts +9 -6
- package/build/types/src/viewer/GlobeManager.d.ts +2 -1
- package/build/types/src/viewer/Sky.d.ts +5 -2
- package/build/types/src/viewer/TransitionControls.d.ts +2 -1
- package/build/types/src/viewer/index.d.ts +48 -18
- package/build/types/src/viewer/loadSpark.d.ts +1 -0
- package/build/types/src/viewer/mods.d.ts +1 -0
- package/build/types/src/viewer/shaders/chunks.d.ts +1 -0
- package/build/types/src/viewer/surfacePicking.d.ts +31 -0
- package/build/types/src/viewer/utils.d.ts +6 -4
- package/build/types/src/workers/geojson.worker.d.ts +2 -2
- package/build/types/utils/elevation/gltf.d.ts +2 -1
- package/build/viewer.cjs +1 -1
- package/build/viewer.js +5 -28044
- package/package.json +18 -16
- package/build/assets/viewer/spark-8b93f8c03d97.wasm +0 -0
- package/build/assets/viewer/spark-old-worker-932b4a2c87ca.js +0 -8168
- package/build/assets/viewer/spark-worker-015de49d2d00.wasm +0 -0
- package/build/index-wUFLgXbb.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-D87IZDc6.cjs"),e=require("./main-CaYKxosA.cjs"),n=-12,a=Math.exp(n),s=Math.exp(9),r=Math.exp(-30),i=2048,o=2048;var l=(t=>(t.PLY="ply",t.SPZ="spz",t.SPLAT="splat",t.KSPLAT="ksplat",t.PCSOGS="pcsogs",t.PCSOGSZIP="pcsogszip",t.RAD="rad",t))(l||{});const u={rgbMin:0,rgbMax:1,lnScaleMin:n,lnScaleMax:9,sh1Max:1,sh2Max:1,sh3Max:1,lodOpacity:!1},c=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_SPLAT_ENCODING:u,LN_SCALE_MAX:9,LN_SCALE_MIN:n,LN_SCALE_ZERO:-30,SCALE_MAX:s,SCALE_MIN:a,SCALE_ZERO:r,SPLAT_TEX_DEPTH:2048,SPLAT_TEX_DEPTH_BITS:11,SPLAT_TEX_DEPTH_MASK:2047,SPLAT_TEX_HEIGHT:o,SPLAT_TEX_HEIGHT_BITS:11,SPLAT_TEX_HEIGHT_MASK:2047,SPLAT_TEX_LAYER_BITS:22,SPLAT_TEX_MIN_HEIGHT:1,SPLAT_TEX_WIDTH:i,SPLAT_TEX_WIDTH_BITS:11,SPLAT_TEX_WIDTH_MASK:2047,SplatFileType:l,USE_COMPILED_PARSER_FUNCTION:!0,WASM_SPLAT_SORT:!0},Symbol.toStringTag,{value:"Module"}));function p(t){return"bool"===t||"bvec2"===t||"bvec3"===t||"bvec4"===t}function d(t){return"int"===t||"uint"===t||"float"===t}function h(t){return"int"===t||"ivec2"===t||"ivec3"===t||"ivec4"===t}function x(t){return"uint"===t||"uvec2"===t||"uvec3"===t||"uvec4"===t}function f(t){return"float"===t||"vec2"===t||"vec3"===t||"vec4"===t}function m(t){return"mat2"===t||"mat2x2"===t||"mat2x3"===t||"mat2x4"===t||"mat3"===t||"mat3x2"===t||"mat3x3"===t||"mat3x4"===t||"mat4"===t||"mat4x2"===t||"mat4x3"===t||"mat4x4"===t}function y(t){return f(t)||m(t)}function g(t){return"vec2"===t||"ivec2"===t||"uvec2"===t}function v(t){return"vec3"===t||"ivec3"===t||"uvec3"===t}function w(t){return"vec4"===t||"ivec4"===t||"uvec4"===t}function b(t){return"mat2"===t||"mat2x2"===t}function S(t){return"mat3"===t||"mat3x3"===t}function T(t){return"mat4"===t||"mat4x4"===t}function _(t){switch(t){case"vec2":case"vec3":case"vec4":return"float";case"ivec2":case"ivec3":case"ivec4":return"int";case"uvec2":case"uvec3":case"uvec4":return"uint";default:throw new Error(`Invalid vector type: ${t}`)}}function M(t){switch(t){case"vec2":case"ivec2":case"uvec2":return 2;case"vec3":case"ivec3":case"uvec3":return 3;case"vec4":case"ivec4":case"uvec4":return 4;default:throw new Error(`Invalid vector type: ${t}`)}}function k(t){if(d(t))return"uint";if(g(t))return"uvec2";if(v(t))return"uvec3";if(w(t))return"uvec4";throw new Error(`Invalid vector type: ${t}`)}function $(t){if("string"==typeof t)return t;if("object"==typeof t&&t.type)return t.type;throw new Error(`Invalid DynoType: ${String(t)}`)}function D(t){return Math.trunc(t).toString()}function z(t){return`${Math.max(0,Math.trunc(t)).toString()}u`}function I(t){return t===Number.POSITIVE_INFINITY?"INFINITY":t===Number.NEGATIVE_INFINITY?"-INFINITY":Number.isInteger(t)?t.toFixed(1):t.toString()}function E(t){if(t instanceof A)return t.type;return t.dynoOut().type}class A{constructor(t){this.__isDynoValue=!0,this.type=t}}class F extends A{constructor(t,e){super(t.outTypes[e]),this.dyno=t,this.key=e}}class P extends A{constructor(t,e){super(t),this.literal=e}getLiteral(){return this.literal}}function C(t,e){return new P(t,e)}class L extends P{constructor(t,e){super(t,""),this.value=e}getLiteral(){const{type:e,value:n}=this;switch(e){case"bool":return n?"true":"false";case"uint":return z(n);case"int":return D(n);case"float":return I(n);case"bvec2":{const t=n;return`bvec2(${t[0]}, ${t[1]})`}case"uvec2":{if(n instanceof t.Vector2)return`uvec2(${z(n.x)}, ${z(n.y)})`;const e=n;return`uvec2(${z(e[0])}, ${z(e[1])})`}case"ivec2":{if(n instanceof t.Vector2)return`ivec2(${D(n.x)}, ${D(n.y)})`;const e=n;return`ivec2(${D(e[0])}, ${D(e[1])})`}case"vec2":{if(n instanceof t.Vector2)return`vec2(${I(n.x)}, ${I(n.y)})`;const e=n;return`vec2(${I(e[0])}, ${I(e[1])})`}case"bvec3":{const t=n;return`bvec3(${t[0]}, ${t[1]}, ${t[2]})`}case"uvec3":{if(n instanceof t.Vector3)return`uvec3(${z(n.x)}, ${z(n.y)}, ${z(n.z)})`;const e=n;return`uvec3(${z(e[0])}, ${z(e[1])}, ${z(e[2])})`}case"ivec3":{if(n instanceof t.Vector3)return`ivec3(${D(n.x)}, ${D(n.y)}, ${D(n.z)})`;const e=n;return`ivec3(${D(e[0])}, ${D(e[1])}, ${D(e[2])})`}case"vec3":{if(n instanceof t.Vector3)return`vec3(${I(n.x)}, ${I(n.y)}, ${I(n.z)})`;const e=n;return`vec3(${I(e[0])}, ${I(e[1])}, ${I(e[2])})`}case"bvec4":{const t=n;return`bvec4(${t[0]}, ${t[1]}, ${t[2]}, ${t[3]})`}case"uvec4":{if(n instanceof t.Vector4)return`uvec4(${z(n.x)}, ${z(n.y)}, ${z(n.z)}, ${z(n.w)})`;const e=n;return`uvec4(${z(e[0])}, ${z(e[1])}, ${z(e[2])}, ${z(e[3])})`}case"ivec4":{if(n instanceof t.Vector4)return`ivec4(${D(n.x)}, ${D(n.y)}, ${D(n.z)}, ${D(n.w)})`;const e=n;return`ivec4(${D(e[0])}, ${D(e[1])}, ${D(e[2])}, ${D(e[3])})`}case"vec4":{if(n instanceof t.Vector4)return`vec4(${I(n.x)}, ${I(n.y)}, ${I(n.z)}, ${I(n.w)})`;if(n instanceof t.Quaternion)return`vec4(${I(n.x)}, ${I(n.y)}, ${I(n.z)}, ${I(n.w)})`;const e=n;return`vec4(${I(e[0])}, ${I(e[1])}, ${I(e[2])}, ${I(e[3])})`}case"mat2":case"mat2x2":{const a=n,s=a instanceof t.Matrix2?a.elements:n,r=new Array(4).fill(0).map(((t,e)=>I(s[e])));return`${e}(${r.join(", ")})`}case"mat2x3":{const t=n,a=new Array(6).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}case"mat2x4":{const t=n,a=new Array(8).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}case"mat3":case"mat3x3":{const a=n,s=a instanceof t.Matrix3?a.elements:n,r=new Array(9).fill(0).map(((t,e)=>I(s[e])));return`${e}(${r.join(", ")})`}case"mat3x2":{const t=n,a=new Array(6).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}case"mat3x4":{const t=n,a=new Array(12).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}case"mat4":case"mat4x4":{const a=n,s=a instanceof t.Matrix4?a.elements:n,r=new Array(16).fill(0).map(((t,e)=>I(s[e])));return`${e}(${r.join(", ")})`}case"mat4x2":{const t=n,a=new Array(8).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}case"mat4x3":{const t=n,a=new Array(12).fill(0).map(((e,n)=>I(t[n])));return`${e}(${a.join(", ")})`}default:throw new Error(`Type not implemented: ${String(e)}`)}}}function R(t,e){return new L(t,e)}function q(t){const e=String(t);if(p(t))return`${e}(false)`;if(y(t))return`${e}(0.0)`;if(h(t))return`${e}(0)`;if(x(t))return`${e}(0u)`;throw new Error(`Type not implemented: ${e}`)}const U=" ";class V{constructor({indent:t}={}){this.globals=new Set,this.statements=[],this.uniforms={},this.declares=new Set,this.updaters=[],this.sequence=0,this.indent=U,this.indent=t??U}nextSequence(){return this.sequence++}}class B{constructor({inTypes:t,outTypes:e,inputs:n,update:a,globals:s,statements:r,generate:i}){this.inTypes=t??{},this.outTypes=e??{},this.inputs=n??{},this.update=a,this.globals=s,this.statements=r,this.generate=i??(({inputs:t,outputs:e,compile:n})=>{var a,s;return{globals:null==(a=this.globals)?void 0:a.call(this,{inputs:t,outputs:e,compile:n}),statements:null==(s=this.statements)?void 0:s.call(this,{inputs:t,outputs:e,compile:n})}})}get outputs(){const t={};for(const e in this.outTypes)t[e]=new F(this,e);return t}apply(t){return Object.assign(this.inputs,t),this.outputs}compile({inputs:t,outputs:e,compile:n}){const a=[`// ${this.constructor.name}(${Object.values(t).join(", ")}) => (${Object.values(e).join(", ")})`],s=[];for(const l in e){const t=e[l];t&&!n.declares.has(t)&&(n.declares.add(t),s.push(l))}const{globals:r,statements:i,uniforms:o}=this.generate({inputs:t,outputs:e,compile:n});for(const l of r??[])n.globals.add(l);for(const l in o)n.uniforms[l]=o[l];this.update&&n.updaters.push(this.update);for(const l of s){const t=e[l];t&&(n.uniforms[t]||a.push(`${H(t,this.outTypes[l])};`))}return(null==i?void 0:i.length)&&(a.push("{"),a.push(...i.map((t=>n.indent+t))),a.push("}")),a}}class N extends B{constructor({inTypes:t,outTypes:e,inputs:n,update:a,globals:s,construct:r}){super({inTypes:t,outTypes:e,inputs:n,update:a,globals:s,generate:t=>this.generateBlock(t)}),this.construct=r}generateBlock({inputs:t,outputs:e,compile:n}){var a,s;const r={},i={};for(const x in t)null!=t[x]&&(r[x]=new P(this.inTypes[x],t[x]));for(const x in e)null!=e[x]&&(i[x]=new A(this.outTypes[x]));const o={roots:[]},l=this.construct(r,i,o);for(const x of(null==(a=this.globals)?void 0:a.call(this,{inputs:t,outputs:e,compile:n}))??[])n.globals.add(x);const u=[],c=new Map;function p(t,e,a){let s=c.get(t);if(!s){s={sequence:n.nextSequence(),outNames:new Map,newOuts:new Set},c.set(t,s);for(const e in t.inputs){let n=t.inputs[e];for(;n;){if(n instanceof A){n instanceof F&&p(n.dyno,n.key);break}if("function"!=typeof n.dynoOut)throw new Error(`dynoOut is not a function for ${n.constructor.name}`);n=n.dynoOut()}}u.push(t)}e&&(a||s.newOuts.add(e),s.outNames.set(e,a??`${e}_${s.sequence}`))}for(const x of o.roots)p(x);for(const x in i){let t=(null==l?void 0:l[x])??i[x];for(;t;){if(t instanceof A){t instanceof F&&p(t.dyno,t.key,e[x]);break}t=t.dynoOut()}i[x]=t}const d=[];for(const x of u){const t={},e={};for(const n in x.inputs){let e=x.inputs[n];for(;e;){if(e instanceof A){if(e instanceof P)t[n]=e.getLiteral();else if(e instanceof F){const a=null==(s=c.get(e.dyno))?void 0:s.outNames.get(e.key);if(!a)throw new Error(`Source not found for ${e.dyno.constructor.name}.${e.key}`);t[n]=a}break}e=e.dynoOut()}}const a=c.get(x)??{outNames:new Map};for(const[n,s]of a.outNames.entries())e[n]=s;const r=x.compile({inputs:t,outputs:e,compile:n});d.push(r)}const h=[];for(const x in e)i[x]instanceof P&&h.push(`${e[x]} = ${i[x].getLiteral()};`);h.length>0&&d.push(h);return{statements:d.flatMap(((t,e)=>0===e?t:["",...t]))}}}function O(t,e,n,{update:a,globals:s}={}){return new N({inTypes:t,outTypes:e,construct:n,update:a,globals:s})}function G({inTypes:t,outTypes:e,inputs:n,update:a,globals:s,statements:r,generate:i}){return new B({inTypes:t,outTypes:e,inputs:n,update:a,globals:s,statements:r,generate:i})}function H(t,e,n){const a="string"==typeof e?e:e.type;if(!a)throw new Error(`Invalid DynoType: ${String(e)}`);return`${a} ${t}${null!=n?`[${n}]`:""}`}function W(t){var e;let n=!1;const a=t.split("\n").map((t=>{const e=t.trimEnd();return n?e:e.length>0?(n=!0,e):null})).filter((t=>null!=t));for(;a.length>0&&0===a[a.length-1].length;)a.pop();if(0===a.length)return[];const s=null==(e=a[0].match(/^\s*/))?void 0:e[0];if(!s)return a;const r=new RegExp(`^${s}`);return a.map((t=>t.replace(r,"")))}function j(t){return W(t).join("\n")}class Q extends B{constructor({a:t,outKey:e,outTypeFunc:n}){const a={a:E(t)},s=n(E(t));super({inTypes:a,outTypes:{[e]:s},inputs:{a:t}}),this.outKey=e}dynoOut(){return new F(this,this.outKey)}}class K extends B{constructor({a:t,b:e,outKey:n,outTypeFunc:a}){const s={a:E(t),b:E(e)},r=a(E(t),E(e));super({inTypes:s,outTypes:{[n]:r},inputs:{a:t,b:e}}),this.outKey=n}dynoOut(){return new F(this,this.outKey)}}class X extends B{constructor({a:t,b:e,c:n,outKey:a,outTypeFunc:s}){const r={a:E(t),b:E(e),c:E(n)},i=s(E(t),E(e),E(n));super({inTypes:r,outTypes:{[a]:i},inputs:{a:t,b:e,c:n}}),this.outKey=a}dynoOut(){return new F(this,this.outKey)}}const Y={type:"Gsplat"},J={type:"CovSplat"},Z={type:"PackedSplats"},tt={type:"ExtSplats"},et={type:"CovSplats"},nt=(t,e)=>new yt({packedSplats:t,index:e}),at=(t,e,n,a)=>new gt({packedSplats:t,index:e,base:n,count:a}),st=(t,e)=>new St({extSplats:t,index:e}),rt=t=>new kt({gsplat:t}),it=t=>new $t({gsplat:t}),ot=({gsplat:t,flags:e,index:n,center:a,scales:s,quaternion:r,rgba:i,rgb:o,opacity:l,x:u,y:c,z:p,r:d,g:h,b:x})=>new Dt({gsplat:t,flags:e,index:n,center:a,scales:s,quaternion:r,rgba:i,rgb:o,opacity:l,x:u,y:c,z:p,r:d,g:h,b:x}),lt=t=>new It({gsplat:t}),ut=(t,{scale:e,rotate:n,translate:a,recolor:s})=>new Pt({gsplat:t,scale:e,rotate:n,translate:a,recolor:s}),ct=t=>new Ut({index:t}),pt=t=>new Vt({index:t}),dt=j("\n struct Gsplat {\n vec3 center;\n uint flags;\n vec3 scales;\n int index;\n vec4 quaternion;\n vec4 rgba;\n };\n const uint GSPLAT_FLAG_ACTIVE = 1u << 0u;\n\n bool isGsplatActive(uint flags) {\n return (flags & GSPLAT_FLAG_ACTIVE) != 0u;\n }\n"),ht=j("\n struct CovSplat {\n vec3 center;\n uint flags;\n vec4 rgba;\n vec3 xxyyzz;\n int index;\n vec3 xyxzyz;\n };\n\n bool isCovSplatActive(uint flags) {\n return (flags & GSPLAT_FLAG_ACTIVE) != 0u;\n }\n"),xt=j("\n struct PackedSplats {\n usampler2DArray textureArray;\n int numSplats;\n vec4 rgbMinMaxLnScaleMinMax;\n bool lodOpacity;\n };\n");class ft extends Q{constructor({packedSplats:t}){super({a:t,outKey:"numSplats",outTypeFunc:()=>"int"}),this.statements=({inputs:t,outputs:e})=>[`${e.numSplats} = ${t.a}.numSplats;`]}}const mt=j("\n bool readPackedArray(usampler2DArray texture, int numSplats, vec4 rgbMinMaxLnScaleMinMax, int index, out Gsplat gsplat) {\n if ((index >= 0) && (index < numSplats)) {\n uvec4 packedData = texelFetch(texture, splatTexCoord(index), 0);\n unpackSplatEncoding(packedData, gsplat.center, gsplat.scales, gsplat.quaternion, gsplat.rgba, rgbMinMaxLnScaleMinMax);\n return true;\n } else {\n return false;\n }\n }\n");class yt extends B{constructor({packedSplats:t,index:e}){super({inTypes:{packedSplats:Z,index:"int"},outTypes:{gsplat:Y},inputs:{packedSplats:t,index:e},globals:()=>[dt,xt,mt],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=e;if(!n)return[];const{packedSplats:a,index:s}=t;let r;return r=a&&s?W(`\n ${n}.flags = 0u;\n if (readPackedArray(${a}.textureArray, ${a}.numSplats, ${a}.rgbMinMaxLnScaleMinMax, ${s}, ${n})) {\n if (${a}.lodOpacity) {\n ${n}.rgba.a = 2.0 * ${n}.rgba.a;\n }\n bool zeroSize = all(equal(${n}.scales, vec3(0.0, 0.0, 0.0)));\n ${n}.flags = zeroSize ? 0u : GSPLAT_FLAG_ACTIVE;\n }\n `):[`${n}.flags = 0u;`],r.push(`${n}.index = ${s??"0"};`),r}})}dynoOut(){return new F(this,"gsplat")}}class gt extends B{constructor({packedSplats:t,index:e,base:n,count:a}){super({inTypes:{packedSplats:Z,index:"int",base:"int",count:"int"},outTypes:{gsplat:Y},inputs:{packedSplats:t,index:e,base:n,count:a},globals:()=>[dt,xt,mt],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=e;if(!n)return[];const{packedSplats:a,index:s,base:r,count:i}=t;let o;return o=a&&s&&r&&i?W(`\n ${n}.flags = 0u;\n if (readPackedArray(${a}.textureArray, ${a}.numSplats, ${a}.rgbMinMaxLnScaleMinMax, ${s}, ${n})) {\n if (${a}.lodOpacity) {\n ${n}.rgba.a = 2.0 * ${n}.rgba.a;\n }\n bool zeroSize = all(equal(${n}.scales, vec3(0.0, 0.0, 0.0)));\n ${n}.flags = zeroSize ? 0u : GSPLAT_FLAG_ACTIVE;\n }\n `):[`${n}.flags = 0u;`],o.push(`${n}.index = ${s??"0"};`),o}})}dynoOut(){return new F(this,"gsplat")}}const vt=j("\n struct ExtSplats {\n usampler2DArray textureArray1;\n usampler2DArray textureArray2;\n int numSplats;\n };\n");class wt extends Q{constructor({extSplats:t}){super({a:t,outKey:"numSplats",outTypeFunc:()=>"int"}),this.statements=({inputs:t,outputs:e})=>[`${e.numSplats} = ${t.a}.numSplats;`]}}const bt=j("\n void readExtArrays(usampler2DArray texture1, usampler2DArray texture2, int numSplats, int index, out Gsplat gsplat) {\n gsplat.flags = 0u;\n if ((index >= 0) && (index < numSplats)) {\n ivec3 coord = splatTexCoord(index);\n uvec4 packed1 = texelFetch(texture1, coord, 0);\n uvec4 packed2 = texelFetch(texture2, coord, 0);\n unpackSplatExt(packed1, packed2, gsplat.center, gsplat.scales, gsplat.quaternion, gsplat.rgba);\n gsplat.flags = all(equal(gsplat.scales, vec3(0.0, 0.0, 0.0))) ? 0u : GSPLAT_FLAG_ACTIVE;\n gsplat.index = index;\n }\n }\n");class St extends B{constructor({extSplats:t,index:e}){super({inTypes:{extSplats:tt,index:"int"},outTypes:{gsplat:Y},inputs:{extSplats:t,index:e},globals:()=>[dt,vt,bt],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=e;if(!n)return[`${n}.flags = 0u;`];const{extSplats:a,index:s}=t;return a&&s?W(`\n readExtArrays(${a}.textureArray1, ${a}.textureArray2, ${a}.numSplats, ${s}, ${n});\n `):[`${n}.flags = 0u;`]}})}dynoOut(){return new F(this,"gsplat")}}class Tt extends Q{constructor({covsplats:t}){super({a:t,outKey:"numSplats",outTypeFunc:()=>"int"}),this.statements=({inputs:t,outputs:e})=>[`${e.numSplats} = ${t.a}.numSplats;`]}}const _t=j("\n void readCovArrays(usampler2DArray texture1, usampler2DArray texture2, int numSplats, int index, out CovSplat covsplat) {\n covsplat.flags = 0u;\n if ((index >= 0) && (index < numSplats)) {\n ivec3 coord = splatTexCoord(index);\n uvec4 packed1 = texelFetch(texture1, coord, 0);\n uvec4 packed2 = texelFetch(texture2, coord, 0);\n unpackSplatExtCov(packed1, packed2, covsplat.center, covsplat.rgba, covsplat.xxyyzz, covsplat.xyxzyz);\n covsplat.flags = (all(equal(covsplat.xxyyzz, vec3(0.0))) && all(equal(covsplat.xyxzyz, vec3(0.0)))) ? 0u : GSPLAT_FLAG_ACTIVE;\n gsplat.index = index;\n }\n }\n");class Mt extends B{constructor({covSplats:t,index:e}){super({inTypes:{covSplats:et,index:"int"},outTypes:{covsplat:J},inputs:{covSplats:t,index:e},globals:()=>[dt,ht,_t],statements:({inputs:t,outputs:e})=>{const{covsplat:n}=e;if(!n)return[`${n}.flags = 0u;`];const{covSplats:a,index:s}=t;return a&&s?W(`\n readCovArrays(${a}.textureArray, ${a}.numSplats, ${s}, ${n});\n `):[`${n}.flags = 0u;`]}})}dynoOut(){return new F(this,"covsplat")}}class kt extends B{constructor({gsplat:t}){super({inTypes:{gsplat:Y},outTypes:{covsplat:J},inputs:{gsplat:t},globals:()=>[dt,ht],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=t,{covsplat:a}=e;return n?W(`\n ${a}.flags = 0u;\n if (isGsplatActive(${n}.flags)) {\n ${a}.flags = ${n}.flags;\n ${a}.index = ${n}.index;\n ${a}.rgba = ${n}.rgba;\n ${a}.center = ${n}.center;\n mat3 m = scaleQuaternionToMatrix(${n}.scales, ${n}.quaternion);\n m = m * transpose(m);\n ${a}.xxyyzz = vec3(m[0][0], m[1][1], m[2][2]);\n ${a}.xyxzyz = vec3(m[0][1], m[0][2], m[1][2]);\n }\n `):[`${a}.flags = 0u;`]}})}dynoOut(){return new F(this,"covsplat")}}class $t extends B{constructor({gsplat:t}){super({inTypes:{gsplat:Y},outTypes:{flags:"uint",active:"bool",index:"int",center:"vec3",scales:"vec3",quaternion:"vec4",rgba:"vec4",rgb:"vec3",opacity:"float",x:"float",y:"float",z:"float",r:"float",g:"float",b:"float"},inputs:{gsplat:t},globals:()=>[dt],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=t,{flags:a,active:s,index:r,center:i,scales:o,quaternion:l,rgba:u,rgb:c,opacity:p,x:d,y:h,z:x,r:f,g:m,b:y}=e;return[a?`${a} = ${n?`${n}.flags`:"0u"};`:null,s?`${s} = isGsplatActive(${n?`${n}.flags`:"0u"});`:null,r?`${r} = ${n?`${n}.index`:"0"};`:null,i?`${i} = ${n?`${n}.center`:"vec3(0.0, 0.0, 0.0)"};`:null,o?`${o} = ${n?`${n}.scales`:"vec3(0.0, 0.0, 0.0)"};`:null,l?`${l} = ${n?`${n}.quaternion`:"vec4(0.0, 0.0, 0.0, 1.0)"};`:null,u?`${u} = ${n?`${n}.rgba`:"vec4(0.0, 0.0, 0.0, 0.0)"};`:null,c?`${c} = ${n?`${n}.rgba.rgb`:"vec3(0.0, 0.0, 0.0)"};`:null,p?`${p} = ${n?`${n}.rgba.a`:"0.0"};`:null,d?`${d} = ${n?`${n}.center.x`:"0.0"};`:null,h?`${h} = ${n?`${n}.center.y`:"0.0"};`:null,x?`${x} = ${n?`${n}.center.z`:"0.0"};`:null,f?`${f} = ${n?`${n}.rgba.r`:"0.0"};`:null,m?`${m} = ${n?`${n}.rgba.g`:"0.0"};`:null,y?`${y} = ${n?`${n}.rgba.b`:"0.0"};`:null].filter(Boolean)}})}}class Dt extends B{constructor({gsplat:t,flags:e,index:n,center:a,scales:s,quaternion:r,rgba:i,rgb:o,opacity:l,x:u,y:c,z:p,r:d,g:h,b:x}){super({inTypes:{gsplat:Y,flags:"uint",index:"int",center:"vec3",scales:"vec3",quaternion:"vec4",rgba:"vec4",rgb:"vec3",opacity:"float",x:"float",y:"float",z:"float",r:"float",g:"float",b:"float"},outTypes:{gsplat:Y},inputs:{gsplat:t,flags:e,index:n,center:a,scales:s,quaternion:r,rgba:i,rgb:o,opacity:l,x:u,y:c,z:p,r:d,g:h,b:x},globals:()=>[dt],statements:({inputs:t,outputs:e})=>{const{gsplat:n}=e;if(!n)return[];const{gsplat:a,flags:s,index:r,center:i,scales:o,quaternion:l,rgba:u,rgb:c,opacity:p,x:d,y:h,z:x,r:f,g:m,b:y}=t;return[`${n}.flags = ${s??(a?`${a}.flags`:"0u")};`,`${n}.index = ${r??(a?`${a}.index`:"0")};`,`${n}.center = ${i??(a?`${a}.center`:"vec3(0.0, 0.0, 0.0)")};`,`${n}.scales = ${o??(a?`${a}.scales`:"vec3(0.0, 0.0, 0.0)")};`,`${n}.quaternion = ${l??(a?`${a}.quaternion`:"vec4(0.0, 0.0, 0.0, 1.0)")};`,`${n}.rgba = ${u??(a?`${a}.rgba`:"vec4(0.0, 0.0, 0.0, 0.0)")};`,c?`${n}.rgba.rgb = ${c};`:null,p?`${n}.rgba.a = ${p};`:null,d?`${n}.center.x = ${d};`:null,h?`${n}.center.y = ${h};`:null,x?`${n}.center.z = ${x};`:null,f?`${n}.rgba.r = ${f};`:null,m?`${n}.rgba.g = ${m};`:null,y?`${n}.rgba.b = ${y};`:null].filter(Boolean)}})}dynoOut(){return new F(this,"gsplat")}}const zt=j("\n vec3 gsplatNormal(vec3 scales, vec4 quaternion) {\n float minScale = min(scales.x, min(scales.y, scales.z));\n vec3 normal;\n if (scales.z == minScale) {\n normal = vec3(0.0, 0.0, 1.0);\n } else if (scales.y == minScale) {\n normal = vec3(0.0, 1.0, 0.0);\n } else {\n normal = vec3(1.0, 0.0, 0.0);\n }\n return quatVec(quaternion, normal);\n }\n");class It extends Q{constructor({gsplat:t}){super({a:t,outKey:"normal",outTypeFunc:()=>"vec3"}),this.globals=()=>[dt,zt],this.statements=({inputs:t,outputs:e})=>[`${e.normal} = gsplatNormal(${t.a}.scales, ${t.a}.quaternion);`]}}class Et extends Q{constructor({gsplat:t}){super({a:t,outKey:"xaxis",outTypeFunc:()=>"vec3"}),this.globals=()=>[dt],this.statements=({inputs:t,outputs:e})=>[`${e.xaxis} = quatVec(${t.a}.quaternion, vec3(1.0, 0.0, 0.0));`]}}class At extends Q{constructor({gsplat:t}){super({a:t,outKey:"yaxis",outTypeFunc:()=>"vec3"}),this.globals=()=>[dt],this.statements=({inputs:t,outputs:e})=>[`${e.yaxis} = quatVec(${t.a}.quaternion, vec3(0.0, 1.0, 0.0));`]}}class Ft extends Q{constructor({gsplat:t}){super({a:t,outKey:"zaxis",outTypeFunc:()=>"vec3"}),this.globals=()=>[dt],this.statements=({inputs:t,outputs:e})=>[`${e.zaxis} = quatVec(${t.a}.quaternion, vec3(0.0, 0.0, 1.0));`]}}class Pt extends B{constructor({gsplat:t,scale:e,rotate:n,translate:a,recolor:s}){super({inTypes:{gsplat:Y,scale:"float",rotate:"vec4",translate:"vec3",recolor:"vec4"},outTypes:{gsplat:Y},inputs:{gsplat:t,scale:e,rotate:n,translate:a,recolor:s},globals:()=>[dt],statements:({inputs:t,outputs:e,compile:n})=>{const{gsplat:a}=e;if(!a||!t.gsplat)return[];const{scale:s,rotate:r,translate:i,recolor:o}=t,l=n.indent;return[`${a} = ${t.gsplat};`,`if (isGsplatActive(${a}.flags)) {`,s?`${l}${a}.center *= ${s};`:null,r?`${l}${a}.center = quatVec(${r}, ${a}.center);`:null,i?`${l}${a}.center += ${i};`:null,s?`${l}${a}.scales *= ${s};`:null,r?`${l}${a}.quaternion = quatQuat(${r}, ${a}.quaternion);`:null,o?`${l}${a}.rgba *= ${o};`:null,"}"].filter(Boolean)}})}dynoOut(){return new F(this,"gsplat")}}const Ct=t=>new Rt({covsplat:t}),Lt=({covsplat:t,flags:e,index:n,center:a,rgba:s,rgb:r,opacity:i,x:o,y:l,z:u,r:c,g:p,b:d})=>new qt({covsplat:t,flags:e,index:n,center:a,rgba:s,rgb:r,opacity:i,x:o,y:l,z:u,r:c,g:p,b:d});class Rt extends B{constructor({covsplat:t}){super({inTypes:{covsplat:J},outTypes:{flags:"uint",active:"bool",index:"int",center:"vec3",rgba:"vec4",rgb:"vec3",opacity:"float",x:"float",y:"float",z:"float",r:"float",g:"float",b:"float"},inputs:{covsplat:t},globals:()=>[ht],statements:({inputs:t,outputs:e})=>{const{covsplat:n}=t,{flags:a,active:s,index:r,center:i,rgba:o,rgb:l,opacity:u,x:c,y:p,z:d,r:h,g:x,b:f}=e;return[a?`${a} = ${n?`${n}.flags`:"0u"};`:null,s?`${s} = isCovSplatActive(${n?`${n}.flags`:"0u"});`:null,r?`${r} = ${n?`${n}.index`:"0"};`:null,i?`${i} = ${n?`${n}.center`:"vec3(0.0, 0.0, 0.0)"};`:null,o?`${o} = ${n?`${n}.rgba`:"vec4(0.0, 0.0, 0.0, 0.0)"};`:null,l?`${l} = ${n?`${n}.rgba.rgb`:"vec3(0.0, 0.0, 0.0)"};`:null,u?`${u} = ${n?`${n}.rgba.a`:"0.0"};`:null,c?`${c} = ${n?`${n}.center.x`:"0.0"};`:null,p?`${p} = ${n?`${n}.center.y`:"0.0"};`:null,d?`${d} = ${n?`${n}.center.z`:"0.0"};`:null,h?`${h} = ${n?`${n}.rgba.r`:"0.0"};`:null,x?`${x} = ${n?`${n}.rgba.g`:"0.0"};`:null,f?`${f} = ${n?`${n}.rgba.b`:"0.0"};`:null].filter(Boolean)}})}}class qt extends B{constructor({covsplat:t,flags:e,index:n,center:a,rgba:s,rgb:r,opacity:i,x:o,y:l,z:u,r:c,g:p,b:d}){super({inTypes:{covsplat:J,flags:"uint",index:"int",center:"vec3",rgba:"vec4",rgb:"vec3",opacity:"float",x:"float",y:"float",z:"float",r:"float",g:"float",b:"float"},outTypes:{covsplat:J},inputs:{covsplat:t,flags:e,index:n,center:a,rgba:s,rgb:r,opacity:i,x:o,y:l,z:u,r:c,g:p,b:d},globals:()=>[ht],statements:({inputs:t,outputs:e})=>{const{covsplat:n}=e;if(!n)return[];const{covsplat:a,flags:s,index:r,center:i,rgba:o,rgb:l,opacity:u,x:c,y:p,z:d,r:h,g:x,b:f}=t;return[`${n}.flags = ${s??(a?`${a}.flags`:"0u")};`,`${n}.index = ${r??(a?`${a}.index`:"0")};`,`${n}.center = ${i??(a?`${a}.center`:"vec3(0.0, 0.0, 0.0)")};`,`${n}.rgba = ${o??(a?`${a}.rgba`:"vec4(0.0, 0.0, 0.0, 0.0)")};`,l?`${n}.rgba.rgb = ${l};`:null,u?`${n}.rgba.a = ${u};`:null,c?`${n}.center.x = ${c};`:null,p?`${n}.center.y = ${p};`:null,d?`${n}.center.z = ${d};`:null,h?`${n}.rgba.r = ${h};`:null,x?`${n}.rgba.g = ${x};`:null,f?`${n}.rgba.b = ${f};`:null,`${n}.xxyyzz = ${a?`${a}.xxyyzz`:"vec3(0.0, 0.0, 0.0)"};`,`${n}.xyxzyz = ${a?`${a}.xyxzyz`:"vec3(0.0, 0.0, 0.0)"};`].filter(Boolean)}})}dynoOut(){return new F(this,"covsplat")}}class Ut extends B{constructor({index:t}){super({inTypes:{index:"int"},outTypes:{coord:"ivec3"},inputs:{index:t},statements:({inputs:t,outputs:e})=>{const{index:n}=t,{coord:a}=e;return n&&a?[`${a} = splatTexCoord(${n});`]:[]}})}dynoOut(){return new F(this,"coord")}}class Vt extends B{constructor({index:t}){super({inTypes:{index:"int"},outTypes:{coord:"ivec3"},inputs:{index:t},statements:({inputs:t,outputs:e})=>{const{index:n}=t,{coord:a}=e;return n&&a?[`${a} = pagedSplatTexCoord(${n});`]:[]}})}dynoOut(){return new F(this,"coord")}}const Bt=(t,e)=>new jt({gsplat:t,rgbMinMaxLnScaleMinMax:e}),Nt=(t,e)=>new Qt({covsplat:t,rgbMinMaxLnScaleMinMax:e}),Ot=t=>new Kt({gsplat:t}),Gt=t=>new Xt({covsplat:t}),Ht=(t,e,n,a)=>new Yt({gsplat:t,viewCenter:e,viewDir:n,sortRadial:a}),Wt=(t,e,n,a)=>new Jt({covsplat:t,viewCenter:e,viewDir:n,sortRadial:a});class jt extends B{constructor({gsplat:t,rgbMinMaxLnScaleMinMax:e}){super({inTypes:{gsplat:Y,rgbMinMaxLnScaleMinMax:"vec4"},inputs:{gsplat:t,rgbMinMaxLnScaleMinMax:e},globals:()=>[dt],statements:({inputs:t,outputs:e})=>{const{gsplat:n,rgbMinMaxLnScaleMinMax:a}=t;return n&&a?W(`\n if (isGsplatActive(${n}.flags)) {\n target = packSplatEncoding(${n}.center, ${n}.scales, ${n}.quaternion, ${n}.rgba, ${a});\n } else {\n target = uvec4(0u, 0u, 0u, 0u);\n }\n `):["target = uvec4(0u, 0u, 0u, 0u);"]}})}}class Qt extends B{constructor({covsplat:t,rgbMinMaxLnScaleMinMax:e}){super({inTypes:{covsplat:J,rgbMinMaxLnScaleMinMax:"vec4"},inputs:{covsplat:t,rgbMinMaxLnScaleMinMax:e},globals:()=>[ht],statements:({inputs:t})=>{const{covsplat:e,rgbMinMaxLnScaleMinMax:n}=t;return e&&n?W(`\n if (isCovSplatActive(${e}.flags)) {\n target = packSplatCovEncoding(${e}.center, ${e}.rgba, ${e}.xxyyzz, ${e}.xyxzyz, ${n});\n } else {\n target = uvec4(0u);\n }\n `):["target = uvec4(0u);"]}})}}class Kt extends B{constructor({gsplat:t}){super({inTypes:{gsplat:Y},inputs:{gsplat:t},globals:()=>[dt],statements:({inputs:t})=>{const{gsplat:e}=t;return e?W(`\n if (isGsplatActive(${e}.flags)) {\n packSplatExt(target, target2, ${e}.center, ${e}.scales, ${e}.quaternion, ${e}.rgba);\n } else {\n target = uvec4(0u);\n target2 = uvec4(0u);\n }\n `):["target = uvec4(0u);","target2 = uvec4(0u);"]}})}}class Xt extends B{constructor({covsplat:t}){super({inTypes:{covsplat:J},inputs:{covsplat:t},globals:()=>[ht],statements:({inputs:t})=>{const{covsplat:e}=t;return e?W(`\n if (isCovSplatActive(${e}.flags)) {\n packSplatExtCov(target, target2, ${e}.center, ${e}.rgba, ${e}.xxyyzz, ${e}.xyxzyz);\n } else {\n target = uvec4(0u);\n target2 = uvec4(0u);\n }\n `):["target = uvec4(0u);","target2 = uvec4(0u);"]}})}}class Yt extends B{constructor({gsplat:t,viewCenter:e,viewDir:n,sortRadial:a}){super({inTypes:{gsplat:Y,viewCenter:"vec3",viewDir:"vec3",sortRadial:"bool"},inputs:{gsplat:t,viewCenter:e,viewDir:n,sortRadial:a},globals:()=>[dt],statements:({inputs:t})=>{const{gsplat:e,viewCenter:n,viewDir:a,sortRadial:s}=t;return e&&n&&a&&s?W(`\n float metric = 1.0 / 0.0;\n if (isGsplatActive(${e}.flags)) {\n vec3 center = ${e}.center - ${n};\n if (${s}) {\n metric = length(center);\n } else {\n float bias = 100.0; // reduce popping\n metric = dot(center, ${a}) + bias;\n }\n }\n target3 = floatToVec4(metric);\n `):[]}})}}class Jt extends B{constructor({covsplat:t,viewCenter:e,viewDir:n,sortRadial:a}){super({inTypes:{covsplat:J,viewCenter:"vec3",viewDir:"vec3",sortRadial:"bool"},inputs:{covsplat:t,viewCenter:e,viewDir:n,sortRadial:a},globals:()=>[ht],statements:({inputs:t})=>{const{covsplat:e,viewCenter:n,viewDir:a,sortRadial:s}=t;return e&&n&&a&&s?W(`\n float metric = 1.0 / 0.0;\n if (isCovSplatActive(${e}.flags)) {\n vec3 center = ${e}.center - ${n};\n if (${s}) {\n metric = length(center);\n } else {\n float bias = 100.0; // reduce popping\n metric = dot(center, ${a}) + bias;\n }\n }\n target3 = floatToVec4(metric);\n `):[]}})}}class Zt extends B{constructor({rgba8:t}){super({inTypes:{rgba8:"vec4"},inputs:{rgba8:t},statements:({inputs:t,outputs:e})=>[`target = ${t.rgba8??"vec4(0.0, 0.0, 0.0, 0.0)"};`]})}dynoOut(){return new F(this,"rgba8")}}const te=(t=0,e)=>new ie({key:e,value:t}),ee=(t,e)=>new xe({key:e,value:t});class ne extends B{constructor({key:t,type:e,count:n,value:a,update:s,globals:r}){t=t??"value",super({outTypes:{[t]:e},update:()=>{if(s){const t=s(this.value);void 0!==t&&(this.value=t)}this.uniform.value=this.value},generate:({inputs:a,outputs:s})=>{const i=(null==r?void 0:r({inputs:a,outputs:s}))??[],o={},l=s[t];return l&&(i.push(`uniform ${H(l,e,n)};`),o[l]=this.uniform),{globals:i,uniforms:o}}}),this.type=e,this.count=n,this.value=a,this.uniform={value:a},this.outKey=t}dynoOut(){return new F(this,this.outKey)}}class ae extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"bool",value:e,update:n})}}class se extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"uint",value:e,update:n})}}class re extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"int",value:e,update:n})}}class ie extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"float",value:e,update:n})}}class oe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"bvec2",value:e,update:n})}}class le extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"uvec2",value:e,update:n})}}class ue extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"ivec2",value:e,update:n})}}class ce extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"vec2",value:e,update:n})}}class pe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"bvec3",value:e,update:n})}}class de extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"uvec3",value:e,update:n})}}class he extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"ivec3",value:e,update:n})}}class xe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"vec3",value:e,update:n})}}class fe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"bvec4",value:e,update:n})}}class me extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"uvec4",value:e,update:n})}}class ye extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"ivec4",value:e,update:n})}}class ge extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"vec4",value:e,update:n})}}class ve extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat2",value:e,update:n})}}class we extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat2x2",value:e,update:n})}}class be extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat2x3",value:e,update:n})}}class Se extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat2x4",value:e,update:n})}}class Te extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat3",value:e,update:n})}}class _e extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat3x2",value:e,update:n})}}class Me extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat3x3",value:e,update:n})}}class ke extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat3x4",value:e,update:n})}}class $e extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat4",value:e,update:n})}}class De extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat4x2",value:e,update:n})}}class ze extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat4x3",value:e,update:n})}}class Ie extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"mat4x4",value:e,update:n})}}class Ee extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"usampler2D",value:e,update:n})}}class Ae extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"isampler2D",value:e,update:n})}}class Fe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"sampler2D",value:e,update:n})}}class Pe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"usampler2DArray",value:e,update:n})}}class Ce extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"isampler2DArray",value:e,update:n})}}class Le extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"sampler2DArray",value:e,update:n})}}class Re extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"usampler3D",value:e,update:n})}}class qe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"isampler3D",value:e,update:n})}}class Ue extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"sampler3D",value:e,update:n})}}class Ve extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"usamplerCube",value:e,update:n})}}class Be extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"isamplerCube",value:e,update:n})}}class Ne extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"samplerCube",value:e,update:n})}}class Oe extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"sampler2DShadow",value:e,update:n})}}class Ge extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"sampler2DArrayShadow",value:e,update:n})}}class He extends ne{constructor({key:t,value:e,update:n}){super({key:t,type:"samplerCubeShadow",value:e,update:n})}}var We=Uint8Array,je=Uint16Array,Qe=Int32Array,Ke=new We([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Xe=new We([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Ye=new We([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Je=function(t,e){for(var n=new je(31),a=0;a<31;++a)n[a]=e+=1<<t[a-1];var s=new Qe(n[30]);for(a=1;a<30;++a)for(var r=n[a];r<n[a+1];++r)s[r]=r-n[a]<<5|a;return{b:n,r:s}},Ze=Je(Ke,2),tn=Ze.b,en=Ze.r;tn[28]=258,en[258]=28;for(var nn=Je(Xe,0).b,an=new je(32768),sn=0;sn<32768;++sn){var rn=(43690&sn)>>1|(21845&sn)<<1;rn=(61680&(rn=(52428&rn)>>2|(13107&rn)<<2))>>4|(3855&rn)<<4,an[sn]=((65280&rn)>>8|(255&rn)<<8)>>1}var on=function(t,e,n){for(var a=t.length,s=0,r=new je(e);s<a;++s)t[s]&&++r[t[s]-1];var i,o=new je(e);for(s=1;s<e;++s)o[s]=o[s-1]+r[s-1]<<1;i=new je(1<<e);var l=15-e;for(s=0;s<a;++s)if(t[s])for(var u=s<<4|t[s],c=e-t[s],p=o[t[s]-1]++<<c,d=p|(1<<c)-1;p<=d;++p)i[an[p]>>l]=u;return i},ln=new We(288);for(sn=0;sn<144;++sn)ln[sn]=8;for(sn=144;sn<256;++sn)ln[sn]=9;for(sn=256;sn<280;++sn)ln[sn]=7;for(sn=280;sn<288;++sn)ln[sn]=8;var un=new We(32);for(sn=0;sn<32;++sn)un[sn]=5;var cn=on(ln,9),pn=on(un,5),dn=function(t){for(var e=t[0],n=1;n<t.length;++n)t[n]>e&&(e=t[n]);return e},hn=function(t,e,n){var a=e/8|0;return(t[a]|t[a+1]<<8)>>(7&e)&n},xn=function(t,e){var n=e/8|0;return(t[n]|t[n+1]<<8|t[n+2]<<16)>>(7&e)},fn=function(t){return(t+7)/8|0},mn=function(t,e,n){return(null==e||e<0)&&(e=0),(null==n||n>t.length)&&(n=t.length),new We(t.subarray(e,n))},yn=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],gn=function(t,e,n){var a=new Error(e||yn[t]);if(a.code=t,Error.captureStackTrace&&Error.captureStackTrace(a,gn),!n)throw a;return a},vn=function(t,e,n,a){var s=t.length,r=a?a.length:0;if(!s||e.f&&!e.l)return n||new We(0);var i=!n,o=i||2!=e.i,l=e.i;i&&(n=new We(3*s));var u=function(t){var e=n.length;if(t>e){var a=new We(Math.max(2*e,t));a.set(n),n=a}},c=e.f||0,p=e.p||0,d=e.b||0,h=e.l,x=e.d,f=e.m,m=e.n,y=8*s;do{if(!h){c=hn(t,p,1);var g=hn(t,p+1,3);if(p+=3,!g){var v=t[(I=fn(p)+4)-4]|t[I-3]<<8,w=I+v;if(w>s){l&&gn(0);break}o&&u(d+v),n.set(t.subarray(I,w),d),e.b=d+=v,e.p=p=8*w,e.f=c;continue}if(1==g)h=cn,x=pn,f=9,m=5;else if(2==g){var b=hn(t,p,31)+257,S=hn(t,p+10,15)+4,T=b+hn(t,p+5,31)+1;p+=14;for(var _=new We(T),M=new We(19),k=0;k<S;++k)M[Ye[k]]=hn(t,p+3*k,7);p+=3*S;var $=dn(M),D=(1<<$)-1,z=on(M,$);for(k=0;k<T;){var I,E=z[hn(t,p,D)];if(p+=15&E,(I=E>>4)<16)_[k++]=I;else{var A=0,F=0;for(16==I?(F=3+hn(t,p,3),p+=2,A=_[k-1]):17==I?(F=3+hn(t,p,7),p+=3):18==I&&(F=11+hn(t,p,127),p+=7);F--;)_[k++]=A}}var P=_.subarray(0,b),C=_.subarray(b);f=dn(P),m=dn(C),h=on(P,f),x=on(C,m)}else gn(1);if(p>y){l&&gn(0);break}}o&&u(d+131072);for(var L=(1<<f)-1,R=(1<<m)-1,q=p;;q=p){var U=(A=h[xn(t,p)&L])>>4;if((p+=15&A)>y){l&&gn(0);break}if(A||gn(2),U<256)n[d++]=U;else{if(256==U){q=p,h=null;break}var V=U-254;if(U>264){var B=Ke[k=U-257];V=hn(t,p,(1<<B)-1)+tn[k],p+=B}var N=x[xn(t,p)&R],O=N>>4;N||gn(3),p+=15&N;C=nn[O];if(O>3){B=Xe[O];C+=xn(t,p)&(1<<B)-1,p+=B}if(p>y){l&&gn(0);break}o&&u(d+131072);var G=d+V;if(d<C){var H=r-C,W=Math.min(C,G);for(H+d<0&&gn(3);d<W;++d)n[d]=a[H+d]}for(;d<G;++d)n[d]=n[d-C]}}e.l=h,e.p=q,e.b=d,e.f=c,h&&(c=1,e.m=f,e.d=x,e.n=m)}while(!c);return d!=n.length&&i?mn(n,0,d):n.subarray(0,d)},wn=new We(0),bn=function(t,e){return t[e]|t[e+1]<<8},Sn=function(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0},Tn=function(t,e){return Sn(t,e)+4294967296*Sn(t,e+4)},_n=function(){function t(t,e){"function"==typeof t&&(e=t,t={}),this.ondata=e;var n=t&&t.dictionary&&t.dictionary.subarray(-32768);this.s={i:0,b:n?n.length:0},this.o=new We(32768),this.p=new We(0),n&&this.o.set(n)}return t.prototype.e=function(t){if(this.ondata||gn(5),this.d&&gn(4),this.p.length){if(t.length){var e=new We(this.p.length+t.length);e.set(this.p),e.set(t,this.p.length),this.p=e}}else this.p=t},t.prototype.c=function(t){this.s.i=+(this.d=t||!1);var e=this.s.b,n=vn(this.p,this.s,this.o);this.ondata(mn(n,e,this.s.b),this.d),this.o=mn(n,this.s.b-32768),this.s.b=this.o.length,this.p=mn(this.p,this.s.p/8|0),this.s.p&=7},t.prototype.push=function(t,e){this.e(t),this.c(e)},t}();function Mn(t,e){return vn(t,{i:2},e&&e.out,e&&e.dictionary)}var kn=function(){function t(t,e){this.v=1,this.r=0,_n.call(this,t,e)}return t.prototype.push=function(t,e){if(_n.prototype.e.call(this,t),this.r+=t.length,this.v){var n=this.p.subarray(this.v-1),a=n.length>3?function(t){31==t[0]&&139==t[1]&&8==t[2]||gn(6,"invalid gzip data");var e=t[3],n=10;4&e&&(n+=2+(t[10]|t[11]<<8));for(var a=(e>>3&1)+(e>>4&1);a>0;a-=!t[n++]);return n+(2&e)}(n):4;if(a>n.length){if(!e)return}else this.v>1&&this.onmember&&this.onmember(this.r-n.length);this.p=n.subarray(a),this.v=0}_n.prototype.c.call(this,e),!this.s.f||this.s.l||e||(this.v=fn(this.s.p)+9,this.s={i:0},this.o=new We(0),this.push(new We(0),e))},t}(),$n="undefined"!=typeof TextDecoder&&new TextDecoder;try{$n.decode(wn,{stream:!0})}catch(sc){}function Dn(t,e){if(e){for(var n="",a=0;a<t.length;a+=16384)n+=String.fromCharCode.apply(null,t.subarray(a,a+16384));return n}if($n)return $n.decode(t);var s=function(t){for(var e="",n=0;;){var a=t[n++],s=(a>127)+(a>223)+(a>239);if(n+s>t.length)return{s:e,r:mn(t,n-1)};s?3==s?(a=((15&a)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e+=String.fromCharCode(55296|a>>10,56320|1023&a)):e+=1&s?String.fromCharCode((31&a)<<6|63&t[n++]):String.fromCharCode((15&a)<<12|(63&t[n++])<<6|63&t[n++]):e+=String.fromCharCode(a)}}(t),r=s.s;return(n=s.r).length&&gn(8),r}var zn=function(t,e){return e+30+bn(t,e+26)+bn(t,e+28)},In=function(t,e,n){var a=bn(t,e+28),s=Dn(t.subarray(e+46,e+46+a),!(2048&bn(t,e+8))),r=e+46+a,i=Sn(t,e+20),o=n&&4294967295==i?En(t,r):[i,Sn(t,e+24),Sn(t,e+42)],l=o[0],u=o[1],c=o[2];return[bn(t,e+10),l,u,s,r+bn(t,e+30)+bn(t,e+32),c]},En=function(t,e){for(;1!=bn(t,e);e+=4+bn(t,e+2));return[Tn(t,e+12),Tn(t,e+4),Tn(t,e+20)]};const An=Number.parseInt(t.REVISION),Fn=An>=179,Pn=new Float32Array(1),Cn=new Uint32Array(Pn.buffer),Ln="Float16Array"in globalThis,Rn=Ln?new globalThis.Float16Array(1):null,qn=new Uint16Array(null==Rn?void 0:Rn.buffer);function Un(t){return Pn[0]=t,Cn[0]}function Vn(t){return Cn[0]=t,Pn[0]}const Bn=Ln?function(t){return Rn[0]=t,qn[0]}:function(t){Pn[0]=t;const e=Cn[0],n=e>>23&255,a=8388607&e,s=(e>>31&1)<<15;if(255===n)return 0!==a?32767|s:31744|s;const r=n-127+15;if(r>=31)return 31744|s;if(r<=0){if(r<-10)return s;return s|(8388608|a)>>1-r+13}return s|r<<10|a>>13},Nn=Ln?function(t){return qn[0]=t,Rn[0]}:function(t){const e=t>>15&1,n=t>>10&31,a=1023&t;let s;if(0===n)if(0===a)s=e<<31;else{let t=a,n=-14;for(;!(1024&t);)t<<=1,n--;t&=1023;s=e<<31|n+127<<23|t<<13}else if(31===n)s=0===a?e<<31|2139095040:e<<31|2143289344;else{s=e<<31|n-15+127<<23|a<<13}return Cn[0]=s,Pn[0]};function On(t){return Math.max(0,Math.min(255,Math.round(255*t)))}function Gn(t){return Math.max(-127,Math.min(127,Math.round(127*t)))}function Hn(t){return t/255}function Wn(t){return t/127}function jn(t){const e=[],n=new Set;return function t(a){a&&"object"==typeof a&&!n.has(a)&&(n.add(a),a instanceof ArrayBuffer?e.push(a):ArrayBuffer.isView(a)?e.push(a.buffer):Array.isArray(a)?a.forEach(t):Object.values(a).forEach(t))}(t),e}function Qn(t,e){return new Array(t).fill(null).map(((t,n)=>e(n)))}function Kn(t,e,n,a,s,r,i,o,l,u,c,p,d,h,x,f){const m=4*e,[y,g]=t;y[m]=Un(n),y[m+1]=Un(a),y[m+2]=Un(s),y[m+3]=Bn(d),g[m]=Bn(h)|Bn(x)<<16,g[m+1]=Bn(f)|Bn(Math.log(r))<<16,g[m+2]=Bn(Math.log(i))|Bn(Math.log(o))<<16,g[m+3]=ya(l,u,c,p)}function Xn(t,e){const n=Zn,a=4*e,[s,r]=t;return n.center.x=Vn(s[a]),n.center.y=Vn(s[a+1]),n.center.z=Vn(s[a+2]),n.opacity=Nn(65535&s[a+3]),n.color.r=Nn(65535&r[a]),n.color.g=Nn(r[a]>>>16),n.color.b=Nn(65535&r[a+1]),n.scales.x=Math.exp(Nn(r[a+1]>>>16)),n.scales.y=Math.exp(Nn(65535&r[a+2])),n.scales.z=Math.exp(Nn(r[a+2]>>>16)),ga(r[a+3],n.quaternion),n}function Yn(t,e,a,s,i,o,l,u,c,p,d,h,x,f,m,y,g){const v=(null==g?void 0:g.rgbMin)??0,w=((null==g?void 0:g.rgbMax)??1)-v,b=On((f-v)/w),S=On((m-v)/w),T=On((y-v)/w),_=On((null==g?void 0:g.lodOpacity)?.5*x:x),M=fa(Jn.set(c,p,d,h)),k=255&M,$=M>>>8&255,D=M>>>16&255,z=(null==g?void 0:g.lnScaleMin)??n,I=254/(((null==g?void 0:g.lnScaleMax)??9)-z),E=o<r?0:Math.min(255,Math.max(1,Math.round((Math.log(o)-z)*I)+1)),A=l<r?0:Math.min(255,Math.max(1,Math.round((Math.log(l)-z)*I)+1)),F=u<r?0:Math.min(255,Math.max(1,Math.round((Math.log(u)-z)*I)+1)),P=Bn(a),C=Bn(s),L=Bn(i),R=4*e;t[R]=b|S<<8|T<<16|_<<24,t[R+1]=P|C<<16,t[R+2]=L|k<<16|$<<24,t[R+3]=E|A<<8|F<<16|D<<24}const Jn=new t.Quaternion;const Zn={center:new t.Vector3,scales:new t.Vector3,quaternion:new t.Quaternion,color:new t.Color,opacity:0};function ta(t,e,a){const s=Zn,r=4*e,i=t[r],o=t[r+1],l=t[r+2],u=t[r+3],c=(null==a?void 0:a.rgbMin)??0,p=((null==a?void 0:a.rgbMax)??1)-c;s.color.set(c+(255&i)/255*p,c+(i>>>8&255)/255*p,c+(i>>>16&255)/255*p),s.opacity=(i>>>24&255)/255,(null==a?void 0:a.lodOpacity)&&(s.opacity=2*s.opacity),s.center.set(Nn(65535&o),Nn(o>>>16&65535),Nn(65535&l));const d=(null==a?void 0:a.lnScaleMin)??n,h=(((null==a?void 0:a.lnScaleMax)??9)-d)/254,x=255&u;s.scales.x=0===x?0:Math.exp(d+(x-1)*h);const f=u>>>8&255;s.scales.y=0===f?0:Math.exp(d+(f-1)*h);const m=u>>>16&255;s.scales.z=0===m?0:Math.exp(d+(m-1)*h);return ma(l>>>16&65535|u>>>8&16711680,s.quaternion),s}function ea(t){const e=i,n=Math.max(1,Math.min(o,Math.ceil(t/e))),a=Math.ceil(t/(e*n));return{width:e,height:n,depth:a,maxSplats:e*n*a}}function na(){return!navigator.platform.toLowerCase().startsWith("win")&&(navigator.maxTouchPoints>0||/Mobi|Android|iPhone|iPad|iPod|Opera Mini|IEMobile/.test(navigator.userAgent))}function aa(){return/Android/.test(navigator.userAgent)||/Tizen/.test(navigator.userAgent)}function sa(){return!!navigator.xr&&/Oculus/.test(navigator.userAgent)}function ra(){return sa()&&/Quest 2/.test(navigator.userAgent)}function ia(){return/iPhone|iPad/.test(navigator.userAgent)}function oa(){return!!navigator.xr&&ia()&&/Safari/.test(navigator.userAgent)&&na()}function la(t,e,n){const a=new Uint8Array(4*e);for(let s=0;s<n/2;s++){const r=s*e*4,i=(n-1-s)*e*4;a.set(t.subarray(r,r+4*e)),t.set(t.subarray(i,i+4*e),r),t.set(a,i)}return t}function ua(t,e,n){const a=document.createElement("canvas");a.width=e,a.height=n;const s=a.getContext("2d");if(!s)throw new Error("Can't get 2d context");const r=s.createImageData(e,n);return r.data.set(t),s.putImageData(r,0,0),a.toDataURL("image/png")}const ca=j("\n precision highp float;\n\n in vec3 position;\n\n void main() {\n gl_Position = vec4(position.xy, 0.0, 1.0);\n }\n");function pa(e,n){const a=new t.Vector3(0,0,0).applyMatrix4(e),s=new t.Vector3(0,0,0).applyMatrix4(n),r=new t.Vector3(0,0,-1).applyMatrix4(e).sub(a).normalize(),i=new t.Vector3(0,0,-1).applyMatrix4(n).sub(s).normalize();return{distance:a.distanceTo(s),coincidence:r.dot(i)}}function da(e,n){const[a,s]=[new t.Vector3,new t.Quaternion],[r,i]=[new t.Vector3,new t.Quaternion];e.decompose(a,s,new t.Vector3),n.decompose(r,i,new t.Vector3);return{distance:a.distanceTo(r),coorient:Math.abs(s.dot(i))}}const ha=new t.Quaternion,xa=new t.Vector3;function fa(t){const e=ha.copy(t).normalize();e.w<0&&e.set(-e.x,-e.y,-e.z,-e.w);const n=2*Math.acos(e.w),a=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z),s=a<1e-6?xa.set(1,0,0):xa.set(e.x,e.y,e.z).divideScalar(a),r=Math.abs(s.x)+Math.abs(s.y)+Math.abs(s.z);let i=s.x/r,o=s.y/r;if(s.z<0){const t=i;i=(1-Math.abs(o))*(i>=0?1:-1),o=(1-Math.abs(t))*(o>=0?1:-1)}const l=.5*i+.5,u=.5*o+.5,c=Math.round(255*l),p=Math.round(255*u);return Math.round(n*(255/Math.PI))<<16|p<<8|c}function ma(t,e){const n=t>>>16&255;let a=2*((255&t)/255-.5),s=2*((t>>>8&255)/255-.5);const r=1-(Math.abs(a)+Math.abs(s)),i=Math.max(-r,0);a+=a>=0?-i:i,s+=s>=0?-i:i;const o=xa.set(a,s,r).normalize(),l=.5*(n/255*Math.PI),u=Math.sin(l),c=Math.cos(l);return e.set(o.x*u,o.y*u,o.z*u,c),e}function ya(t,e,n,a){const s=Math.sqrt(t*t+e*e+n*n+a*a),r=(a<0?-t:t)/s,i=(a<0?-e:e)/s,o=(a<0?-n:n)/s,l=(a<0?-a:a)/s,u=2*Math.acos(l),c=Math.sqrt(r*r+i*i+o*o),p=c<1e-6?1:r/c,d=c<1e-6?0:i/c,h=c<1e-6?0:o/c,x=Math.abs(p)+Math.abs(d)+Math.abs(h);let f=p/x,m=d/x;if(h<0){const t=f;f=(1-Math.abs(m))*(f>=0?1:-1),m=(1-Math.abs(t))*(m>=0?1:-1)}const y=.5*f+.5,g=.5*m+.5,v=Math.round(1023*y),w=Math.round(1023*g);return Math.round(u*(4095/Math.PI))<<20|w<<10|v}function ga(t,e){const n=t>>>20&4095;let a=2*((1023&t)/1023-.5),s=2*((t>>>10&1023)/1023-.5);const r=1-(Math.abs(a)+Math.abs(s)),i=Math.max(-r,0);a+=a>=0?-i:i,s+=s>=0?-i:i;const o=Math.sqrt(a*a+s*s+r*r),l=o<1e-6?0:a/o,u=o<1e-6?0:s/o,c=o<1e-6?0:r/o,p=.5*(n/4095*Math.PI),d=Math.sin(p),h=Math.cos(p);return e.set(l*d,u*d,c*d,h),e}function va(t,e,n,a){return 255&Math.round(Math.max(-127,Math.min(127,127*t)))|(255&Math.round(Math.max(-127,Math.min(127,127*e))))<<8|(255&Math.round(Math.max(-127,Math.min(127,127*n))))<<16|(255&Math.round(Math.max(-127,Math.min(127,127*a))))<<24}function wa(t,e,n){const a=Math.abs(t),s=Math.abs(e),r=Math.abs(n),i=Math.max(a,s,r),o=Math.floor(Math.log2(i)),l=Math.max(0,Math.min(31,o+15)),u=2**(l-15)/255;return Math.round(Math.max(0,Math.min(255,a/u)))|Math.round(Math.max(0,Math.min(255,s/u)))<<8|Math.round(Math.max(0,Math.min(255,r/u)))<<16|(l<<3|(t<0?1:0)|(e<0?2:0)|(n<0?4:0))<<24}function ba(t,e){const n=[];let a=0,s=null;const r=new kn(((t,r)=>{if(n.push(t),a+=t.length,r||a>=e){const t=new Uint8Array(a);let r=0;for(const e of n)t.set(e,r),r+=e.length;s=t.slice(0,e)}}));let i=0;for(;null==s&&i<t.length;){const e=t.slice(i,i+1024);r.push(e,!1),i+=1024}if(null==s&&(r.push(new Uint8Array,!0),null==s))throw new Error("Failed to decompress partial gzip");return s}function Sa(t,e,n,a,s){const r=t.getContext(),i=t.properties.get(e),o=null==i?void 0:i.__webglTexture;if(!o)throw new Error("texture not found");const l=r.getParameter(r.UNPACK_FLIP_Y_WEBGL),u=r.getParameter(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL);t.state.activeTexture(r.TEXTURE0),t.state.bindTexture(r.TEXTURE_2D,o),r.bindBuffer(r.PIXEL_UNPACK_BUFFER,null),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!1),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),r.texSubImage2D(r.TEXTURE_2D,0,0,0,n,a,r.RGBA_INTEGER,r.UNSIGNED_INT,s),t.state.unbindTexture(),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,l),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,u)}const Ta=Object.freeze(Object.defineProperty({__proto__:null,DataCache:class{constructor({asyncFetch:t,dispose:e,maxItems:n=5}){this.asyncFetch=t,this.dispose=e,this.maxItems=n,this.items=[],this.pending=new Map}has(t){return this.items.some((e=>e.key===t))}getImmediate(t){const e=this.items.findIndex((e=>e.key===t));if(e>=0){const t=this.items.splice(e,1)[0];return this.items.push(t),t.data}}async getFetch(t){const e=this.getImmediate(t);if(void 0!==e)return e;let n=this.pending.get(t);return n||(n=this.asyncFetch(t).then((e=>{for(this.pending.delete(t),this.items.push({key:t,data:e});this.items.length>this.maxItems;){const t=this.items.shift();t&&this.dispose&&this.dispose(t.data)}return e})),this.pending.set(t,n),n)}},FreeList:class{constructor({allocate:t,dispose:e,valid:n}){this.items=[],this.allocate=t,this.dispose=e,this.valid=n}alloc(t){for(;;){const e=this.items.pop();if(!e)break;if(this.valid(e,t))return e;this.dispose&&this.dispose(e)}return this.allocate(t)}free(t){this.items.push(t)}disposeAll(){let t;for(t=this.items.pop();t;)this.dispose&&this.dispose(t),t=this.items.pop()}},GunzipReader:class{constructor({fileBytes:t,chunkBytes:e=65536}){this.fileBytes=t,this.chunkBytes=e,this.chunks=[],this.totalBytes=0;const n=new DecompressionStream("gzip"),a=new Blob([t]).stream().pipeThrough(n);this.reader=a.getReader()}async read(t){for(;this.totalBytes<t;){const{value:t,done:e}=await this.reader.read();if(e)break;this.chunks.push(t),this.totalBytes+=t.length}if(this.totalBytes<t)throw new Error(`Unexpected EOF: needed ${t}, got ${this.totalBytes}`);const e=new Uint8Array(this.totalBytes);let n=0;for(const s of this.chunks)e.set(s,n),n+=s.length;const a=e.subarray(0,t);return this.chunks=[e.subarray(t)],this.totalBytes-=t,a}},IDENT_VERTEX_SHADER:ca,Sint8ToFloat:Wn,Uint8ToFloat:Hn,averagePositions:function(e){const n=new t.Vector3;for(const t of e)n.add(t);return n.divideScalar(e.length)},averageQuaternions:function(e){if(0===e.length)return new t.Quaternion;const n=e[0].clone();for(let t=1;t<e.length;t++)e[t].dot(e[0])<0?(n.x-=e[t].x,n.y-=e[t].y,n.z-=e[t].z,n.w-=e[t].w):(n.x+=e[t].x,n.y+=e[t].y,n.z+=e[t].z,n.w+=e[t].w);return n.normalize()},coinciDist:pa,computeMaxSplats:function(t){const e=i,n=Math.max(1,Math.min(o,Math.ceil(t/e)));return e*n*Math.ceil(t/(e*n))},coorientDist:da,decodeExtRgb:function(t){const e=Zn.color,n=2**((t>>>27&31)-15)/255,a=(255&t)*n,s=(t>>>8&255)*n,r=(t>>>16&255)*n;return e.r=16777216&t?-a:a,e.g=33554432&t?-s:s,e.b=67108864&t?-r:r,e},decodeExtSplat:Xn,decodeQuatEulerXyz888:function(t,e){const n=(t>>>8&255)/255,a=(t>>>16&255)/255,s=(255&t)/255*(2*Math.PI)-Math.PI,r=n*(2*Math.PI)-Math.PI,i=a*(2*Math.PI)-Math.PI,o=Math.cos(.5*s),l=Math.sin(.5*s),u=Math.cos(.5*r),c=Math.sin(.5*r),p=Math.cos(.5*i),d=Math.sin(.5*i);return e.w=o*u*p+l*c*d,e.x=l*u*p-o*c*d,e.y=o*c*p+l*u*d,e.z=o*u*d-l*c*p,e.normalize(),e},decodeQuatOctXy1010R12:ga,decodeQuatOctXy88R8:ma,decodeQuatXyz888:function(t,e){const n=t<<24>>24,a=t<<16>>24,s=t<<8>>24;e.set(n/127,a/127,s/127,0);const r=e.x*e.x+e.y*e.y+e.z*e.z;return e.w=Math.sqrt(Math.max(0,1-r)),e},decompressPartialGzip:ba,encodeExt3Rgb:function(t,e,n,a){const s=4*n;for(let r=0;r<4;++r){const e=3*r;t[s+r]=wa(a[e],a[e+1],a[e+2])}for(let r=4;r<7;++r){const t=3*r;e[s+(r-4)]=wa(a[t],a[t+1],a[t+2])}},encodeExtRgb:wa,encodeExtSh12Rgb:function(t,e,n,a,s){const r=4*n;for(let i=0;i<3;++i){const e=3*i;t[r+i]=wa(a[e],a[e+1],a[e+2])}t[r+3]=wa(s[0],s[1],s[2]);for(let i=1;i<5;++i){const t=5*i;e[r+(i-1)]=wa(s[t],s[t+1],s[t+2])}},encodeExtSh1Rgb:function(t,e,n){const a=4*e;for(let s=0;s<3;++s){const e=3*s;t[a+s]=wa(n[e],n[e+1],n[e+2])}},encodeExtSplat:Kn,encodeQuatEulerXyz888:function(t){const e=t.clone().normalize(),n=2*(e.w*e.x+e.y*e.z),a=1-2*(e.x*e.x+e.y*e.y),s=Math.atan2(n,a),r=2*(e.w*e.y-e.z*e.x),i=Math.abs(r)>=1?Math.sign(r)*(Math.PI/2):Math.asin(r),o=2*(e.w*e.z+e.x*e.y),l=1-2*(e.y*e.y+e.z*e.z),u=Math.atan2(o,l),c=(s+Math.PI)/(2*Math.PI),p=(i+Math.PI)/(2*Math.PI),d=(u+Math.PI)/(2*Math.PI),h=Math.round(255*c),x=Math.round(255*p);return Math.round(255*d)<<16|x<<8|h},encodeQuatOctXy1010R12:ya,encodeQuatOctXy88R8:fa,encodeQuatXyz888:function(t){const e=t.w<0;return 255&Gn(e?-t.x:t.x)|(255&Gn(e?-t.y:t.y))<<8|(255&Gn(e?-t.z:t.z))<<16},encodeSh1Rgb:function(t,e,n,a){const s=63/((null==a?void 0:a.sh1Max)??1),r=2*e;for(let i=0;i<9;++i){const e=n[i]*s,a=127&Math.round(Math.max(-63,Math.min(63,e))),o=7*i,l=o+7,u=Math.floor(o/32),c=o-32*u,p=a<<c&4294967295;if(t[r+u]|=p,l>32*u+32){const e=a>>>32-c&4294967295;t[r+u+1]|=e}}},encodeSh2Rgb:function(t,e,n,a){const s=1/((null==a?void 0:a.sh2Max)??1);t[4*e+0]=va(n[0]*s,n[1]*s,n[2]*s,n[3]*s),t[4*e+1]=va(n[4]*s,n[5]*s,n[6]*s,n[7]*s),t[4*e+2]=va(n[8]*s,n[9]*s,n[10]*s,n[11]*s),t[4*e+3]=va(n[12]*s,n[13]*s,n[14]*s,0)},encodeSh3Rgb:function(t,e,n,a){const s=31/((null==a?void 0:a.sh3Max)??1),r=4*e;for(let i=0;i<21;++i){const e=n[i]*s,a=63&Math.round(Math.max(-31,Math.min(31,e))),o=6*i,l=o+6,u=Math.floor(o/32),c=o-32*u,p=a<<c&4294967295;if(t[r+u]|=p,l>32*u+32){const e=a>>>32-c&4294967295;t[r+u+1]|=e}}},epsilonSign:function(t,e=.001){return Math.abs(t)<e?0:Math.sign(t)},flipPixels:la,floatBitsToUint:Un,floatToSint8:Gn,floatToUint8:On,fromHalf:Nn,getTextureSize:ea,getTransferable:jn,isAndroid:aa,isIos:ia,isMobile:na,isOculus:sa,isQuest2:ra,isVisionPro:oa,mapFilterObject:function(t,e){const n=Object.entries(t).map((([t,n])=>[t,e(n,t)])).filter((([t,e])=>void 0!==e));return Object.fromEntries(n)},mapObject:function(t,e){const n=Object.entries(t).map((([t,n])=>[t,e(n,t)]));return Object.fromEntries(n)},newArray:Qn,normalize:function(t){const e=Math.sqrt(t.reduce(((t,e)=>t+e*e),0));return t.map((t=>t/e))},omitUndefined:function(t){return Object.fromEntries(Object.entries(t).filter((([t,e])=>void 0!==e)))},pixelsToPngUrl:ua,setPackedSplat:Yn,setPackedSplatCenter:function(t,e,n,a,s){const r=Bn(n),i=Bn(a),o=Bn(s),l=4*e;t[l+1]=r|i<<16,t[l+2]=o|4294901760&t[l+2]},setPackedSplatOpacity:function(t,e,n){const a=On(n),s=4*e;t[s]=16777215&t[s]|a<<24},setPackedSplatQuat:function(t,e,n,a,s,r){const i=fa(Jn.set(n,a,s,r)),o=255&i,l=i>>>8&255,u=i>>>16&255,c=4*e;t[c+2]=65535&t[c+2]|o<<16|l<<24,t[c+3]=16777215&t[c+3]|u<<24},setPackedSplatRgb:function(t,e,n,a,s,r){const i=(null==r?void 0:r.rgbMin)??0,o=((null==r?void 0:r.rgbMax)??1)-i,l=On((n-i)/o),u=On((a-i)/o),c=On((s-i)/o),p=4*e;t[p]=l|u<<8|c<<16|4278190080&t[p]},setPackedSplatRgba:function(t,e,n,a,s,r,i){const o=(null==i?void 0:i.rgbMin)??0,l=((null==i?void 0:i.rgbMax)??1)-o,u=On((n-o)/l),c=On((a-o)/l),p=On((s-o)/l),d=On((null==i?void 0:i.lodOpacity)?.5*r:r);t[4*e]=u|c<<8|p<<16|d<<24},setPackedSplatScales:function(t,e,a,s,i,o){const l=(null==o?void 0:o.lnScaleMin)??n,u=254/(((null==o?void 0:o.lnScaleMax)??9)-l),c=a<r?0:Math.min(255,Math.max(1,Math.round((Math.log(a)-l)*u)+1)),p=s<r?0:Math.min(255,Math.max(1,Math.round((Math.log(s)-l)*u)+1)),d=i<r?0:Math.min(255,Math.max(1,Math.round((Math.log(i)-l)*u)+1)),h=4*e;t[h+3]=c|p<<8|d<<16|4278190080&t[h+3]},threeMrtArray:Fn,threeRevision:An,toHalf:Bn,uintBitsToFloat:Vn,unpackSplat:ta,uploadU32DataTextureRows:Sa,withinCoinciDist:function({matrix1:t,matrix2:e,maxDistance:n,minCoincidence:a}){const{distance:s,coincidence:r}=pa(t,e);return s<=n&&(null==a||r>=a)},withinCoorientDist:function({matrix1:t,matrix2:e,maxDistance:n,minCoorient:a}){const{distance:s,coorient:r}=da(t,e);return s<=n&&(null==a||r>=a)},withinDist:function({matrix1:e,matrix2:n,maxDistance:a}){const s=new t.Vector3(0,0,0).applyMatrix4(e),r=new t.Vector3(0,0,0).applyMatrix4(n);return s.distanceTo(r)<=a}},Symbol.toStringTag,{value:"Module"}));class _a{constructor({graph:t,inputs:e,outputs:n,template:a,consoleLog:s}){this.graph=t,this.template=a,this.inputs=e??{},this.outputs=n??{};const r=new V({indent:this.template.indent});for(const o in this.outputs)this.outputs[o]&&r.declares.add(this.outputs[o]);const i=t.compile({inputs:this.inputs,outputs:this.outputs,compile:r});this.shader=a.generate({globals:r.globals,statements:i}),this.uniforms=r.uniforms,this.updaters=r.updaters}prepareMaterial(){return function(e){let n=ka.get(e);if(n)return n;return n=new t.RawShaderMaterial({glslVersion:t.GLSL3,vertexShader:ca,fragmentShader:e.shader,uniforms:e.uniforms}),ka.set(e,n),n}(this)}update(){for(const t of this.updaters)t()}}class Ma{constructor(t){const e=t.match(/^([ \t]*)\{\{\s*GLOBALS\s*\}\}/m),n=t.match(/^([ \t]*)\{\{\s*STATEMENTS\s*\}\}/m);if(!e||!n)throw new Error("Template must contain {{ GLOBALS }} and {{ STATEMENTS }}");this.before=t.substring(0,e.index),this.between=t.substring(e.index+e[0].length,n.index),this.after=t.substring(n.index+n[0].length),this.indent=n[1]}generate({globals:t,statements:e}){return this.before+Array.from(t).join("\n\n")+this.between+e.map((t=>this.indent+t)).join("\n")+this.after}}const ka=new WeakMap;function $a(t,e,n="add"){const a=()=>{throw new Error(`Invalid ${n} types: ${t}, ${e}`)};if(t===e)return t;if("int"===t){if(h(e))return e;a()}if("int"===e){if(h(t))return t;a()}if("uint"===t){if(x(e))return e;a()}if("uint"===e){if(x(t))return t;a()}if("float"===t){if(y(e))return e;a()}if("float"===e){if(y(t))return t;a()}throw new Error(`Invalid ${n} types: ${t}, ${e}`)}function Da(t,e){return $a(t,e,"sub")}function za(t,e){const n=()=>{throw new Error(`Invalid mul types: ${t}, ${e}`)};if("int"===t){if(h(e))return e;n()}if("int"===e){if(h(t))return t;n()}if("uint"===t){if(x(e))return e;n()}if("uint"===e){if(x(t))return t;n()}if("float"===t){if(y(e))return e;n()}if("float"===e){if(y(t))return t;n()}if(h(t)||x(t)||h(e)||x(e)){if(t===e)return t;n()}if("vec2"===t){if("vec2"===e||b(e))return"vec2";if("mat3x2"===e)return"vec3";if("mat4x2"===e)return"vec4";n()}if("vec3"===t){if("mat2x3"===e)return"vec2";if("vec3"===e||S(e))return"vec3";if("mat4x3"===e)return"vec4";n()}if("vec4"===t){if("mat2x4"===e)return"vec2";if("mat3x4"===e)return"vec3";if("vec4"===e||T(e))return"vec4";n()}if("vec2"===e){if(b(t))return"vec2";if("mat2x3"===t)return"vec3";if("mat2x4"===t)return"vec4";n()}if("vec3"===e){if("mat3x2"===t)return"vec2";if(S(t))return"vec3";if("mat3x4"===t)return"vec4";n()}if("vec4"===e){if("mat4x2"===t)return"vec2";if("mat4x3"===t)return"vec3";if(T(t))return"vec4";n()}if(b(t)){if(b(e))return"mat2";if("mat3x2"===e)return"mat3x2";if("mat4x2"===e)return"mat4x2";n()}if("mat2x3"===t){if(b(e))return"mat2x3";if("mat3x2"===e)return"mat3";if("mat4x2"===e)return"mat4x3";n()}if("mat2x4"===t){if(b(e))return"mat2x4";if("mat3x2"===e)return"mat3x4";if("mat4x2"===e)return"mat4";n()}if("mat3x2"===t){if("mat2x3"===e)return"mat2";if(S(e))return"mat3x2";if("mat4x3"===e)return"mat4x2";n()}if(S(t)){if("mat2x3"===e)return"mat2x3";if(S(e))return"mat3";if("mat4x3"===e)return"mat4x3";n()}if("mat3x4"===t){if("mat2x3"===e)return"mat2x4";if(S(e))return"mat3x4";if("mat4x3"===e)return"mat4";n()}if("mat4x2"===t){if("mat2x4"===e)return"mat2";if("mat3x4"===e)return"mat3x2";if(T(e))return"mat4x2";n()}if("mat4x3"===t){if("mat2x4"===e)return"mat2x3";if("mat3x4"===e)return"mat3";if(T(e))return"mat4x3";n()}if(T(t)){if("mat2x4"===e)return"mat2x4";if("mat3x4"===e)return"mat3x4";if(T(e))return"mat4";n()}throw new Error(`Invalid mul types: ${t}, ${e}`)}function Ia(t,e){return $a(t,e,"div")}function Ea(t,e){if(t===e)return t;if("int"===t){if(h(e))return e}else if("int"===e){if(h(t))return t}else if("uint"===t){if(x(e))return e}else if("uint"===e&&x(t))return t;throw new Error(`Invalid imod types: ${t}, ${e}`)}function Aa(t,e){if(t===e||"float"===e)return t;throw new Error(`Invalid mod types: ${t}, ${e}`)}function Fa(t){return t}function Pa(t){return t}function Ca(t){return t}function La(t){return t}function Ra(t){return t}function qa(t){return t}function Ua(t){return t}function Va(t){return t}function Ba(t){return t}function Na(t){return t}function Oa(t){return t}function Ga(t){return t}function Ha(t){return t}function Wa(t){return t}function ja(t){return t}function Qa(t){return t}function Ka(t,e,n="min"){if(t===e)return t;if("float"===e){if(f(t))return t}else if("int"===e){if(h(t))return t}else if("uint"===e&&x(t))return t;throw new Error(`Invalid ${n} types: ${t}, ${e}`)}function Xa(t,e){return Ka(t,e,"max")}function Ya(t,e,n){if("float"===e){if(f(t))return t}else if("int"===e){if(h(t))return t}else if("uint"===e&&x(t))return t;throw new Error(`Invalid clamp types: ${t}, ${e}`)}function Ja(t,e,n){if(n===t)return t;if("float"===n)return t;if("bool"===n&&"float"===t)return t;if("bvec2"===n&&"vec2"===t)return t;if("bvec3"===n&&"vec3"===t)return t;if("bvec4"===n&&"vec4"===t)return t;throw new Error(`Invalid mix types: ${t}, ${e}, ${n}`)}function Za(t,e){if(t===e||"float"===e)return e;throw new Error(`Invalid step types: ${t}, ${e}`)}function ts(t,e,n){if(t===e&&(t===n||"float"===t))return n;throw new Error(`Invalid smoothstep types: ${t}, ${e}, ${n}`)}function es(t,e="isNan"){if("float"===t)return"bool";if("vec2"===t)return"bvec2";if("vec3"===t)return"bvec3";if("vec4"===t)return"bvec4";throw new Error(`Invalid ${e} types: ${t}`)}function ns(t){return es(t,"isInf")}const as=(t,e)=>new hs({a:t,b:e}),ss=(t,e)=>new xs({a:t,b:e}),rs=(t,e)=>new fs({a:t,b:e}),is=(t,e)=>new ms({a:t,b:e}),os=(t,e)=>new ys({a:t,b:e}),ls=(t,e)=>new gs({a:t,b:e}),us=t=>new ws({a:t}),cs=t=>new $s({a:t}),ps=(t,e)=>new Rs({a:t,b:e}),ds=(t,e,n)=>new Us({a:t,b:e,t:n});class hs extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"sum",outTypeFunc:$a}),this.statements=({inputs:t,outputs:e})=>[`${e.sum} = ${t.a} + ${t.b};`]}}class xs extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"difference",outTypeFunc:Da}),this.statements=({inputs:t,outputs:e})=>[`${e.difference} = ${t.a} - ${t.b};`]}}class fs extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"product",outTypeFunc:za}),this.statements=({inputs:t,outputs:e})=>[`${e.product} = ${t.a} * ${t.b};`]}}class ms extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"quotient",outTypeFunc:Ia}),this.statements=({inputs:t,outputs:e})=>[`${e.quotient} = ${t.a} / ${t.b};`]}}class ys extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"remainder",outTypeFunc:Ea}),this.statements=({inputs:t,outputs:e})=>[`${e.remainder} = ${t.a} % ${t.b};`]}}class gs extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"remainder",outTypeFunc:Aa}),this.statements=({inputs:t,outputs:e})=>[`${e.remainder} = mod(${t.a}, ${t.b});`]}}class vs extends B{constructor({a:t}){const e={a:E(t)},n=e.a;super({inTypes:e,outTypes:{fract:n,integer:n},inputs:{a:t}}),this.statements=({inputs:t,outputs:e})=>[`${e.fract} = modf(${t.a}, ${e.integer});`]}}class ws extends Q{constructor({a:t}){super({a:t,outKey:"neg",outTypeFunc:Fa}),this.statements=({inputs:t,outputs:e})=>[`${e.neg} = -${t.a};`]}}class bs extends Q{constructor({a:t}){super({a:t,outKey:"abs",outTypeFunc:Pa}),this.statements=({inputs:t,outputs:e})=>[`${e.abs} = abs(${t.a});`]}}class Ss extends Q{constructor({a:t}){super({a:t,outKey:"sign",outTypeFunc:Ca}),this.statements=({inputs:t,outputs:e})=>[`${e.sign} = sign(${t.a});`]}}class Ts extends Q{constructor({a:t}){super({a:t,outKey:"floor",outTypeFunc:La}),this.statements=({inputs:t,outputs:e})=>[`${e.floor} = floor(${t.a});`]}}class _s extends Q{constructor({a:t}){super({a:t,outKey:"ceil",outTypeFunc:Ra}),this.statements=({inputs:t,outputs:e})=>[`${e.ceil} = ceil(${t.a});`]}}class Ms extends Q{constructor({a:t}){super({a:t,outKey:"trunc",outTypeFunc:qa}),this.statements=({inputs:t,outputs:e})=>[`${e.trunc} = trunc(${t.a});`]}}class ks extends Q{constructor({a:t}){super({a:t,outKey:"round",outTypeFunc:Ua}),this.statements=({inputs:t,outputs:e})=>[`${e.round} = round(${t.a});`]}}class $s extends Q{constructor({a:t}){super({a:t,outKey:"fract",outTypeFunc:Va}),this.statements=({inputs:t,outputs:e})=>[`${e.fract} = fract(${t.a});`]}}class Ds extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"power",outTypeFunc:Ba}),this.statements=({inputs:t,outputs:e})=>[`${e.power} = pow(${t.a}, ${t.b});`]}}class zs extends Q{constructor({a:t}){super({a:t,outKey:"exp",outTypeFunc:Na}),this.statements=({inputs:t,outputs:e})=>[`${e.exp} = exp(${t.a});`]}}class Is extends Q{constructor({a:t}){super({a:t,outKey:"exp2",outTypeFunc:Oa}),this.statements=({inputs:t,outputs:e})=>[`${e.exp2} = exp2(${t.a});`]}}class Es extends Q{constructor({a:t}){super({a:t,outKey:"log",outTypeFunc:Ga}),this.statements=({inputs:t,outputs:e})=>[`${e.log} = log(${t.a});`]}}class As extends Q{constructor({a:t}){super({a:t,outKey:"log2",outTypeFunc:Ha}),this.statements=({inputs:t,outputs:e})=>[`${e.log2} = log2(${t.a});`]}}class Fs extends Q{constructor({a:t}){super({a:t,outKey:"sqr",outTypeFunc:Wa}),this.statements=({inputs:t,outputs:e})=>[`${e.sqr} = ${t.a} * ${t.a};`]}}class Ps extends Q{constructor({a:t}){super({a:t,outKey:"sqrt",outTypeFunc:ja}),this.statements=({inputs:t,outputs:e})=>[`${e.sqrt} = sqrt(${t.a});`]}}class Cs extends Q{constructor({a:t}){super({a:t,outKey:"inversesqrt",outTypeFunc:Qa}),this.statements=({inputs:t,outputs:e})=>[`${e.inversesqrt} = inversesqrt(${t.a});`]}}class Ls extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"min",outTypeFunc:Ka}),this.statements=({inputs:t,outputs:e})=>[`${e.min} = min(${t.a}, ${t.b});`]}}class Rs extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"max",outTypeFunc:Xa}),this.statements=({inputs:t,outputs:e})=>[`${e.max} = max(${t.a}, ${t.b});`]}}class qs extends X{constructor({a:t,min:e,max:n}){super({a:t,b:e,c:n,outKey:"clamp",outTypeFunc:Ya}),this.statements=({inputs:t,outputs:e})=>{const{a:n,b:a,c:s}=t;return[`${e.clamp} = clamp(${n}, ${a}, ${s});`]}}}class Us extends X{constructor({a:t,b:e,t:n}){super({a:t,b:e,c:n,outKey:"mix",outTypeFunc:Ja}),this.statements=({inputs:t,outputs:e})=>{const{a:n,b:a,c:s}=t;return[`${e.mix} = mix(${n}, ${a}, ${s});`]}}}class Vs extends K{constructor({edge:t,x:e}){super({a:t,b:e,outKey:"step",outTypeFunc:Za}),this.statements=({inputs:t,outputs:e})=>{const{a:n,b:a}=t;return[`${e.step} = step(${n}, ${a});`]}}}class Bs extends X{constructor({edge0:t,edge1:e,x:n}){super({a:t,b:e,c:n,outKey:"smoothstep",outTypeFunc:ts}),this.statements=({inputs:t,outputs:e})=>{const{a:n,b:a,c:s}=t;return[`${e.smoothstep} = smoothstep(${n}, ${a}, ${s});`]}}}class Ns extends Q{constructor({a:t}){super({a:t,outKey:"isNan",outTypeFunc:es}),this.statements=({inputs:t,outputs:e})=>[`${e.isNan} = isNan(${t.a});`]}}class Os extends Q{constructor({a:t}){super({a:t,outKey:"isInf",outTypeFunc:ns}),this.statements=({inputs:t,outputs:e})=>[`${e.isInf} = isInf(${t.a});`]}}const Gs=(t,e)=>new Zs({a:t,b:e}),Hs=(t,e,n)=>new sr({cond:t,t:e,f:n});class Ws extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"and"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.and?[`${e.and} = ${t.a} && ${t.b};`]:[`${e.and} = ${t.a} & ${t.b};`]}}class js extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"or"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.or?[`${e.or} = ${t.a} || ${t.b};`]:[`${e.or} = ${t.a} | ${t.b};`]}}class Qs extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"xor"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.xor?[`${e.xor} = ${t.a} ^^ ${t.b};`]:[`${e.xor} = ${t.a} ^ ${t.b};`]}}class Ks extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>t,outKey:"not"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.not?[`${e.not} = !${t.a};`]:[`${e.not} = not(${t.a});`]}}class Xs extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>rr(t,"lessThan"),outKey:"lessThan"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.lessThan?[`${e.lessThan} = ${t.a} < ${t.b};`]:[`${e.lessThan} = lessThan(${t.a}, ${t.b});`]}}class Ys extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>rr(t,"lessThanEqual"),outKey:"lessThanEqual"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.lessThanEqual?[`${e.lessThanEqual} = ${t.a} <= ${t.b};`]:[`${e.lessThanEqual} = lessThanEqual(${t.a}, ${t.b});`]}}class Js extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>rr(t,"greaterThan"),outKey:"greaterThan"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.greaterThan?[`${e.greaterThan} = ${t.a} > ${t.b};`]:[`${e.greaterThan} = greaterThan(${t.a}, ${t.b});`]}}class Zs extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>rr(t,"greaterThanEqual"),outKey:"greaterThanEqual"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.greaterThanEqual?[`${e.greaterThanEqual} = ${t.a} >= ${t.b};`]:[`${e.greaterThanEqual} = greaterThanEqual(${t.a}, ${t.b});`]}}class tr extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:ir,outKey:"equal"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.equal?[`${e.equal} = ${t.a} == ${t.b};`]:[`${e.equal} = equal(${t.a}, ${t.b});`]}}class er extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:or,outKey:"notEqual"}),this.statements=({inputs:t,outputs:e})=>"bool"===this.outTypes.notEqual?[`${e.notEqual} = ${t.a} != ${t.b};`]:[`${e.notEqual} = notEqual(${t.a}, ${t.b});`]}}class nr extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>"bool",outKey:"any"}),this.statements=({inputs:t,outputs:e})=>[`${e.any} = any(${t.a});`]}}class ar extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>"bool",outKey:"all"}),this.statements=({inputs:t,outputs:e})=>[`${e.all} = all(${t.a});`]}}class sr extends X{constructor({cond:t,t:e,f:n}){super({a:t,b:e,c:n,outKey:"select",outTypeFunc:(t,e,n)=>e}),this.statements=({inputs:t,outputs:e})=>{const{a:n,b:a,c:s}=t;return[`${e.select} = (${n}) ? (${a}) : (${s});`]}}}function rr(t,e){if(d(t))return"bool";if("ivec2"===t||"uvec2"===t||"vec2"===t)return"bvec2";if("ivec3"===t||"uvec3"===t||"vec3"===t)return"bvec3";if("ivec4"===t||"uvec4"===t||"vec4"===t)return"bvec4";throw new Error(`Invalid ${e} type: ${t}`)}function ir(t,e="equal"){if(d(t))return"bool";if(p(t))return t;if("ivec2"===t||"uvec2"===t||"vec2"===t)return"bvec2";if("ivec3"===t||"uvec3"===t||"vec3"===t)return"bvec3";if("ivec4"===t||"uvec4"===t||"vec4"===t)return"bvec4";throw new Error(`Invalid ${e} type: ${t}`)}function or(t){return ir(t,"notEqual")}class lr extends Q{constructor({a:t}){const e=function(t){if(p(t))return"bool";if(h(t))return"int";if(x(t))return"uint";throw new Error(`Invalid compXor type: ${t}`)}(E(t));super({a:t,outTypeFunc:t=>e,outKey:"compXor"}),this.statements=({inputs:t,outputs:n})=>{if(d(this.outTypes.compXor))return[`${n.compXor} = ${t.a};`];const a=(g(e)?["x","y"]:v(e)?["x","y","z"]:["x","y","z","w"]).map((e=>`${t.a}.${e}`)),s=p(e)?"^^":"^";return[`${n.compXor} = ${a.join(` ${s} `)};`]}}}class ur extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"shr"}),this.statements=({inputs:t,outputs:e})=>[`${e.shr} = ${t.a} >> ${t.b};`]}}class cr extends K{constructor({a:t,b:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"shl"}),this.statements=({inputs:t,outputs:e})=>[`${e.shl} = ${t.a} << ${t.b};`]}}const pr=t=>new wr({value:t}),dr=t=>new Ir({value:t}),hr=t=>new Er({value:t}),xr=t=>new Ar({value:t}),fr=t=>new Lr({value:t});class mr extends Q{constructor({value:t,outType:e,outKey:n}){super({a:t,outTypeFunc:()=>e,outKey:n}),this.statements=({inputs:t,outputs:a})=>[`${a[n]} = ${$(e)}(${t.a});`]}}class yr extends mr{constructor({value:t}){super({value:t,outType:"bool",outKey:"bool"})}}class gr extends mr{constructor({value:t}){super({value:t,outType:"int",outKey:"int"})}}class vr extends mr{constructor({value:t}){super({value:t,outType:"uint",outKey:"uint"})}}class wr extends mr{constructor({value:t}){super({value:t,outType:"float",outKey:"float"})}}class br extends mr{constructor({value:t}){super({value:t,outType:"bvec2",outKey:"bvec2"})}}class Sr extends mr{constructor({value:t}){super({value:t,outType:"bvec3",outKey:"bvec3"})}}class Tr extends mr{constructor({value:t}){super({value:t,outType:"bvec4",outKey:"bvec4"})}}class _r extends mr{constructor({value:t}){super({value:t,outType:"ivec2",outKey:"ivec2"})}}class Mr extends mr{constructor({value:t}){super({value:t,outType:"ivec3",outKey:"ivec3"})}}class kr extends mr{constructor({value:t}){super({value:t,outType:"ivec4",outKey:"ivec4"})}}class $r extends mr{constructor({value:t}){super({value:t,outType:"uvec2",outKey:"uvec2"})}}class Dr extends mr{constructor({value:t}){super({value:t,outType:"uvec3",outKey:"uvec3"})}}class zr extends mr{constructor({value:t}){super({value:t,outType:"uvec4",outKey:"uvec4"})}}class Ir extends mr{constructor({value:t}){super({value:t,outType:"vec2",outKey:"vec2"})}}class Er extends mr{constructor({value:t}){super({value:t,outType:"vec3",outKey:"vec3"})}}class Ar extends mr{constructor({value:t}){super({value:t,outType:"vec4",outKey:"vec4"})}}class Fr extends mr{constructor({value:t}){super({value:t,outType:"mat2",outKey:"mat2"})}}class Pr extends mr{constructor({value:t}){super({value:t,outType:"mat3",outKey:"mat3"})}}class Cr extends mr{constructor({value:t}){super({value:t,outType:"mat4",outKey:"mat4"})}}class Lr extends Q{constructor({value:t}){super({a:t,outKey:"int",outTypeFunc:()=>"int"}),this.statements=({inputs:t,outputs:e})=>[`${e.int} = floatBitsToInt(${t.a});`]}}class Rr extends Q{constructor({value:t}){super({a:t,outKey:"uint",outTypeFunc:()=>"uint"}),this.statements=({inputs:t,outputs:e})=>[`${e.uint} = floatBitsToUint(${t.a});`]}}class qr extends Q{constructor({value:t}){super({a:t,outKey:"float",outTypeFunc:()=>"float"}),this.statements=({inputs:t,outputs:e})=>[`${e.float} = intBitsToFloat(${t.a});`]}}class Ur extends Q{constructor({value:t}){super({a:t,outKey:"float",outTypeFunc:()=>"float"}),this.statements=({inputs:t,outputs:e})=>[`${e.float} = uintBitsToFloat(${t.a});`]}}class Vr extends Q{constructor({value:t}){super({a:t,outKey:"uint",outTypeFunc:()=>"uint"}),this.statements=({inputs:t,outputs:e})=>[`${e.uint} = packSnorm2x16(${t.a});`]}}class Br extends Q{constructor({value:t}){super({a:t,outKey:"vec2",outTypeFunc:()=>"vec2"}),this.statements=({inputs:t,outputs:e})=>[`${e.vec2} = unpackSnorm2x16(${t.a});`]}}class Nr extends Q{constructor({value:t}){super({a:t,outKey:"uint",outTypeFunc:()=>"uint"}),this.statements=({inputs:t,outputs:e})=>[`${e.uint} = packUnorm2x16(${t.a});`]}}class Or extends Q{constructor({value:t}){super({a:t,outKey:"vec2",outTypeFunc:()=>"vec2"}),this.statements=({inputs:t,outputs:e})=>[`${e.vec2} = unpackUnorm2x16(${t.a});`]}}class Gr extends Q{constructor({value:t}){super({a:t,outKey:"uint",outTypeFunc:()=>"uint"}),this.statements=({inputs:t,outputs:e})=>[`${e.uint} = packHalf2x16(${t.a});`]}}class Hr extends Q{constructor({value:t}){super({a:t,outKey:"vec2",outTypeFunc:()=>"vec2"}),this.statements=({inputs:t,outputs:e})=>[`${e.vec2} = unpackHalf2x16(${t.a});`]}}class Wr extends Q{constructor({value:t}){super({a:t,outKey:"rgba8",outTypeFunc:()=>"vec4"}),this.statements=({inputs:t,outputs:e})=>[`uvec4 uRgba = uvec4(${t.a} & 0xffu, (${t.a} >> 8u) & 0xffu, (${t.a} >> 16u) & 0xffu, (${t.a} >> 24u) & 0xffu);`,`${e.rgba8} = vec4(uRgba) / 255.0;`]}}const jr=(t,e)=>new Zr({a:t,b:e}),Qr=t=>new ei({a:t}),Kr=t=>new xi({vector:t}),Xr=({vector:t,vectorType:e,x:n,y:a,z:s,w:r,r:i,g:o,b:l,a:u})=>new fi({vector:t,vectorType:e,x:n,y:a,z:s,w:r,r:i,g:o,b:l,a:u});class Yr extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>"float",outKey:"length"}),this.statements=({inputs:t,outputs:e})=>[`${e.length} = length(${t.a});`]}}class Jr extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"distance",outTypeFunc:(t,e)=>"float"}),this.statements=({inputs:t,outputs:e})=>[`${e.distance} = distance(${t.a}, ${t.b});`]}}class Zr extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"dot",outTypeFunc:(t,e)=>"float"}),this.statements=({inputs:t,outputs:e})=>[`${e.dot} = dot(${t.a}, ${t.b});`]}}class ti extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"cross",outTypeFunc:(t,e)=>"vec3"}),this.statements=({inputs:t,outputs:e})=>[`${e.cross} = cross(${t.a}, ${t.b});`]}}class ei extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>t,outKey:"normalize"}),this.statements=({inputs:t,outputs:e})=>[`${e.normalize} = normalize(${t.a});`]}}class ni extends Q{constructor({a:t}){super({a:t,outTypeFunc:t=>function(t){if("vec3"===t)return"vec2";if("vec4"===t)return"vec3";throw new Error("Invalid type")}(t),outKey:"projected"}),this.statements=({inputs:t,outputs:e})=>{if("vec3"===this.inTypes.a)return[`${e.projected} = ${t.a}.xy / ${t.a}.z;`];if("vec4"===this.inTypes.a)return[`${e.projected} = ${t.a}.xyz / ${t.a}.w;`];throw new Error("Invalid type")}}}class ai extends K{constructor({a:t,b:e}){const n=function(t){if("float"===t)return"vec2";if("vec2"===t)return"vec3";if("vec3"===t)return"vec4";throw new Error("Invalid type")}(E(t));super({a:t,b:e,outKey:"extend",outTypeFunc:()=>n}),this.statements=({inputs:t,outputs:e})=>[`${e.extend} = ${n}(${t.a}, ${t.b});`]}}class si extends X{constructor({a:t,b:e,c:n}){super({a:t,b:e,c:n,outKey:"forward",outTypeFunc:(t,e,n)=>t}),this.statements=({inputs:t,outputs:e})=>[`${e.forward} = faceforward(${t.a}, ${t.b}, ${t.c});`]}}class ri extends K{constructor({incident:t,normal:e}){super({a:t,b:e,outKey:"reflection",outTypeFunc:(t,e)=>t}),this.statements=({inputs:t,outputs:e})=>[`${e.reflection} = reflect(${t.a}, ${t.b});`]}}class ii extends X{constructor({incident:t,normal:e,eta:n}){super({a:t,b:e,c:n,outKey:"refraction",outTypeFunc:(t,e,n)=>t}),this.statements=({inputs:t,outputs:e})=>[`${e.refraction} = refract(${t.a}, ${t.b}, ${t.c});`]}}class oi extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"product",outTypeFunc:(t,e)=>t}),this.statements=({inputs:n,outputs:a})=>[`${a.product} = matrixCompMult(${t}, ${e});`]}}function li(t,e){if("vec2"===t){if("vec2"===e)return"mat2";if("vec3"===e)return"mat3x2";if("vec4"===e)return"mat4x2"}if("vec3"===t){if("vec2"===e)return"mat2x3";if("vec3"===e)return"mat3";if("vec4"===e)return"mat4x3"}if("vec4"===t){if("vec2"===e)return"mat2x4";if("vec3"===e)return"mat3x4";if("vec4"===e)return"mat4"}throw new Error(`Invalid outer type: ${t}, ${e}`)}class ui extends K{constructor({a:t,b:e}){super({a:t,b:e,outKey:"outer",outTypeFunc:li}),this.statements=({inputs:t,outputs:e})=>[`${e.outer} = outerProduct(${t.a}, ${t.b});`]}}function ci(t){if("mat2"===t)return"mat2";if("mat3"===t)return"mat3";if("mat4"===t)return"mat4";if("mat2x2"===t)return"mat2x2";if("mat2x3"===t)return"mat3x2";if("mat2x4"===t)return"mat4x2";if("mat3x2"===t)return"mat2x3";if("mat3x3"===t)return"mat3x3";if("mat3x4"===t)return"mat4x3";if("mat4x2"===t)return"mat2x4";if("mat4x3"===t)return"mat3x4";if("mat4x4"===t)return"mat4x4";throw new Error(`Invalid transpose type: ${t}`)}class pi extends Q{constructor({a:t}){super({a:t,outKey:"transpose",outTypeFunc:ci}),this.statements=({inputs:t,outputs:e})=>[`${e.transpose} = transpose(${t.a});`]}}class di extends Q{constructor({a:t}){super({a:t,outKey:"det",outTypeFunc:t=>"float"}),this.statements=({inputs:t,outputs:e})=>[`${e.det} = determinant(${t.a});`]}}class hi extends Q{constructor({a:t}){super({a:t,outKey:"inverse",outTypeFunc:t=>t}),this.statements=({inputs:e,outputs:n})=>[`${n.inverse} = inverse(${t});`]}}class xi extends B{constructor({vector:t}){const e={vector:E(t)},n=function(t){switch(t){case"vec2":return{x:"float",y:"float",r:"float",g:"float"};case"vec3":return{x:"float",y:"float",z:"float",r:"float",g:"float",b:"float"};case"vec4":return{x:"float",y:"float",z:"float",w:"float",r:"float",g:"float",b:"float",a:"float"};case"ivec2":return{x:"int",y:"int",r:"int",g:"int"};case"ivec3":return{x:"int",y:"int",z:"int",r:"int",g:"int",b:"int"};case"ivec4":return{x:"int",y:"int",z:"int",w:"int",r:"int",g:"int",b:"int",a:"int"};case"uvec2":return{x:"uint",y:"uint",r:"uint",g:"uint"};case"uvec3":return{x:"uint",y:"uint",z:"uint",r:"uint",g:"uint",b:"uint"};case"uvec4":return{x:"uint",y:"uint",z:"uint",w:"uint",r:"uint",g:"uint",b:"uint",a:"uint"};default:throw new Error(`Invalid vector type: ${t}`)}}(e.vector);super({inTypes:e,outTypes:n,inputs:{vector:t}}),this.statements=({inputs:t,outputs:e})=>{const{x:n,y:a,z:s,w:r,r:i,g:o,b:l,a:u}=e,{vector:c}=t;return[n?`${n} = ${c}.x;`:null,a?`${a} = ${c}.y;`:null,s?`${s} = ${c}.z;`:null,r?`${r} = ${c}.w;`:null,i?`${i} = ${c}.r;`:null,o?`${o} = ${c}.g;`:null,l?`${l} = ${c}.b;`:null,u?`${u} = ${c}.a;`:null].filter(Boolean)}}}class fi extends B{constructor({vector:t,vectorType:e,x:n,y:a,z:s,w:r,r:i,g:o,b:l,a:u}){if(!t&&!e)throw new Error("Either vector or vectorType must be provided");const c=e??E(t),p=_(c),d=M(c),h={vector:c,x:p,y:p,r:p,g:p},x={vector:t,x:n,y:a,r:i,g:o};d>=3&&(Object.assign(h,{z:p,b:p}),Object.assign(x,{z:s,b:l})),d>=4&&(Object.assign(h,{w:p,a:p}),Object.assign(x,{w:r,a:u})),super({inTypes:h,outTypes:{vector:c},inputs:x}),this.statements=({inputs:t,outputs:e})=>{const{vector:n}=e,{vector:a,x:s,y:r,z:i,w:o,r:l,g:u,b:c,a:h}=t,x=[`${n}.x = ${s??l??(a?`${a}.x`:q(p))};`,`${n}.y = ${r??u??(a?`${a}.y`:q(p))};`];return d>=3&&x.push(`${n}.z = ${i??c??(a?`${a}.z`:q(p))};`),d>=4&&x.push(`${n}.w = ${o??h??(a?`${a}.w`:q(p))};`),x}}dynoOut(){return new F(this,"vector")}}class mi extends Q{constructor({vector:t,select:e}){super({a:t,outKey:"swizzle",outTypeFunc:t=>function(t,e){let n=null;if(f(t)?n=1===e.length?"float":2===e.length?"vec2":3===e.length?"vec3":4===e.length?"vec4":null:h(t)?n=1===e.length?"int":2===e.length?"ivec2":3===e.length?"ivec3":4===e.length?"ivec4":null:x(t)&&(n=1===e.length?"uint":2===e.length?"uvec2":3===e.length?"uvec3":4===e.length?"uvec4":null),null==n)throw new Error(`Invalid swizzle: ${e}`);return n}(t,e)}),this.statements=({inputs:t,outputs:n})=>[`${n.swizzle} = ${t.a}.${e};`]}}const yi=t=>new Di({value:t}),gi=t=>new zi({value:t}),vi=t=>new Ii({value:t}),wi=t=>new Ei({value:t}),bi=t=>new Pi({value:t}),Si=t=>new Ci({value:t}),Ti=(t,e,n)=>new Li({z:t,zNear:e,zFar:n}).outputs.depth;class _i extends B{constructor({from:t,to:e,index:n}){super({inTypes:{from:"int",to:"int",index:"int"},outTypes:{index:"int"},inputs:{from:t,to:e,index:n},statements:({inputs:t,outputs:e})=>[`${e.index} = ${t.index} - ${t.from} + ${t.to};`]})}dynoOut(){return new F(this,"index")}}class Mi extends B{constructor({state:t}){const e=E(t);super({inTypes:{state:e},outTypes:{state:"uint"},inputs:{state:t},globals:()=>[j("\n uint pcg_next(uint state) {\n return state * 747796405u + 2891336453u;\n }\n ")],statements:({inputs:t,outputs:n})=>{const a="uint"===e?`${t.state}`:"int"===e?`uint(${t.state})`:`floatBitsToUint(${t.state})`;return[`${n.state} = pcg_next(${a});`]}})}dynoOut(){return new F(this,"state")}}class ki extends B{constructor({state:t}){super({inTypes:{state:"uint"},outTypes:{hash:"uint"},inputs:{state:t},globals:()=>[j("\n uint pcg_hash(uint state) {\n uint hash = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;\n return (hash >> 22u) ^ hash;\n }\n ")],statements:({inputs:t,outputs:e})=>[`${e.hash} = pcg_hash(${t.state});`]})}dynoOut(){return new F(this,"hash")}}class $i extends B{constructor({value:t}){const e=E(t),n=k(e);super({inTypes:{value:e},outTypes:{state:"uint"},inputs:{value:t},globals:()=>[j("\n uint pcg_mix(uint value) {\n return value;\n }\n uint pcg_mix(uvec2 value) {\n return value.x + 0x9e3779b9u * value.y;\n }\n uint pcg_mix(uvec3 value) {\n return value.x + 0x9e3779b9u * value.y + 0x85ebca6bu * value.z;\n }\n uint pcg_mix(uvec4 value) {\n return value.x + 0x9e3779b9u * value.y + 0x85ebca6bu * value.z + 0xc2b2ae35u * value.w;\n }\n ")],statements:({inputs:t,outputs:a})=>{const s=x(e)?`${t.value}`:h(e)?`${n}(${t.value})`:`floatBitsToUint(${t.value})`;return[`${n} bits = ${s};`,`${a.state} = pcg_mix(bits);`]}})}dynoOut(){return new F(this,"state")}}class Di extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"uint"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");let e=new $i({value:t}).outputs.state;return e=new Mi({state:e}).outputs.state,new ki({state:e}).outputs}})}dynoOut(){return new F(this,"hash")}}class zi extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"uvec2"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");let e=new $i({value:t}).outputs.state;e=new Mi({state:e}).outputs.state;const n=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const a=new ki({state:e}).outputs.hash;return{hash:Xr({vectorType:"uvec2",x:n,y:a})}}})}dynoOut(){return new F(this,"hash")}}class Ii extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"uvec3"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");let e=new $i({value:t}).outputs.state;e=new Mi({state:e}).outputs.state;const n=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const a=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const s=new ki({state:e}).outputs.hash;return{hash:Xr({vectorType:"uvec3",x:n,y:a,z:s})}}})}dynoOut(){return new F(this,"hash")}}class Ei extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"uvec4"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");let e=new $i({value:t}).outputs.state;e=new Mi({state:e}).outputs.state;const n=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const a=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const s=new ki({state:e}).outputs.hash;e=new Mi({state:e}).outputs.state;const r=new ki({state:e}).outputs.hash;return{hash:Xr({vectorType:"uvec4",x:n,y:a,z:s,w:r})}}})}dynoOut(){return new F(this,"hash")}}class Ai extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"float"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");const e=yi(t);return{hash:rs(pr(e),R("float",1/2**32))}}})}dynoOut(){return new F(this,"hash")}}class Fi extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"vec2"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");const e=gi(t);return{hash:rs(dr(e),R("float",1/2**32))}}})}dynoOut(){return new F(this,"hash")}}class Pi extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"vec3"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");const e=vi(t);return{hash:rs(hr(e),R("float",1/2**32))}}})}dynoOut(){return new F(this,"hash")}}class Ci extends N{constructor({value:t}){super({inTypes:{value:E(t)},outTypes:{hash:"vec4"},inputs:{value:t},construct:({value:t})=>{if(!t)throw new Error("value is required");const e=wi(t);return{hash:rs(xr(e),R("float",1/2**32))}}})}dynoOut(){return new F(this,"hash")}}class Li extends B{constructor({z:t,zNear:e,zFar:n}){super({inTypes:{z:"float",zNear:"float",zFar:"float"},outTypes:{depth:"float"},inputs:{z:t,zNear:e,zFar:n},statements:({inputs:t,outputs:e})=>[`float clamped = clamp(${t.z}, ${t.zNear}, ${t.zFar});`,`${e.depth} = (log2(clamped + 1.0) - log2(${t.zNear} + 1.0)) / (log2(${t.zFar} + 1.0) - log2(${t.zNear} + 1.0));`]})}dynoOut(){return new F(this,"depth")}}class Ri extends B{constructor({index:t}){super({inTypes:{index:"int"},outTypes:{color:"vec3"},inputs:{index:t},statements:({inputs:t,outputs:e})=>[`${e.color} = debugColorHue(uint(${t.index}));`]})}dynoOut(){return new F(this,"color")}}const qi=(t,{scale:e,scales:n,rotate:a,translate:s})=>new Vi({position:t,scale:e,scales:n,rotate:a,translate:s}).outputs.position,Ui=(t,{scale:e,scales:n,rotate:a})=>new Bi({dir:t,scale:e,scales:n,rotate:a}).outputs.dir;class Vi extends B{constructor({position:t,scale:e,scales:n,rotate:a,translate:s}){super({inTypes:{position:"vec3",scale:"float",scales:"vec3",rotate:"vec4",translate:"vec3"},outTypes:{position:"vec3"},inputs:{position:t,scale:e,scales:n,rotate:a,translate:s},statements:({inputs:t,outputs:e})=>{const{position:n}=e;if(!n)return[];const{scale:a,scales:s,rotate:r,translate:i}=t;return[`${n} = ${t.position??"vec3(0.0, 0.0, 0.0)"};`,a?`${n} *= ${a};`:null,s?`${n} *= ${s};`:null,r?`${n} = quatVec(${r}, ${n});`:null,i?`${n} += ${i};`:null].filter(Boolean)}})}}class Bi extends B{constructor({dir:t,scale:e,scales:n,rotate:a}){super({inTypes:{dir:"vec3",scale:"float",scales:"vec3",rotate:"vec4"},outTypes:{dir:"vec3"},inputs:{dir:t,scale:e,scales:n,rotate:a},statements:({inputs:t,outputs:e})=>{const{dir:n}=e;if(!n)return[];const{scale:a,scales:s,rotate:r}=t;return[`${n} = ${t.dir??"vec3(0.0, 0.0, 0.0)"};`,a?`${n} *= ${a};`:null,s?`${n} *= ${s};`:null,r?`${n} = quatVec(${r}, ${n});`:null].filter(Boolean)}})}}class Ni extends B{constructor({quaternion:t,rotate:e}){super({inTypes:{quaternion:"vec4",rotate:"vec4"},outTypes:{quaternion:"vec4"},inputs:{quaternion:t,rotate:e},statements:({inputs:t,outputs:n})=>{const{quaternion:a}=n;return a?[`${a} = ${t.quaternion??"vec4(0.0, 0.0, 0.0, 1.0)"};`,e?`${a} = quatQuat(${t.rotate}, ${a});`:null].filter(Boolean):[]}})}}class Oi extends B{constructor({texture:t,lod:e}){const n=E(t);super({inTypes:{texture:n,lod:"int"},outTypes:{size:Wi(n)},inputs:{texture:t,lod:e},statements:({inputs:t,outputs:e})=>[`${e.size} = textureSize(${t.texture}, ${t.lod??"0"});`]})}dynoOut(){return new F(this,"size")}}class Gi extends B{constructor({texture:t,coord:e,bias:n}){const a=E(t);super({inTypes:{texture:a,coord:ji(a),bias:"float"},outTypes:{sample:Qi(a)},inputs:{texture:t,coord:e,bias:n},statements:({inputs:t,outputs:e})=>[`${e.sample} = texture(${t.texture}, ${t.coord}${t.bias?`, ${t.bias}`:""});`]})}dynoOut(){return new F(this,"sample")}}class Hi extends B{constructor({texture:t,coord:e,lod:n}){const a=E(t);super({inTypes:{texture:a,coord:Wi(a),lod:"int"},outTypes:{texel:Qi(a)},inputs:{texture:t,coord:e,lod:n},statements:({inputs:t,outputs:e})=>[`${e.texel} = texelFetch(${t.texture}, ${t.coord}, ${t.lod??"0"});`]})}dynoOut(){return new F(this,"texel")}}function Wi(t){switch(t){case"sampler2D":case"usampler2D":case"isampler2D":case"samplerCube":case"usamplerCube":case"isamplerCube":case"sampler2DShadow":case"samplerCubeShadow":return"ivec2";case"sampler3D":case"usampler3D":case"isampler3D":case"sampler2DArray":case"usampler2DArray":case"isampler2DArray":case"sampler2DArrayShadow":return"ivec3";default:throw new Error(`Invalid texture type: ${t}`)}}function ji(t){switch(t){case"sampler2D":case"usampler2D":case"isampler2D":return"vec2";case"sampler3D":case"usampler3D":case"isampler3D":case"samplerCube":case"usamplerCube":case"isamplerCube":case"sampler2DArray":case"usampler2DArray":case"isampler2DArray":case"sampler2DShadow":return"vec3";case"samplerCubeShadow":case"sampler2DArrayShadow":return"vec4";default:throw new Error(`Invalid texture type: ${t}`)}}function Qi(t){switch(t){case"sampler2D":case"sampler2DArray":case"sampler3D":case"samplerCube":case"sampler2DShadow":return"vec4";case"usampler2D":case"usampler2DArray":case"usampler3D":case"usamplerCube":return"uvec4";case"isampler2D":case"isampler2DArray":case"isampler3D":case"isamplerCube":return"ivec4";case"samplerCubeShadow":case"sampler2DArrayShadow":return"float";default:throw new Error(`Invalid texture type: ${t}`)}}const Ki=t=>new Ji({radians:t});class Xi extends Q{constructor({degrees:t}){super({a:t,outTypeFunc:t=>t,outKey:"radians"}),this.statements=({inputs:t,outputs:e})=>[`${e.radians} = radians(${t.a});`]}}class Yi extends Q{constructor({radians:t}){super({a:t,outTypeFunc:t=>t,outKey:"degrees"}),this.statements=({inputs:t,outputs:e})=>[`${e.degrees} = degrees(${t.a});`]}}class Ji extends Q{constructor({radians:t}){super({a:t,outTypeFunc:t=>t,outKey:"sin"}),this.statements=({inputs:t,outputs:e})=>[`${e.sin} = sin(${t.a});`]}}class Zi extends Q{constructor({radians:t}){super({a:t,outTypeFunc:t=>t,outKey:"cos"}),this.statements=({inputs:t,outputs:e})=>[`${e.cos} = cos(${t.a});`]}}class to extends Q{constructor({radians:t}){super({a:t,outTypeFunc:t=>t,outKey:"tan"}),this.statements=({inputs:t,outputs:e})=>[`${e.tan} = tan(${t.a});`]}}class eo extends Q{constructor({sin:t}){super({a:t,outTypeFunc:t=>t,outKey:"asin"}),this.statements=({inputs:t,outputs:e})=>[`${e.asin} = asin(${t.a});`]}}class no extends Q{constructor({cos:t}){super({a:t,outTypeFunc:t=>t,outKey:"acos"}),this.statements=({inputs:t,outputs:e})=>[`${e.acos} = acos(${t.a});`]}}class ao extends Q{constructor({tan:t}){super({a:t,outTypeFunc:t=>t,outKey:"atan"}),this.statements=({inputs:t,outputs:e})=>[`${e.atan} = atan(${t.a});`]}}class so extends K{constructor({y:t,x:e}){super({a:t,b:e,outTypeFunc:(t,e)=>t,outKey:"atan2"}),this.statements=({inputs:t,outputs:e})=>[`${e.atan2} = atan2(${t.a}, ${t.b});`]}}class ro extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"sinh"}),this.statements=({inputs:t,outputs:e})=>[`${e.sinh} = sinh(${t.a});`]}}class io extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"cosh"}),this.statements=({inputs:t,outputs:e})=>[`${e.cosh} = cosh(${t.a});`]}}class oo extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"tanh"}),this.statements=({inputs:t,outputs:e})=>[`${e.tanh} = tanh(${t.a});`]}}class lo extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"asinh"}),this.statements=({inputs:t,outputs:e})=>[`${e.asinh} = asinh(${t.a});`]}}class uo extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"acosh"}),this.statements=({inputs:t,outputs:e})=>[`${e.acosh} = acosh(${t.a});`]}}class co extends Q{constructor({x:t}){super({a:t,outTypeFunc:t=>t,outKey:"atanh"}),this.statements=({inputs:t,outputs:e})=>[`${e.atanh} = atanh(${t.a});`]}}const po=Object.freeze(Object.defineProperty({__proto__:null,Abs:bs,Acos:no,Acosh:uo,Add:hs,All:ar,And:Ws,Any:nr,Asin:eo,Asinh:lo,Atan:ao,Atan2:so,Atanh:co,BVec2:br,BVec3:Sr,BVec4:Tr,BinaryOp:K,Bool:yr,Ceil:_s,Clamp:qs,Combine:fi,CombineCovSplat:qt,CombineGsplat:Dt,CompMult:oi,CompXor:lr,Compilation:V,Cos:Zi,Cosh:io,CovSplat:J,Cross:ti,DebugColorHue:Ri,Degrees:Yi,Determinant:di,Distance:Jr,Div:ms,Dot:Zr,Dyno:B,DynoBlock:N,DynoBool:ae,DynoBvec2:oe,DynoBvec3:pe,DynoBvec4:fe,DynoConst:L,DynoFloat:ie,DynoInt:re,DynoIsampler2D:Ae,DynoIsampler2DArray:Ce,DynoIsampler3D:qe,DynoIsamplerCube:Be,DynoIvec2:ue,DynoIvec3:he,DynoIvec4:ye,DynoLiteral:P,DynoMat2:ve,DynoMat2x2:we,DynoMat2x3:be,DynoMat2x4:Se,DynoMat3:Te,DynoMat3x2:_e,DynoMat3x3:Me,DynoMat3x4:ke,DynoMat4:$e,DynoMat4x2:De,DynoMat4x3:ze,DynoMat4x4:Ie,DynoOutput:F,DynoProgram:_a,DynoProgramTemplate:Ma,DynoRemapIndex:_i,DynoSampler2D:Fe,DynoSampler2DArray:Le,DynoSampler2DArrayShadow:Ge,DynoSampler2DShadow:Oe,DynoSampler3D:Ue,DynoSamplerCube:Ne,DynoSamplerCubeShadow:He,DynoUint:se,DynoUniform:ne,DynoUsampler2D:Ee,DynoUsampler2DArray:Pe,DynoUsampler3D:Re,DynoUsamplerCube:Ve,DynoUvec2:le,DynoUvec3:de,DynoUvec4:me,DynoValue:A,DynoVec2:ce,DynoVec3:xe,DynoVec4:ge,Equal:tr,Exp:zs,Exp2:Is,ExtendVec:ai,FaceForward:si,Float:wr,FloatBitsToInt:Lr,FloatBitsToUint:Rr,Floor:Ts,Fract:$s,GreaterThan:Js,GreaterThanEqual:Zs,Gsplat:Y,GsplatNormal:It,GsplatToCovSplat:kt,GsplatXAxis:Et,GsplatYAxis:At,GsplatZAxis:Ft,Hash:Di,Hash2:zi,Hash3:Ii,Hash4:Ei,HashFloat:Ai,HashVec2:Fi,HashVec3:Pi,HashVec4:Ci,IMod:ys,IVec2:_r,IVec3:Mr,IVec4:kr,Int:gr,IntBitsToFloat:qr,Inverse:hi,InverseSqrt:Cs,IsInf:Os,IsNan:Ns,Length:Yr,LessThan:Xs,LessThanEqual:Ys,Log:Es,Log2:As,Mat2:Fr,Mat3:Pr,Mat4:Cr,Max:Rs,Min:Ls,Mix:Us,Mod:gs,Modf:vs,Mul:fs,Neg:ws,Normalize:ei,NormalizedDepth:Li,Not:Ks,NotEqual:er,NumCovSplats:Tt,NumExtSplats:wt,NumPackedSplats:ft,Or:js,Outer:ui,OutputCovSplat:Qt,OutputExtCovSplat:Xt,OutputExtendedSplat:Kt,OutputPackedSplat:jt,OutputRgba8:Zt,PackHalf2x16:Gr,PackSnorm2x16:Vr,PackUnorm2x16:Nr,PagedSplatTexCoord:Vt,PcgHash:ki,PcgMix:$i,PcgNext:Mi,Pow:Ds,ProjectH:ni,Radians:Xi,ReadCovSplat:Mt,ReadExtSplat:St,ReadPackedSplat:yt,ReadPackedSplatRange:gt,ReflectVec:ri,RefractVec:ii,Round:ks,Select:sr,Shl:cr,Shr:ur,Sign:Ss,SimpleCast:mr,Sin:Ji,Sinh:ro,Smoothstep:Bs,SplatTexCoord:Ut,Split:xi,SplitCovSplat:Rt,SplitGsplat:$t,Sqr:Fs,Sqrt:Ps,Step:Vs,Sub:xs,Swizzle:mi,TCovSplats:et,TExtSplats:tt,TPackedSplats:Z,Tan:to,Tanh:oo,TexelFetch:Hi,Texture:Gi,TextureSize:Oi,TransformDir:Bi,TransformGsplat:Pt,TransformPosition:Vi,TransformQuaternion:Ni,Transpose:pi,TrinaryOp:X,Trunc:Ms,UVec2:$r,UVec3:Dr,UVec4:zr,Uint:vr,UintBitsToFloat:Ur,UintToRgba8:Wr,UnaryOp:Q,UnpackHalf2x16:Hr,UnpackSnorm2x16:Br,UnpackUnorm2x16:Or,Vec2:Ir,Vec3:Er,Vec4:Ar,Xor:Qs,abs:t=>new bs({a:t}),acos:t=>new no({cos:t}),acosh:t=>new uo({x:t}),add:as,all:t=>new ar({a:t}),and:(t,e)=>new Ws({a:t,b:e}),any:t=>new nr({a:t}),arrayIndex:()=>{throw new Error("Not implemented")},arrayLength:()=>{throw new Error("Not implemented")},asin:t=>new eo({sin:t}),asinh:t=>new lo({x:t}),atan:t=>new ao({tan:t}),atan2:(t,e)=>new so({y:t,x:e}),atanh:t=>new co({x:t}),bool:t=>new yr({value:t}),bvec2:t=>new br({value:t}),bvec3:t=>new Sr({value:t}),bvec4:t=>new Tr({value:t}),ceil:t=>new _s({a:t}),clamp:(t,e,n)=>new qs({a:t,min:e,max:n}),combine:Xr,combineCovSplat:Lt,combineGsplat:ot,comment:()=>{throw new Error("Not implemented")},compMult:(t,e)=>new oi({a:t,b:e}),compXor:t=>new lr({a:t}),cos:t=>new Zi({radians:t}),cosh:t=>new io({x:t}),cross:(t,e)=>new ti({a:t,b:e}),debugColorHue:t=>new Ri({index:t}),defineCovSplat:ht,defineExtSplats:vt,defineGsplat:dt,defineGsplatNormal:zt,definePackedSplats:xt,degrees:t=>new Yi({radians:t}),determinant:t=>new di({a:t}),distance:(t,e)=>new Jr({a:t,b:e}),div:is,dot:jr,dyno:G,dynoBlock:O,dynoBool:(t=!1,e)=>new ae({key:e,value:t}),dynoBvec2:(t,e)=>new oe({key:e,value:t}),dynoBvec3:(t,e)=>new pe({key:e,value:t}),dynoBvec4:(t,e)=>new fe({key:e,value:t}),dynoConst:R,dynoDeclare:H,dynoFloat:te,dynoFor:()=>{throw new Error("Not implemented")},dynoIf:()=>{throw new Error("Not implemented")},dynoInt:(t=0,e)=>new re({key:e,value:t}),dynoIsampler2D:(t,e)=>new Ae({key:e,value:t}),dynoIsampler2DArray:(t,e)=>new Ce({key:t,value:e}),dynoIsampler3D:(t,e)=>new qe({key:e,value:t}),dynoIsamplerCube:(t,e)=>new Be({key:e,value:t}),dynoIvec2:(t,e)=>new ue({key:e,value:t}),dynoIvec3:(t,e)=>new he({key:e,value:t}),dynoIvec4:(t,e)=>new ye({key:e,value:t}),dynoLiteral:C,dynoMat2:(t,e)=>new ve({key:e,value:t}),dynoMat2x2:(t,e)=>new we({key:e,value:t}),dynoMat2x3:(t,e)=>new be({key:e,value:t}),dynoMat2x4:(t,e)=>new Se({key:e,value:t}),dynoMat3:(t,e)=>new Te({key:e,value:t}),dynoMat3x2:(t,e)=>new _e({key:e,value:t}),dynoMat3x3:(t,e)=>new Me({key:e,value:t}),dynoMat3x4:(t,e)=>new ke({key:e,value:t}),dynoMat4:(t,e)=>new $e({key:e,value:t}),dynoMat4x2:(t,e)=>new De({key:e,value:t}),dynoMat4x3:(t,e)=>new ze({key:e,value:t}),dynoMat4x4:(t,e)=>new Ie({key:e,value:t}),dynoSampler2D:(t,e)=>new Fe({key:e,value:t}),dynoSampler2DArray:(t,e)=>new Le({key:e,value:t}),dynoSampler2DArrayShadow:(t,e)=>new Ge({key:e,value:t}),dynoSampler2DShadow:(t,e)=>new Oe({key:e,value:t}),dynoSampler3D:(t,e)=>new Ue({key:e,value:t}),dynoSamplerCube:(t,e)=>new Ne({key:e,value:t}),dynoSamplerCubeShadow:(t,e)=>new He({key:e,value:t}),dynoSwitch:()=>{throw new Error("Not implemented")},dynoUint:(t=0,e)=>new se({key:e,value:t}),dynoUsampler2D:(t,e)=>new Ee({key:e,value:t}),dynoUsampler2DArray:(t,e)=>new Pe({key:e,value:t}),dynoUsampler3D:(t,e)=>new Re({key:e,value:t}),dynoUsamplerCube:(t,e)=>new Ve({key:e,value:t}),dynoUvec2:(t,e)=>new le({key:e,value:t}),dynoUvec3:(t,e)=>new de({key:e,value:t}),dynoUvec4:(t,e)=>new me({key:e,value:t}),dynoVec2:(t,e)=>new ce({key:e,value:t}),dynoVec3:ee,dynoVec4:(t,e)=>new ge({key:e,value:t}),equal:(t,e)=>new tr({a:t,b:e}),exp:t=>new zs({a:t}),exp2:t=>new Is({a:t}),extendVec:(t,e)=>new ai({a:t,b:e}),faceforward:(t,e,n)=>new si({a:t,b:e,c:n}),float:pr,floatBitsToInt:fr,floatBitsToUint:t=>new Rr({value:t}),floor:t=>new Ts({a:t}),fract:cs,greaterThan:(t,e)=>new Js({a:t,b:e}),greaterThanEqual:Gs,gsplatNormal:lt,gsplatToCovSplat:rt,gsplatXAxis:t=>new Et({gsplat:t}),gsplatYAxis:t=>new At({gsplat:t}),gsplatZAxis:t=>new Ft({gsplat:t}),hash:yi,hash2:gi,hash3:vi,hash4:wi,hashFloat:t=>new Ai({value:t}),hashVec2:t=>new Fi({value:t}),hashVec3:bi,hashVec4:Si,imod:os,int:t=>new gr({value:t}),intBitsToFloat:t=>new qr({value:t}),inverse:t=>new hi({a:t}),inversesqrt:t=>new Cs({a:t}),isAllFloatType:y,isBoolType:p,isFloatType:f,isInf:t=>new Os({a:t}),isIntType:h,isMat2:b,isMat3:S,isMat4:T,isMatFloatType:m,isNan:t=>new Ns({a:t}),isScalarType:d,isUintType:x,isVector2Type:g,isVector3Type:v,isVector4Type:w,isVectorType:function(t){return g(t)||v(t)||w(t)},ivec2:t=>new _r({value:t}),ivec3:t=>new Mr({value:t}),ivec4:t=>new kr({value:t}),length:t=>new Yr({a:t}),lessThan:(t,e)=>new Xs({a:t,b:e}),lessThanEqual:(t,e)=>new Ys({a:t,b:e}),literalNegOne:function(t){const e=String(t);if(p(t))return`${e}(true)`;if(y(t))return`${e}(-1.0)`;if(h(t))return`${e}(-1)`;if(x(t))return`${e}(0xFFFFFFFFu)`;throw new Error(`Type not implemented: ${e}`)},literalOne:function(t){const e=String(t);if(p(t))return`${e}(true)`;if(y(t))return`${e}(1.0)`;if(h(t))return`${e}(1)`;if(x(t))return`${e}(1u)`;throw new Error(`Type not implemented: ${e}`)},literalZero:q,log:t=>new Es({a:t}),log2:t=>new As({a:t}),mat2:t=>new Fr({value:t}),mat3:t=>new Pr({value:t}),mat4:t=>new Cr({value:t}),max:ps,min:(t,e)=>new Ls({a:t,b:e}),mix:ds,mod:ls,modf:t=>new vs({a:t}).outputs,mul:rs,neg:us,normalize:Qr,normalizedDepth:Ti,not:t=>new Ks({a:t}),notEqual:(t,e)=>new er({a:t,b:e}),numCovSplats:t=>new Tt({covsplats:t}),numExtSplats:t=>new wt({extSplats:t}),numPackedSplats:t=>new ft({packedSplats:t}),numberAsFloat:I,numberAsInt:D,numberAsUint:z,or:(t,e)=>new js({a:t,b:e}),outer:(t,e)=>new ui({a:t,b:e}),outputCovSplat:Nt,outputCovSplatDepth:Wt,outputExtCovSplat:Gt,outputExtendedSplat:Ot,outputPackedSplat:Bt,outputRgba8:t=>new Zt({rgba8:t}),outputSplatDepth:Ht,packHalf2x16:t=>new Gr({value:t}),packSnorm2x16:t=>new Vr({value:t}),packUnorm2x16:t=>new Nr({value:t}),pagedSplatTexCoord:pt,pcgHash:t=>new ki({state:t}),pcgMix:t=>new $i({value:t}),pcgNext:t=>new Mi({state:t}),pow:(t,e)=>new Ds({a:t,b:e}),projectH:t=>new ni({a:t}),radians:t=>new Xi({degrees:t}),readCovSplat:(t,e)=>new Mt({covSplats:t,index:e}),readExtSplat:st,readPackedSplat:nt,readPackedSplatRange:at,reflectVec:(t,e)=>new ri({incident:t,normal:e}),refractVec:(t,e,n)=>new ii({incident:t,normal:e,eta:n}),remapIndex:(t,e,n)=>new _i({index:t,from:e,to:n}),round:t=>new ks({a:t}),sameSizeIvec:function(t){if(d(t))return"int";if(g(t))return"ivec2";if(v(t))return"ivec3";if(w(t))return"ivec4";throw new Error(`Invalid vector type: ${t}`)},sameSizeUvec:k,sameSizeVec:function(t){if(d(t))return"float";if(g(t))return"vec2";if(v(t))return"vec3";if(w(t))return"vec4";throw new Error(`Invalid vector type: ${t}`)},select:Hs,shl:(t,e)=>new cr({a:t,b:e}),shr:(t,e)=>new ur({a:t,b:e}),sign:t=>new Ss({a:t}),sin:Ki,sinh:t=>new ro({x:t}),smoothstep:(t,e,n)=>new Bs({edge0:t,edge1:e,x:n}),splatTexCoord:ct,split:Kr,splitCovSplat:Ct,splitGsplat:it,sqr:t=>new Fs({a:t}),sqrt:t=>new Ps({a:t}),step:(t,e)=>new Vs({edge:t,x:e}),sub:ss,swizzle:(t,e)=>new mi({vector:t,select:e}),tan:t=>new to({radians:t}),tanh:t=>new oo({x:t}),texelFetch:(t,e,n)=>new Hi({texture:t,coord:e,lod:n}),texture:(t,e,n)=>new Gi({texture:t,coord:e,bias:n}),textureSize:(t,e)=>new Oi({texture:t,lod:e}),transformDir:Ui,transformGsplat:ut,transformPos:qi,transformQuat:(t,{rotate:e})=>new Ni({quaternion:t,rotate:e}).outputs.quaternion,transpose:t=>new pi({a:t}),trunc:t=>new Ms({a:t}),typeLiteral:$,uint:t=>new vr({value:t}),uintBitsToFloat:t=>new Ur({value:t}),uintToRgba8:t=>new Wr({value:t}),uniform:(t,e,n)=>new ne({key:t,type:e,value:n}),unindent:j,unindentLines:W,unpackHalf2x16:t=>new Hr({value:t}),unpackSnorm2x16:t=>new Br({value:t}),unpackUnorm2x16:t=>new Or({value:t}),uvec2:t=>new $r({value:t}),uvec3:t=>new Dr({value:t}),uvec4:t=>new zr({value:t}),valType:E,vec2:dr,vec3:hr,vec4:xr,vectorDim:M,vectorElementType:_,xor:(t,e)=>new Qs({a:t,b:e})},Symbol.toStringTag,{value:"Module"}));let ho=null;function xo(){return ho||(t.ShaderChunk.splatDefines="const float LN_SCALE_MIN = -12.0;\nconst float LN_SCALE_MAX = 9.0;\n\nconst uint SPLAT_TEX_WIDTH_BITS = 11u;\nconst uint SPLAT_TEX_HEIGHT_BITS = 11u;\nconst uint SPLAT_TEX_DEPTH_BITS = 11u;\nconst uint SPLAT_TEX_LAYER_BITS = SPLAT_TEX_WIDTH_BITS + SPLAT_TEX_HEIGHT_BITS;\n\nconst uint SPLAT_TEX_WIDTH = 1u << SPLAT_TEX_WIDTH_BITS;\nconst uint SPLAT_TEX_HEIGHT = 1u << SPLAT_TEX_HEIGHT_BITS;\nconst uint SPLAT_TEX_DEPTH = 1u << SPLAT_TEX_DEPTH_BITS;\n\nconst uint SPLAT_TEX_WIDTH_MASK = SPLAT_TEX_WIDTH - 1u;\nconst uint SPLAT_TEX_HEIGHT_MASK = SPLAT_TEX_HEIGHT - 1u;\nconst uint SPLAT_TEX_DEPTH_MASK = SPLAT_TEX_DEPTH - 1u;\n\nconst uint F16_INF = 0x7c00u;\nconst float PI = 3.1415926535897932384626433832795;\n\nconst float INFINITY = 1.0 / 0.0;\nconst float NEG_INFINITY = -INFINITY;\n\nfloat sqr(float x) {\n return x * x;\n}\n\nfloat pow4(float x) {\n float x2 = x * x;\n return x2 * x2;\n}\n\nfloat pow8(float x) {\n float x4 = pow4(x);\n return x4 * x4;\n}\n\nvec3 srgbToLinear(vec3 rgb) {\n return pow(rgb, vec3(2.2));\n}\n\nvec3 linearToSrgb(vec3 rgb) {\n return pow(rgb, vec3(1.0 / 2.2));\n}\n\nuint encodeQuatOctXy88R8(vec4 q) {\n \n if (q.w < 0.0) {\n q = -q;\n }\n \n float theta = 2.0 * acos(q.w);\n float halfTheta = theta * 0.5;\n float s = sin(halfTheta);\n \n vec3 axis = (abs(s) < 1e-6) ? vec3(1.0, 0.0, 0.0) : q.xyz / s;\n \n \n \n float sum = abs(axis.x) + abs(axis.y) + abs(axis.z);\n vec2 p = vec2(axis.x, axis.y) / sum;\n \n if (axis.z < 0.0) {\n float oldPx = p.x;\n p.x = (1.0 - abs(p.y)) * (p.x >= 0.0 ? 1.0 : -1.0);\n p.y = (1.0 - abs(oldPx)) * (p.y >= 0.0 ? 1.0 : -1.0);\n }\n \n float u_f = p.x * 0.5 + 0.5;\n float v_f = p.y * 0.5 + 0.5;\n \n uint quantU = uint(clamp(round(u_f * 255.0), 0.0, 255.0));\n uint quantV = uint(clamp(round(v_f * 255.0), 0.0, 255.0));\n \n \n \n uint angleInt = uint(clamp(round((theta / 3.14159265359) * 255.0), 0.0, 255.0));\n \n \n return (angleInt << 16u) | (quantV << 8u) | quantU;\n}\n\nvec4 decodeQuatOctXy88R8(uint encoded) {\n \n uint quantU = encoded & uint(0xFFu); \n uint quantV = (encoded >> 8u) & uint(0xFFu); \n uint angleInt = encoded >> 16u; \n\n \n float u_f = float(quantU) / 255.0;\n float v_f = float(quantV) / 255.0;\n vec2 f = vec2(u_f * 2.0 - 1.0, v_f * 2.0 - 1.0);\n\n vec3 axis = vec3(f.xy, 1.0 - abs(f.x) - abs(f.y));\n float t = max(-axis.z, 0.0);\n axis.x += (axis.x >= 0.0) ? -t : t;\n axis.y += (axis.y >= 0.0) ? -t : t;\n axis = normalize(axis);\n \n \n float theta = (float(angleInt) / 255.0) * 3.14159265359;\n float halfTheta = theta * 0.5;\n float s = sin(halfTheta);\n float w = cos(halfTheta);\n \n return vec4(axis * s, w);\n}\n\nuint encodeQuatOctXy1010R12(vec4 q) {\n \n if (q.w < 0.0) {\n q = -q;\n }\n \n float halfTheta = acos(q.w);\n float theta = 2.0 * halfTheta;\n float s = sin(halfTheta);\n \n vec3 axis = (abs(s) < 1e-6) ? vec3(1.0, 0.0, 0.0) : q.xyz / s;\n \n \n \n float sum = abs(axis.x) + abs(axis.y) + abs(axis.z);\n vec2 p = vec2(axis.x, axis.y) / sum;\n \n if (axis.z < 0.0) {\n float oldPx = p.x;\n p.x = (1.0 - abs(p.y)) * (p.x >= 0.0 ? 1.0 : -1.0);\n p.y = (1.0 - abs(oldPx)) * (p.y >= 0.0 ? 1.0 : -1.0);\n }\n \n float u_f = p.x * 0.5 + 0.5;\n float v_f = p.y * 0.5 + 0.5;\n \n uint quantU = uint(clamp(round(u_f * 1023.0), 0.0, 1023.0));\n uint quantV = uint(clamp(round(v_f * 1023.0), 0.0, 1023.0));\n \n \n \n uint angleInt = uint(clamp(round((theta / PI) * 4095.0), 0.0, 4095.0));\n \n \n return (angleInt << 20u) | (quantV << 10u) | quantU;\n}\n\nvec4 decodeQuatOctXy1010R12(uint encoded) {\n \n uint quantU = encoded & uint(0x3FFu); \n uint quantV = (encoded >> 10u) & uint(0x3FFu); \n uint angleInt = encoded >> 20u; \n\n \n float u_f = float(quantU) / 1023.0;\n float v_f = float(quantV) / 1023.0;\n vec2 f = vec2(u_f * 2.0 - 1.0, v_f * 2.0 - 1.0);\n\n vec3 axis = vec3(f.xy, 1.0 - abs(f.x) - abs(f.y));\n float t = max(-axis.z, 0.0);\n axis.x += (axis.x >= 0.0) ? -t : t;\n axis.y += (axis.y >= 0.0) ? -t : t;\n axis = normalize(axis);\n \n \n float theta = (float(angleInt) / 4095.0) * PI;\n float halfTheta = theta * 0.5;\n float s = sin(halfTheta);\n float w = cos(halfTheta);\n \n return vec4(axis * s, w);\n}\n\nuvec4 packSplatEncoding(\n vec3 center, vec3 scales, vec4 quaternion, vec4 rgba, vec4 rgbMinMaxLnScaleMinMax\n) {\n float rgbMin = rgbMinMaxLnScaleMinMax.x;\n float rgbMax = rgbMinMaxLnScaleMinMax.y;\n vec3 encRgb = (rgba.rgb - vec3(rgbMin)) / (rgbMax - rgbMin);\n uvec4 uRgba = uvec4(round(clamp(vec4(encRgb, rgba.a) * 255.0, 0.0, 255.0)));\n\n uint uQuat = encodeQuatOctXy88R8(quaternion);\n \n \n uvec3 uQuat3 = uvec3(uQuat & 0xffu, (uQuat >> 8u) & 0xffu, (uQuat >> 16u) & 0xffu);\n\n \n float lnScaleMin = rgbMinMaxLnScaleMinMax.z;\n float lnScaleMax = rgbMinMaxLnScaleMinMax.w;\n float lnScaleScale = 254.0 / (lnScaleMax - lnScaleMin);\n uvec3 uScales = uvec3(\n (scales.x == 0.0) ? 0u : uint(round(clamp((log(scales.x) - lnScaleMin) * lnScaleScale, 0.0, 254.0))) + 1u,\n (scales.y == 0.0) ? 0u : uint(round(clamp((log(scales.y) - lnScaleMin) * lnScaleScale, 0.0, 254.0))) + 1u,\n (scales.z == 0.0) ? 0u : uint(round(clamp((log(scales.z) - lnScaleMin) * lnScaleScale, 0.0, 254.0))) + 1u\n );\n\n \n uint word0 = uRgba.r | (uRgba.g << 8u) | (uRgba.b << 16u) | (uRgba.a << 24u);\n uint word1 = packHalf2x16(center.xy);\n uint word2 = packHalf2x16(vec2(center.z, 0.0)) | (uQuat3.x << 16u) | (uQuat3.y << 24u);\n uint word3 = uScales.x | (uScales.y << 8u) | (uScales.z << 16u) | (uQuat3.z << 24u);\n return uvec4(word0, word1, word2, word3);\n}\n\nuvec4 packSplat(vec3 center, vec3 scales, vec4 quaternion, vec4 rgba) {\n return packSplatEncoding(center, scales, quaternion, rgba, vec4(0.0, 1.0, LN_SCALE_MIN, LN_SCALE_MAX));\n}\n\nvoid unpackSplatEncoding(uvec4 packedData, out vec3 center, out vec3 scales, out vec4 quaternion, out vec4 rgba, vec4 rgbMinMaxLnScaleMinMax) {\n uint word0 = packedData.x, word1 = packedData.y, word2 = packedData.z, word3 = packedData.w;\n\n uvec4 uRgba = uvec4(word0 & 0xffu, (word0 >> 8u) & 0xffu, (word0 >> 16u) & 0xffu, (word0 >> 24u) & 0xffu);\n float rgbMin = rgbMinMaxLnScaleMinMax.x;\n float rgbMax = rgbMinMaxLnScaleMinMax.y;\n rgba = (vec4(uRgba) / 255.0);\n rgba.rgb = rgba.rgb * (rgbMax - rgbMin) + rgbMin;\n\n center = vec4(\n unpackHalf2x16(word1),\n unpackHalf2x16(word2 & 0xffffu)\n ).xyz;\n\n uvec3 uScales = uvec3(word3 & 0xffu, (word3 >> 8u) & 0xffu, (word3 >> 16u) & 0xffu);\n float lnScaleMin = rgbMinMaxLnScaleMinMax.z;\n float lnScaleMax = rgbMinMaxLnScaleMinMax.w;\n float lnScaleScale = (lnScaleMax - lnScaleMin) / 254.0;\n scales = vec3(\n (uScales.x == 0u) ? 0.0 : exp(lnScaleMin + float(uScales.x - 1u) * lnScaleScale),\n (uScales.y == 0u) ? 0.0 : exp(lnScaleMin + float(uScales.y - 1u) * lnScaleScale),\n (uScales.z == 0u) ? 0.0 : exp(lnScaleMin + float(uScales.z - 1u) * lnScaleScale)\n );\n\n uint uQuat = ((word2 >> 16u) & 0xFFFFu) | ((word3 >> 8u) & 0xFF0000u);\n quaternion = decodeQuatOctXy88R8(uQuat);\n \n \n}\n\nvoid unpackSplat(uvec4 packedData, out vec3 center, out vec3 scales, out vec4 quaternion, out vec4 rgba) {\n unpackSplatEncoding(packedData, center, scales, quaternion, rgba, vec4(0.0, 1.0, LN_SCALE_MIN, LN_SCALE_MAX));\n}\n\nuvec4 packSplatCovEncoding(\n vec3 center, vec4 rgba, vec3 xxyyzz, vec3 xyxzyz, vec4 rgbMinMaxLnScaleMinMax\n) {\n float rgbMin = rgbMinMaxLnScaleMinMax.x;\n float rgbMax = rgbMinMaxLnScaleMinMax.y;\n vec3 encRgb = (rgba.rgb - vec3(rgbMin)) / (rgbMax - rgbMin);\n uvec4 uRgba = uvec4(round(clamp(vec4(encRgb, rgba.a) * 255.0, 0.0, 255.0)));\n\n float lnScaleMin = rgbMinMaxLnScaleMinMax.z;\n float lnScaleMax = rgbMinMaxLnScaleMinMax.w;\n float diagScale = 255.0 / (2.0 * (lnScaleMax - lnScaleMin));\n uvec3 uXxyyzz = uvec3(round(clamp((log(xxyyzz) - 2.0 * lnScaleMin) * diagScale, 0.0, 255.0)));\n\n vec3 xyxzyzCor = vec3(\n clamp(xyxzyz.x / sqrt(xxyyzz.x * xxyyzz.y), -1.0, 1.0),\n clamp(xyxzyz.y / sqrt(xxyyzz.x * xxyyzz.z), -1.0, 1.0),\n clamp(xyxzyz.z / sqrt(xxyyzz.y * xxyyzz.z), -1.0, 1.0)\n );\n ivec3 iXyxzyzCor = ivec3(round(xyxzyzCor * 127.0));\n\n \n uint word0 = uRgba.r | (uRgba.g << 8u) | (uRgba.b << 16u) | (uRgba.a << 24u);\n uint word1 = packHalf2x16(center.xy);\n uint word2 = packHalf2x16(vec2(center.z, 0.0)) |\n ((uint(iXyxzyzCor.y) & 0xffu) << 16u) |\n ((uint(iXyxzyzCor.z) & 0xffu) << 24u);\n uint word3 =\n uXxyyzz.x | (uXxyyzz.y << 8u) | (uXxyyzz.z << 16u) |\n ((uint(iXyxzyzCor.x) & 0xffu) << 24u);\n return uvec4(word0, word1, word2, word3);\n}\n\nvoid unpackSplatCovEncoding(uvec4 packedData, out vec3 center, out vec4 rgba, out vec3 xxyyzz, out vec3 xyxzyz, vec4 rgbMinMaxLnScaleMinMax) {\n uint word0 = packedData.x, word1 = packedData.y, word2 = packedData.z, word3 = packedData.w;\n\n uvec4 uRgba = uvec4(word0 & 0xffu, (word0 >> 8u) & 0xffu, (word0 >> 16u) & 0xffu, (word0 >> 24u) & 0xffu);\n float rgbMin = rgbMinMaxLnScaleMinMax.x;\n float rgbMax = rgbMinMaxLnScaleMinMax.y;\n rgba = (vec4(uRgba) / 255.0);\n rgba.rgb = rgba.rgb * (rgbMax - rgbMin) + rgbMin;\n\n center = vec3(\n unpackHalf2x16(word1),\n unpackHalf2x16(word2 & 0xffffu).x\n );\n\n uvec3 uXxyyzz = uvec3(word3 & 0xffu, (word3 >> 8u) & 0xffu, (word3 >> 16u) & 0xffu);\n ivec3 iXyxzyzCor = ivec3(int(word3) >> 24, int(word2 << 8u) >> 24, int(word2) >> 24);\n\n float lnScaleMin = rgbMinMaxLnScaleMinMax.z;\n float lnScaleMax = rgbMinMaxLnScaleMinMax.w;\n float diagScale = 2.0 * (lnScaleMax - lnScaleMin) / 255.0;\n xxyyzz = exp(2.0 * lnScaleMin + vec3(uXxyyzz) * diagScale);\n\n vec3 xyxzyzCor = vec3(iXyxzyzCor) / 127.0;\n xyxzyz = xyxzyzCor * vec3(\n sqrt(xxyyzz.x * xxyyzz.y),\n sqrt(xxyyzz.x * xxyyzz.z),\n sqrt(xxyyzz.y * xxyyzz.z)\n );\n}\n\nvoid packSplatExtCov(\n out uvec4 packedData, out uvec4 packedData2,\n vec3 center, vec4 rgba, vec3 xxyyzz, vec3 xyxzyz\n) {\n packedData.x = floatBitsToUint(center.x);\n packedData.y = floatBitsToUint(center.y);\n packedData.z = floatBitsToUint(center.z);\n packedData.w = packHalf2x16(vec2(rgba.a, rgba.b));\n packedData2.x = packHalf2x16(rgba.rg);\n\n vec3 xyxzyzCor = vec3(\n clamp(xyxzyz.x / sqrt(xxyyzz.x * xxyyzz.y), -1.0, 1.0),\n clamp(xyxzyz.y / sqrt(xxyyzz.x * xxyyzz.z), -1.0, 1.0),\n clamp(xyxzyz.z / sqrt(xxyyzz.y * xxyyzz.z), -1.0, 1.0)\n );\n xyxzyzCor = sign(xyxzyzCor) * clamp(log(abs(xyxzyzCor)), -100.0, -0.0000001);\n xxyyzz = log(xxyyzz);\n\n packedData2.y = packHalf2x16(vec2(xxyyzz.x, xxyyzz.y));\n packedData2.z = packHalf2x16(vec2(xxyyzz.z, xyxzyzCor.x));\n packedData2.w = packHalf2x16(vec2(xyxzyzCor.y, xyxzyzCor.z));\n}\n\nvoid unpackSplatExtCov(\n uvec4 packedData, uvec4 packedData2,\n out vec3 center, out vec4 rgba, out vec3 xxyyzz, out vec3 xyxzyz\n) {\n center.x = uintBitsToFloat(packedData.x);\n center.y = uintBitsToFloat(packedData.y);\n center.z = uintBitsToFloat(packedData.z);\n\n vec2 ab = unpackHalf2x16(packedData.w);\n vec2 rg = unpackHalf2x16(packedData2.x);\n rgba = vec4(rg, ab.y, ab.x);\n\n vec2 xxyy = unpackHalf2x16(packedData2.y);\n vec2 zzxy = unpackHalf2x16(packedData2.z);\n vec2 xzyz = unpackHalf2x16(packedData2.w);\n xxyyzz = exp(vec3(xxyy.x, xxyy.y, zzxy.x));\n xyxzyz = vec3(zzxy.y, xzyz.x, xzyz.y);\n xyxzyz = -sign(xyxzyz) * exp(-abs(xyxzyz));\n xyxzyz *= vec3(\n sqrt(xxyyzz.x * xxyyzz.y),\n sqrt(xxyyzz.x * xxyyzz.z),\n sqrt(xxyyzz.y * xxyyzz.z)\n );\n}\n\nvoid packSplatExt(\n out uvec4 packedData, out uvec4 packedData2,\n vec3 center, vec3 scales, vec4 quaternion, vec4 rgba\n) {\n packedData.x = floatBitsToUint(center.x);\n packedData.y = floatBitsToUint(center.y);\n packedData.z = floatBitsToUint(center.z);\n packedData.w = packHalf2x16(vec2(rgba.a, 0.0));\n\n packedData2.x = packHalf2x16(rgba.rg);\n packedData2.y = packHalf2x16(vec2(rgba.b, log(scales.x)));\n packedData2.z = packHalf2x16(log(scales.yz));\n packedData2.w = encodeQuatOctXy1010R12(quaternion);\n}\n\nvec4 unpackSplatExtCenterAlpha(uvec4 packedData) {\n return vec4(\n uintBitsToFloat(packedData.x),\n uintBitsToFloat(packedData.y),\n uintBitsToFloat(packedData.z),\n unpackHalf2x16(packedData.w).x\n );\n}\n\nfloat unpackSplatExtAlpha(uvec4 packedData) {\n return unpackHalf2x16(packedData.w).x;\n}\n\nvoid unpackSplatExt(\n uvec4 packedData, uvec4 packedData2,\n out vec3 center, out vec3 scales, out vec4 quaternion, out vec4 rgba\n) {\n center.x = uintBitsToFloat(packedData.x);\n center.y = uintBitsToFloat(packedData.y);\n center.z = uintBitsToFloat(packedData.z);\n rgba.a = unpackHalf2x16(packedData.w).x;\n\n rgba.rg = unpackHalf2x16(packedData2.x);\n vec2 split = unpackHalf2x16(packedData2.y);\n rgba.b = split.x;\n scales.x = exp(split.y);\n scales.yz = exp(unpackHalf2x16(packedData2.z));\n quaternion = decodeQuatOctXy1010R12(packedData2.w);\n}\n\nuint encodeExtRgb(vec3 rgb) {\n vec3 absRgb = abs(rgb);\n float maxAbs = max(absRgb.r, max(absRgb.g, absRgb.b));\n\n int base = clamp(int(floor(log2(maxAbs))) + 15, 0, 31);\n float divisor = exp2(float(base - 15)) / 255.0;\n\n uvec3 uRgb = uvec3(round(clamp(absRgb / divisor, 0.0, 255.0)));\n uint expSigns = (uint(base) << 3u) | ((rgb.r < 0.0 ? 0x1u : 0u) | (rgb.g < 0.0 ? 0x2u : 0u) | (rgb.b < 0.0 ? 0x4u : 0u));\n return uRgb.r | (uRgb.g << 8u) | (uRgb.b << 16u) | (expSigns << 24u);\n}\n\nvec3 decodeExtRgb(uint encoded) {\n uint biasedBase = (encoded >> 27u) & 0x1fu;\n float divisor = exp2(float(int(biasedBase) - 15)) / 255.0;\n\n vec3 rgb = vec3(uvec3(encoded & 0xffu, (encoded >> 8u) & 0xffu, (encoded >> 16u) & 0xffu));\n rgb *= divisor;\n\n return vec3(\n ((encoded & 0x1000000u) != 0u) ? -rgb.r : rgb.r,\n ((encoded & 0x2000000u) != 0u) ? -rgb.g : rgb.g,\n ((encoded & 0x4000000u) != 0u) ? -rgb.b : rgb.b\n );\n}\n\nvec3 quatVec(vec4 q, vec3 v) {\n \n vec3 t = 2.0 * cross(q.xyz, v);\n return v + q.w * t + cross(q.xyz, t);\n}\n\nvec4 quatQuat(vec4 q1, vec4 q2) {\n return vec4(\n q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y,\n q1.w * q2.y - q1.x * q2.z + q1.y * q2.w + q1.z * q2.x,\n q1.w * q2.z + q1.x * q2.y - q1.y * q2.x + q1.z * q2.w,\n q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z\n );\n}\n\nmat3 quaternionToMatrix(vec4 q) {\n return mat3(\n (1.0 - 2.0 * (q.y * q.y + q.z * q.z)),\n (2.0 * (q.x * q.y + q.w * q.z)),\n (2.0 * (q.x * q.z - q.w * q.y)),\n (2.0 * (q.x * q.y - q.w * q.z)),\n (1.0 - 2.0 * (q.x * q.x + q.z * q.z)),\n (2.0 * (q.y * q.z + q.w * q.x)),\n (2.0 * (q.x * q.z + q.w * q.y)),\n (2.0 * (q.y * q.z - q.w * q.x)),\n (1.0 - 2.0 * (q.x * q.x + q.y * q.y))\n );\n}\n\nmat3 scaleQuaternionToMatrix(vec3 s, vec4 q) {\n \n return mat3(\n s.x * (1.0 - 2.0 * (q.y * q.y + q.z * q.z)),\n s.x * (2.0 * (q.x * q.y + q.w * q.z)),\n s.x * (2.0 * (q.x * q.z - q.w * q.y)),\n s.y * (2.0 * (q.x * q.y - q.w * q.z)),\n s.y * (1.0 - 2.0 * (q.x * q.x + q.z * q.z)),\n s.y * (2.0 * (q.y * q.z + q.w * q.x)),\n s.z * (2.0 * (q.x * q.z + q.w * q.y)),\n s.z * (2.0 * (q.y * q.z - q.w * q.x)),\n s.z * (1.0 - 2.0 * (q.x * q.x + q.y * q.y))\n );\n}\n\nvec4 slerp(vec4 q1, vec4 q2, float t) {\n \n float cosHalfTheta = dot(q1, q2);\n\n \n if (abs(cosHalfTheta) >= 0.999) {\n return q1;\n }\n \n \n \n if (cosHalfTheta < 0.0) {\n q2 = -q2;\n cosHalfTheta = -cosHalfTheta;\n }\n\n \n float halfTheta = acos(cosHalfTheta);\n float sinHalfTheta = sqrt(1.0 - cosHalfTheta * cosHalfTheta);\n\n \n float ratioA = sin((1.0 - t) * halfTheta) / sinHalfTheta;\n float ratioB = sin(t * halfTheta) / sinHalfTheta;\n\n \n return q1 * ratioA + q2 * ratioB;\n}\n\nivec3 splatTexCoord(int index) {\n uint x = uint(index) & SPLAT_TEX_WIDTH_MASK;\n uint y = (uint(index) >> SPLAT_TEX_WIDTH_BITS) & SPLAT_TEX_HEIGHT_MASK;\n uint z = uint(index) >> SPLAT_TEX_LAYER_BITS;\n return ivec3(x, y, z);\n}\n\nivec3 pagedSplatTexCoord(int index) {\n return ivec3(index & 255, (index >> 8) & 255, index >> 16);\n}\n\nvec4 uintToVec4(uint u32) {\n uvec4 bytes = uvec4(\n u32 & 0xFFu,\n (u32 >> 8u) & 0xFFu,\n (u32 >> 16u) & 0xFFu,\n (u32 >> 24u) & 0xFFu\n );\n return vec4(bytes) / 255.0;\n}\n\nvec4 floatToVec4(float f) {\n uint u32 = floatBitsToUint(f);\n return uintToVec4(u32);\n}\n\nvec3 debugColorHue(uint i) {\n \n float hue = fract(float(i) * 0.61803398875);\n \n vec3 rgb = clamp(abs(mod(hue*6.0 + vec3(0.0,4.0,2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);\n return mix(vec3(1.0), rgb, 0.85); \n}",ho={splatVertex:"precision highp float;\nprecision highp int;\nprecision highp usampler2DArray;\n\n#include <splatDefines>\n\nout vec4 vRgba;\nout vec2 vSplatUv;\nout vec3 vNdc;\nflat out uint vSplatIndex;\nflat out float adjustedStdDev;\n\nuniform vec2 renderSize;\nuniform vec4 renderToViewQuat;\nuniform vec3 renderToViewPos;\nuniform mat3 renderToViewBasis;\nuniform float maxStdDev;\nuniform float minPixelRadius;\nuniform float maxPixelRadius;\nuniform bool enableExtSplats;\nuniform bool enableCovSplats;\nuniform float time;\nuniform float deltaTime;\nuniform bool debugFlag;\nuniform float minAlpha;\nuniform bool enable2DGS;\nuniform bool lodInflate;\nuniform float blurAmount;\nuniform float preBlurAmount;\nuniform float focalDistance;\nuniform float apertureAngle;\nuniform float clipXY;\nuniform float focalAdjustment;\n\nuniform usampler2D ordering;\nuniform usampler2DArray extSplats;\nuniform usampler2DArray extSplats2;\n\nbool isPerspectiveMatrix( mat4 m ) {\n return m[ 2 ][ 3 ] == -1.0;\n}\n\n#include <logdepthbuf_pars_vertex>\n\nvoid main() {\n \n gl_Position = vec4(0.0, 0.0, 2.0, 1.0);\n\n ivec2 orderingCoord = ivec2((gl_InstanceID >> 2) & 4095, gl_InstanceID >> 14);\n uint splatIndex = texelFetch(ordering, orderingCoord, 0)[gl_InstanceID & 3];\n if (splatIndex == 0xffffffffu) {\n \n return;\n }\n\n ivec3 texCoord = splatTexCoord(int(splatIndex));\n vec3 center, scales, xxyyzz, xyxzyz;\n vec4 quaternion, rgba;\n mat3 cov3D;\n bvec3 zeroScales = bvec3(false);\n\n if (enableExtSplats) {\n uvec4 ext1 = texelFetch(extSplats, texCoord, 0);\n float alpha = unpackSplatExtAlpha(ext1);\n if ((alpha == 0.0) || (alpha < minAlpha)) {\n return;\n }\n uvec4 ext2 = texelFetch(extSplats2, texCoord, 0);\n\n if (!enableCovSplats) {\n unpackSplatExt(ext1, ext2, center, scales, quaternion, rgba);\n zeroScales = equal(scales, vec3(0.0));\n if (all(zeroScales)) {\n return;\n }\n } else {\n unpackSplatExtCov(ext1, ext2, center, rgba, xxyyzz, xyxzyz);\n if (all(equal(xxyyzz, vec3(0.0))) && all(equal(xyxzyz, vec3(0.0)))) {\n return;\n }\n }\n } else {\n uvec4 packedData = texelFetch(extSplats, texCoord, 0);\n if (!enableCovSplats) {\n unpackSplatEncoding(packedData, center, scales, quaternion, rgba, vec4(0.0, 1.0, LN_SCALE_MIN, LN_SCALE_MAX));\n zeroScales = equal(scales, vec3(0.0));\n if (all(zeroScales)) {\n return;\n }\n } else {\n unpackSplatCovEncoding(packedData, center, rgba, xxyyzz, xyxzyz, vec4(0.0, 1.0, LN_SCALE_MIN, LN_SCALE_MAX));\n if (all(equal(xxyyzz, vec3(0.0))) && all(equal(xyxzyz, vec3(0.0)))) {\n return;\n }\n }\n\n rgba.a *= 2.0;\n if ((rgba.a == 0.0) || (rgba.a < minAlpha)) {\n return;\n }\n }\n\n \n \n rgba.rgb = max(rgba.rgb, vec3(0.0));\n\n adjustedStdDev = maxStdDev;\n if (rgba.a > 1.0) {\n \n rgba.a = min(rgba.a * 4.0 - 3.0, 5.0);\n\n if (lodInflate) {\n \n float opacity = exp((rgba.a * rgba.a - 1.0) / 2.718281828459045);\n float rescale = pow(opacity, 1.0 / 3.0);\n scales *= rescale;\n rgba.a = 1.0;\n }\n\n \n adjustedStdDev = maxStdDev + 0.7 * (rgba.a - 1.0);\n }\n\n \n vec3 viewCenter = (!enableCovSplats ? quatVec(renderToViewQuat, center) : (renderToViewBasis * center)) + renderToViewPos;\n\n \n if (viewCenter.z >= 0.0) {\n return;\n }\n\n \n vec4 clipCenter = projectionMatrix * vec4(viewCenter, 1.0);\n\n \n if (abs(clipCenter.z) >= clipCenter.w) {\n return;\n }\n\n \n float clip = clipXY * clipCenter.w;\n if (abs(clipCenter.x) > clip || abs(clipCenter.y) > clip) {\n return;\n }\n\n vRgba = rgba;\n vSplatUv = position.xy * adjustedStdDev;\n\n \n vSplatIndex = splatIndex;\n\n if (!enableCovSplats) {\n \n vec4 viewQuaternion = quatQuat(renderToViewQuat, quaternion);\n\n if (enable2DGS && any(zeroScales)) {\n vec3 offset;\n if (zeroScales.z) {\n offset = vec3(vSplatUv.xy * scales.xy, 0.0);\n } else if (zeroScales.y) {\n offset = vec3(vSplatUv.x * scales.x, 0.0, vSplatUv.y * scales.z);\n } else {\n offset = vec3(0.0, vSplatUv.xy * scales.yz);\n }\n\n vec3 viewPos = viewCenter + quatVec(viewQuaternion, offset);\n gl_Position = projectionMatrix * vec4(viewPos, 1.0);\n vNdc = gl_Position.xyz / gl_Position.w;\n\n #include <logdepthbuf_vertex>\n return;\n }\n\n \n mat3 RS = scaleQuaternionToMatrix(scales, viewQuaternion);\n cov3D = RS * transpose(RS);\n } else {\n cov3D = mat3(\n xxyyzz.x, xyxzyz.x, xyxzyz.y,\n xyxzyz.x, xxyyzz.y, xyxzyz.z,\n xyxzyz.y, xyxzyz.z, xxyyzz.z\n );\n cov3D = renderToViewBasis * cov3D * transpose(renderToViewBasis);\n }\n\n \n vec2 scaledRenderSize = renderSize * focalAdjustment;\n vec2 focal = 0.5 * scaledRenderSize * vec2(projectionMatrix[0][0], projectionMatrix[1][1]);\n\n mat3 J;\n if (isOrthographic) {\n J = mat3(\n focal.x, 0.0, 0.0,\n 0.0, focal.y, 0.0,\n 0.0, 0.0, 0.0\n );\n } else {\n float invZ = 1.0 / viewCenter.z;\n vec2 J1 = focal * invZ;\n vec2 J2 = -(J1 * viewCenter.xy) * invZ;\n J = mat3(\n J1.x, 0.0, J2.x,\n 0.0, J1.y, J2.y,\n 0.0, 0.0, 0.0\n );\n }\n\n \n \n mat3 cov2D = transpose(J) * cov3D * J;\n float a = cov2D[0][0];\n float d = cov2D[1][1];\n float b = cov2D[0][1];\n\n \n a += preBlurAmount;\n d += preBlurAmount;\n\n float fullBlurAmount = blurAmount;\n if ((focalDistance > 0.0) && (apertureAngle > 0.0)) {\n float focusRadius = maxPixelRadius;\n if (viewCenter.z < 0.0) {\n float focusBlur = abs((-viewCenter.z - focalDistance) / viewCenter.z);\n float apertureRadius = focal.x * tan(0.5 * apertureAngle);\n focusRadius = focusBlur * apertureRadius;\n }\n fullBlurAmount = clamp(sqr(focusRadius), blurAmount, sqr(maxPixelRadius));\n }\n\n \n float detOrig = a * d - b * b;\n a += fullBlurAmount;\n d += fullBlurAmount;\n float det = a * d - b * b;\n\n \n float blurAdjust = sqrt(max(0.0, detOrig / det));\n rgba.a *= blurAdjust;\n if (rgba.a < minAlpha) {\n return;\n }\n vRgba.a = rgba.a;\n\n \n float eigenAvg = 0.5 * (a + d);\n float eigenDelta = sqrt(max(0.0, eigenAvg * eigenAvg - det));\n float eigen1 = eigenAvg + eigenDelta;\n float eigen2 = eigenAvg - eigenDelta;\n\n vec2 eigenVec1 = (abs(b) > 0.001) ? normalize(vec2(b, eigen1 - a))\n : ((a >= d) ? vec2(1.0, 0.0) : vec2(0.0, 1.0));\n vec2 eigenVec2 = vec2(eigenVec1.y, -eigenVec1.x);\n\n float scale1 = min(maxPixelRadius, adjustedStdDev * sqrt(eigen1));\n float scale2 = min(maxPixelRadius, adjustedStdDev * sqrt(eigen2));\n if (scale1 < minPixelRadius && scale2 < minPixelRadius) {\n return;\n }\n\n \n vec2 pixelOffset = position.x * eigenVec1 * scale1 + position.y * eigenVec2 * scale2;\n vec2 ndcOffset = (2.0 / scaledRenderSize) * pixelOffset;\n\n \n vec3 ndcCenter = clipCenter.xyz / clipCenter.w;\n vec3 ndc = vec3(ndcCenter.xy + ndcOffset, ndcCenter.z);\n\n vNdc = ndc;\n gl_Position = vec4(ndc.xy * clipCenter.w, clipCenter.zw);\n\n #include <logdepthbuf_vertex>\n}",splatFragment:"precision highp float;\nprecision highp int;\n\n#include <splatDefines>\n\nuniform float near;\nuniform float far;\nuniform bool encodeLinear;\nuniform float time;\nuniform bool debugFlag;\nuniform float maxStdDev;\nuniform float minAlpha;\nuniform bool disableFalloff;\nuniform float falloff;\n\nout vec4 fragColor;\n\nin vec4 vRgba;\nin vec2 vSplatUv;\nin vec3 vNdc;\nflat in uint vSplatIndex;\nflat in float adjustedStdDev;\n\n#include <logdepthbuf_pars_fragment>\n\nvoid main() {\n vec4 rgba = vRgba;\n\n float z2 = dot(vSplatUv, vSplatUv);\n if (z2 > (adjustedStdDev * adjustedStdDev)) {\n discard;\n }\n\n if (false) {\n \n float a = rgba.a;\n float shifted = sqrt(z2) - max(0.0, a - 1.0);\n float exponent = -0.5 * max(1.0, a) * sqr(max(0.0, shifted));\n float min1a = min(1.0, a);\n rgba.a = mix(min1a, min1a * exp(exponent), falloff);\n } else {\n \n if (rgba.a <= 1.0) {\n rgba.a = mix(rgba.a, rgba.a * exp(-0.5 * z2), falloff);\n } else {\n float a = exp((rgba.a*rgba.a - 1.0) / 2.718281828459045);\n float alpha = 1.0 - pow(1.0 - exp(-0.5 * z2), a);\n rgba.a = mix(1.0, alpha, falloff);\n }\n }\n\n if (rgba.a < minAlpha) {\n discard;\n }\n if (encodeLinear) {\n rgba.rgb = srgbToLinear(rgba.rgb);\n }\n\n #ifdef PREMULTIPLIED_ALPHA\n fragColor = vec4(rgba.rgb * rgba.a, rgba.a);\n #else\n fragColor = rgba;\n #endif\n\n #include <logdepthbuf_fragment>\n}",computeVec4Template:"precision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp usampler2D;\nprecision highp isampler2D;\nprecision highp sampler2DArray;\nprecision highp usampler2DArray;\nprecision highp isampler2DArray;\nprecision highp sampler3D;\nprecision highp usampler3D;\nprecision highp isampler3D;\n\n#include <splatDefines>\n\nuniform uint targetLayer;\nuniform int targetBase;\nuniform int targetCount;\n\nout vec4 target;\n\n{{ GLOBALS }}\n\nvoid computeReadback(int _index) {\n {{ STATEMENTS }}\n}\n\nvoid main() {\n int targetIndex = int(targetLayer << SPLAT_TEX_LAYER_BITS) + int(uint(gl_FragCoord.y) << SPLAT_TEX_WIDTH_BITS) + int(gl_FragCoord.x);\n int index = targetIndex - targetBase;\n\n if ((index >= 0) && (index < targetCount)) {\n computeReadback(index);\n } else {\n target = vec4(0.0, 0.0, 0.0, 0.0);\n }\n}",computeUvec4Vec4Template:"precision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp usampler2D;\nprecision highp isampler2D;\nprecision highp sampler2DArray;\nprecision highp usampler2DArray;\nprecision highp isampler2DArray;\nprecision highp sampler3D;\nprecision highp usampler3D;\nprecision highp isampler3D;\n\n#include <splatDefines>\n\nuniform uint targetLayer;\nuniform int targetBase;\nuniform int targetCount;\n\nlayout(location = 0) out uvec4 target;\nlayout(location = 1) out vec4 target3;\n\n{{ GLOBALS }}\n\nvoid produceSplat(int _index) {\n {{ STATEMENTS }}\n}\n\nvoid main() {\n int targetIndex = int(targetLayer << SPLAT_TEX_LAYER_BITS) + int(uint(gl_FragCoord.y) << SPLAT_TEX_WIDTH_BITS) + int(gl_FragCoord.x);\n int index = targetIndex - targetBase;\n\n \n target = uvec4(0u, 0u, 0u, 0u);\n\n \n target3 = floatToVec4(1.0 / 0.0);\n\n if ((index >= 0) && (index < targetCount)) {\n produceSplat(index);\n }\n}",computeUvec4x2Vec4Template:"precision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp usampler2D;\nprecision highp isampler2D;\nprecision highp sampler2DArray;\nprecision highp usampler2DArray;\nprecision highp isampler2DArray;\nprecision highp sampler3D;\nprecision highp usampler3D;\nprecision highp isampler3D;\n\n#include <splatDefines>\n\nuniform uint targetLayer;\nuniform int targetBase;\nuniform int targetCount;\n\nlayout(location = 0) out uvec4 target;\nlayout(location = 1) out uvec4 target2;\nlayout(location = 2) out vec4 target3;\n\n{{ GLOBALS }}\n\nvoid produceSplat(int _index) {\n {{ STATEMENTS }}\n}\n\nvoid main() {\n int targetIndex = int(targetLayer << SPLAT_TEX_LAYER_BITS) + int(uint(gl_FragCoord.y) << SPLAT_TEX_WIDTH_BITS) + int(gl_FragCoord.x);\n int index = targetIndex - targetBase;\n\n \n target = uvec4(0u, 0u, 0u, 0u);\n target2 = uvec4(0u, 0u, 0u, 0u);\n\n \n target3 = floatToVec4(1.0 / 0.0);\n\n if ((index >= 0) && (index < targetCount)) {\n produceSplat(index);\n }\n}",computeUvec4Template:"precision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp usampler2D;\nprecision highp isampler2D;\nprecision highp sampler2DArray;\nprecision highp usampler2DArray;\nprecision highp isampler2DArray;\nprecision highp sampler3D;\nprecision highp usampler3D;\nprecision highp isampler3D;\n\n#include <splatDefines>\n\nuniform uint targetLayer;\nuniform int targetBase;\nuniform int targetCount;\n\nout uvec4 target;\n\n{{ GLOBALS }}\n\nvoid produceSplat(int _index) {\n {{ STATEMENTS }}\n}\n\nvoid main() {\n int targetIndex = int(targetLayer << SPLAT_TEX_LAYER_BITS) + int(uint(gl_FragCoord.y) << SPLAT_TEX_WIDTH_BITS) + int(gl_FragCoord.x);\n int index = targetIndex - targetBase;\n\n target = uvec4(0u, 0u, 0u, 0u);\n if ((index >= 0) && (index < targetCount)) {\n produceSplat(index);\n }\n}"}),ho}const fo=class e{constructor({renderer:t}={}){this.renderer=t,this.capacity=0,this.count=0}dispose(){this.target&&(this.target.dispose(),this.target=void 0)}static ensureBuffer(t,e){const n=4*(Math.ceil(Math.max(1,t)/i)*i);if(e.byteLength>=n)return e;const a=new ArrayBuffer(n);if(e instanceof ArrayBuffer)return a;return new(0,e.constructor)(a)}ensureBuffer(t,n){return e.ensureBuffer(t,n)}ensureCapacity(e){const{width:n,height:a,depth:s,maxSplats:r}=ea(e);(!this.target||r>this.capacity)&&(this.dispose(),this.capacity=r,this.target=new t.WebGLArrayRenderTarget(n,a,s,{depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1,magFilter:t.NearestFilter,minFilter:t.NearestFilter}),this.target.texture.format=t.RGBAFormat,this.target.texture.type=t.UnsignedByteType,this.target.texture.internalFormat="RGBA8",this.target.scissorTest=!0)}prepareProgramMaterial(t){let n=e.readbackProgram.get(t);if(!n){const a=O({index:"int"},{rgba8:"vec4"},(({index:e})=>{t.inputs.index=e;return{rgba8:new Zt({rgba8:t.outputs.rgba8})}}));e.programTemplate||(e.programTemplate=new Ma(xo().computeVec4Template)),n=new _a({graph:a,inputs:{index:"_index"},outputs:{rgba8:"target"},template:e.programTemplate}),Object.assign(n.uniforms,{targetLayer:{value:0},targetBase:{value:0},targetCount:{value:0}}),e.readbackProgram.set(t,n)}const a=n.prepareMaterial();return e.fullScreenQuad.material=a,{program:n,material:a}}saveRenderState(t){return{target:t.getRenderTarget(),xrEnabled:t.xr.enabled,autoClear:t.autoClear}}resetRenderState(t,e){t.setRenderTarget(e.target),t.xr.enabled=e.xrEnabled,t.autoClear=e.autoClear}process({count:t,material:n}){const a=this.renderer;if(!a)throw new Error("No renderer");if(!this.target)throw new Error("No target");const s=4194304;n.uniforms.targetBase.value=0,n.uniforms.targetCount.value=t;let r=0;for(;r<t;){const l=Math.floor(r/s),u=l*s,c=Math.min(o,Math.ceil((t-u)/i));n.uniforms.targetLayer.value=l,this.target.scissor.set(0,0,i,c),a.setRenderTarget(this.target,l),a.xr.enabled=!1,a.autoClear=!1,e.fullScreenQuad.render(a),r+=i*c}this.count=t}async read({readback:t}){const e=this.renderer;if(!e)throw new Error("No renderer");if(!this.target)throw new Error("No target");const n=Math.ceil(this.count/i)*i;if(t.byteLength<4*n)throw new Error(`Readback buffer too small: ${t.byteLength} < ${4*n}`);const a=new Uint8Array(t instanceof ArrayBuffer?t:t.buffer),s=4194304;let r=0;const l=[];for(;r<this.count;){const t=Math.floor(r/s),n=t*s,u=Math.min(o,Math.ceil((this.count-n)/i));e.setRenderTarget(this.target,t);const c=i*u*4,p=a.subarray(4*n,4*n+c),d=null==e?void 0:e.readRenderTargetPixelsAsync(this.target,0,0,i,u,p);l.push(d),r+=i*u}return Promise.all(l).then((()=>t))}render({reader:t,count:e,renderer:n}){if(this.renderer=n||this.renderer,!this.renderer)throw new Error("No renderer");this.ensureCapacity(e);const{program:a,material:s}=this.prepareProgramMaterial(t);a.update();const r=this.saveRenderState(this.renderer);this.process({count:e,material:s}),this.resetRenderState(this.renderer,r)}async readback({readback:t}){if(!this.renderer)throw new Error("No renderer");const e=this.saveRenderState(this.renderer),n=this.read({readback:t});return this.resetRenderState(this.renderer,e),n}async renderReadback({reader:t,count:e,renderer:n,readback:a}){if(this.renderer=n||this.renderer,!this.renderer)throw new Error("No renderer");this.ensureCapacity(e);const{program:s,material:r}=this.prepareProgramMaterial(t);s.update();const i=this.saveRenderState(this.renderer);this.process({count:e,material:r});const o=this.read({readback:a});return this.resetRenderState(this.renderer,i),o}getTexture(){var t;return null==(t=this.target)?void 0:t.texture}};fo.programTemplate=null,fo.readbackProgram=new WeakMap,fo.fullScreenQuad=new e.FullScreenQuad(new t.RawShaderMaterial({visible:!1}));let mo=fo;var yo=(t=>(t.ALL="all",t.PLANE="plane",t.SPHERE="sphere",t.BOX="box",t.ELLIPSOID="ellipsoid",t.CYLINDER="cylinder",t.CAPSULE="capsule",t.INFINITE_CONE="infinite_cone",t))(yo||{});function go(t){switch(t){case"all":return 0;case"plane":return 1;case"sphere":return 2;case"box":return 3;case"ellipsoid":return 4;case"cylinder":return 5;case"capsule":return 6;case"infinite_cone":return 7;default:throw new Error(`Unknown SDF type: ${t}`)}}var vo=(t=>(t.MULTIPLY="multiply",t.SET_RGB="set_rgb",t.ADD_RGBA="add_rgba",t))(vo||{});function wo(t){switch(t){case"multiply":return 0;case"set_rgb":return 1;case"add_rgba":return 2;default:throw new Error(`Unknown blend mode: ${t}`)}}class bo extends t.Object3D{constructor(e={}){super();const{type:n,invert:a,opacity:s,color:r,displace:i,radius:o}=e;this.type=n??"sphere",this.invert=a??!1,this.opacity=s??1,this.color=r??new t.Color(1,1,1),this.displace=i??new t.Vector3(0,0,0),this.radius=o??0}}const So=class e extends t.Object3D{constructor(t={}){const{name:n,rgbaBlendMode:a="multiply",sdfSmooth:s=0,softEdge:r=0,invert:i=!1,sdfs:o=null}=t;super(),this.rgbaBlendMode=a,this.sdfSmooth=s,this.softEdge=r,this.invert=i,this.sdfs=o,this.ordering=e.nextOrdering++,this.name=n??`Edit ${this.ordering}`}addSdf(t){null==this.sdfs&&(this.sdfs=[]),this.sdfs.includes(t)||this.sdfs.push(t)}removeSdf(t){null!=this.sdfs&&(this.sdfs=this.sdfs.filter((e=>e!==t)))}};So.nextOrdering=1;let To=So;class _o{constructor({maxSdfs:t,maxEdits:e}){this.maxSdfs=Math.max(16,t??0),this.numSdfs=0,this.sdfData=new Uint32Array(8*this.maxSdfs*4),this.sdfFloatData=new Float32Array(this.sdfData.buffer),this.sdfTexture=this.newSdfTexture(this.sdfData,this.maxSdfs),this.dynoSdfArray=new ne({key:"sdfArray",type:Mo,globals:()=>[ko],value:{numSdfs:0,sdfTexture:this.sdfTexture},update:t=>(t.numSdfs=this.numSdfs,t.sdfTexture=this.sdfTexture,t)}),this.maxEdits=Math.max(16,e??0),this.numEdits=0,this.editData=new Uint32Array(4*this.maxEdits),this.editFloatData=new Float32Array(this.editData.buffer),this.dynoNumEdits=new re({value:0}),this.dynoEdits=this.newEdits(this.editData,this.maxEdits)}newSdfTexture(e,n){const a=new t.DataTexture(e,8,n,t.RGBAIntegerFormat,t.UnsignedIntType);return a.internalFormat="RGBA32UI",a.needsUpdate=!0,a}newEdits(t,e){return new ne({key:"edits",type:"uvec4",count:e,globals:()=>[$o],value:t})}ensureCapacity({maxSdfs:t,maxEdits:e}){let n=!1;return t>this.sdfTexture.image.height&&(this.sdfTexture.dispose(),this.maxSdfs=Math.max(2*this.maxSdfs,t),this.sdfData=new Uint32Array(8*this.maxSdfs*4),this.sdfFloatData=new Float32Array(this.sdfData.buffer),this.sdfTexture=this.newSdfTexture(this.sdfData,this.maxSdfs)),e>(this.dynoEdits.count??0)&&(this.maxEdits=Math.max(2*this.maxEdits,e),this.editData=new Uint32Array(4*this.maxEdits),this.editFloatData=new Float32Array(this.editData.buffer),this.dynoEdits=this.newEdits(this.editData,this.maxEdits),n=!0),n}updateEditData(t,e){const n=this.editData[t]!==e;return this.editData[t]=e,n}updateEditFloatData(t,e){Do[0]=e;const n=this.editFloatData[t]!==Do[0];return n&&(this.editFloatData[t]=Do[0]),n}encodeEdit(t,{sdfFirst:e,sdfCount:n,invert:a,rgbaBlendMode:s,softEdge:r,sdfSmooth:i}){const o=4*t;let l=!1;return l=this.updateEditData(o+0,s|(a?256:0))||l,l=this.updateEditData(o+1,e|n<<16)||l,l=this.updateEditFloatData(o+2,r)||l,l=this.updateEditFloatData(o+3,i)||l,l}updateSdfData(t,e){const n=this.sdfData[t]!==e;return this.sdfData[t]=e,n}updateSdfFloatData(t,e){Do[0]=e;const n=this.sdfFloatData[t]!==Do[0];return n&&(this.sdfFloatData[t]=Do[0]),n}encodeSdf(t,{sdfType:e,invert:n,center:a,quaternion:s,scale:r,sizes:i},o){const l=32*t,u=e|(n?256:0);let c=!1;c=this.updateSdfFloatData(l+0,(null==a?void 0:a.x)??0)||c,c=this.updateSdfFloatData(l+1,(null==a?void 0:a.y)??0)||c,c=this.updateSdfFloatData(l+2,(null==a?void 0:a.z)??0)||c,c=this.updateSdfData(l+3,u)||c,c=this.updateSdfFloatData(l+4,(null==s?void 0:s.x)??0)||c,c=this.updateSdfFloatData(l+5,(null==s?void 0:s.y)??0)||c,c=this.updateSdfFloatData(l+6,(null==s?void 0:s.z)??0)||c,c=this.updateSdfFloatData(l+7,(null==s?void 0:s.w)??0)||c,c=this.updateSdfFloatData(l+8,(null==r?void 0:r.x)??0)||c,c=this.updateSdfFloatData(l+9,(null==r?void 0:r.y)??0)||c,c=this.updateSdfFloatData(l+10,(null==r?void 0:r.z)??0)||c,c=this.updateSdfData(l+11,0)||c,c=this.updateSdfFloatData(l+12,(null==i?void 0:i.x)??0)||c,c=this.updateSdfFloatData(l+13,(null==i?void 0:i.y)??0)||c,c=this.updateSdfFloatData(l+14,(null==i?void 0:i.z)??0)||c,c=this.updateSdfFloatData(l+15,(null==i?void 0:i.w)??0)||c;const p=Math.min(4,o.length);for(let d=0;d<p;++d){const t=l+16+4*d;c=this.updateSdfFloatData(t+0,o[d].x)||c,c=this.updateSdfFloatData(t+1,o[d].y)||c,c=this.updateSdfFloatData(t+2,o[d].z)||c,c=this.updateSdfFloatData(t+3,o[d].w)||c}return c}update(e){const n=e.reduce(((t,{sdfs:e})=>t+e.length),0),a=this.ensureCapacity({maxEdits:e.length,maxSdfs:n}),s=[new t.Vector4,new t.Vector4],r=new t.Vector3,i=new t.Quaternion,o=new t.Vector3,l=new t.Vector4;let u=0,c=a;e.length!==this.dynoNumEdits.value&&(this.dynoNumEdits.value=e.length,this.numEdits=e.length,c=!0);for(const[t,{edit:p,sdfs:d}]of e.entries()){c=this.encodeEdit(t,{sdfFirst:u,sdfCount:d.length,invert:p.invert,rgbaBlendMode:wo(p.rgbaBlendMode),softEdge:p.softEdge,sdfSmooth:p.sdfSmooth})||c;let e=!1;for(const t of d){l.set(t.scale.x,t.scale.y,t.scale.z,t.radius),t.scale.setScalar(1),t.updateMatrixWorld();t.matrixWorld.clone().invert().decompose(r,i,o),t.scale.set(l.x,l.y,l.z),t.updateMatrixWorld(),s[0].set(t.color.r,t.color.g,t.color.b,t.opacity),s[1].set(t.displace.x,t.displace.y,t.displace.z,1),e=this.encodeSdf(u,{sdfType:go(t.type),invert:t.invert,center:r,quaternion:i,scale:o,sizes:l},s)||e,u+=1}this.numSdfs=u,e&&(this.sdfTexture.needsUpdate=!0),c||(c=e)}return{updated:c,dynoUpdated:a}}modify(t){return function(t,e,n,a){const s=new B({inTypes:{gsplat:Y,sdfArray:Mo,numEdits:"int",rgbaDisplaceEdits:"uvec4"},outTypes:{gsplat:Y},globals:()=>[ko,$o],inputs:{gsplat:t,sdfArray:e,numEdits:n,rgbaDisplaceEdits:a},statements:({inputs:t,outputs:e})=>{const{sdfArray:n,numEdits:a,rgbaDisplaceEdits:s}=t,{gsplat:r}=e;return W(`\n ${r} = ${t.gsplat};\n if (isGsplatActive(${r}.flags)) {\n for (int editIndex = 0; editIndex < ${a}; ++editIndex) {\n applyPackedRgbaDisplaceEdit(\n ${s}[editIndex], ${n}.sdfTexture, ${n}.numSdfs,\n ${r}.center, ${r}.rgba\n );\n }\n }\n `)}});return s.outputs.gsplat}(t,this.dynoSdfArray,this.dynoNumEdits,this.dynoEdits)}modifyCov(t){return function(t,e,n,a){const s=new B({inTypes:{covsplat:J,sdfArray:Mo,numEdits:"int",rgbaDisplaceEdits:"uvec4"},outTypes:{covsplat:J},globals:()=>[ko,$o],inputs:{covsplat:t,sdfArray:e,numEdits:n,rgbaDisplaceEdits:a},statements:({inputs:t,outputs:e})=>{const{sdfArray:n,numEdits:a,rgbaDisplaceEdits:s}=t,{covsplat:r}=e;return W(`\n ${r} = ${t.covsplat};\n if (isCovSplatActive(${r}.flags)) {\n for (int editIndex = 0; editIndex < ${a}; ++editIndex) {\n applyPackedRgbaDisplaceEdit(\n ${s}[editIndex], ${n}.sdfTexture, ${n}.numSdfs,\n ${r}.center, ${r}.rgba\n );\n }\n }\n `)}});return s.outputs.covsplat}(t,this.dynoSdfArray,this.dynoNumEdits,this.dynoEdits)}}const Mo={type:"SdfArray"},ko=j("\n struct SdfArray {\n int numSdfs;\n usampler2D sdfTexture;\n };\n\n void unpackSdfArray(\n usampler2D sdfTexture, int sdfIndex, out uint flags,\n out vec3 center, out vec4 quaternion, out vec3 scale, out vec4 sizes,\n int numValues, out vec4 values[4]\n ) {\n uvec4 temp = texelFetch(sdfTexture, ivec2(0, sdfIndex), 0);\n flags = temp.w;\n center = vec3(uintBitsToFloat(temp.x), uintBitsToFloat(temp.y), uintBitsToFloat(temp.z));\n\n temp = texelFetch(sdfTexture, ivec2(1, sdfIndex), 0);\n quaternion = vec4(uintBitsToFloat(temp.x), uintBitsToFloat(temp.y), uintBitsToFloat(temp.z), uintBitsToFloat(temp.w));\n\n temp = texelFetch(sdfTexture, ivec2(2, sdfIndex), 0);\n scale = vec3(uintBitsToFloat(temp.x), uintBitsToFloat(temp.y), uintBitsToFloat(temp.z));\n\n temp = texelFetch(sdfTexture, ivec2(3, sdfIndex), 0);\n sizes = vec4(uintBitsToFloat(temp.x), uintBitsToFloat(temp.y), uintBitsToFloat(temp.z), uintBitsToFloat(temp.w));\n\n for (int i = 0; i < numValues; ++i) {\n temp = texelFetch(sdfTexture, ivec2(4 + i, sdfIndex), 0);\n values[i] = vec4(uintBitsToFloat(temp.x), uintBitsToFloat(temp.y), uintBitsToFloat(temp.z), uintBitsToFloat(temp.w));\n }\n }\n\n const uint SDF_FLAG_TYPE = 0xFFu;\n const uint SDF_FLAG_INVERT = 1u << 8u;\n\n const uint SDF_TYPE_ALL = 0u;\n const uint SDF_TYPE_PLANE = 1u;\n const uint SDF_TYPE_SPHERE = 2u;\n const uint SDF_TYPE_BOX = 3u;\n const uint SDF_TYPE_ELLIPSOID = 4u;\n const uint SDF_TYPE_CYLINDER = 5u;\n const uint SDF_TYPE_CAPSULE = 6u;\n const uint SDF_TYPE_INFINITE_CONE = 7u;\n\n float evaluateSdfArray(\n usampler2D sdfTexture, int numSdfs, int sdfFirst, int sdfCount, vec3 pos,\n float smoothK, int numValues, out vec4 outValues[4]\n ) {\n float distanceAccum = (smoothK == 0.0) ? 1.0 / 0.0 : 0.0;\n float maxExp = -1.0 / 0.0;\n for (int i = 0; i < numValues; ++i) {\n outValues[i] = vec4(0.0);\n }\n\n uint flags;\n vec3 center, scale;\n vec4 quaternion, sizes;\n vec4 values[4];\n\n int sdfLast = min(sdfFirst + sdfCount, numSdfs);\n for (int index = sdfFirst; index < sdfLast; ++index) {\n unpackSdfArray(sdfTexture, index, flags, center, quaternion, scale, sizes, numValues, values);\n uint sdfType = flags & SDF_FLAG_TYPE;\n vec3 sdfPos = quatVec(quaternion, pos * scale) + center;\n\n float distance;\n switch (sdfType) {\n case SDF_TYPE_ALL:\n distance = -1.0 / 0.0;\n break;\n case SDF_TYPE_PLANE: {\n distance = sdfPos.z;\n break;\n }\n case SDF_TYPE_SPHERE: {\n distance = length(sdfPos) - sizes.w;\n break;\n }\n case SDF_TYPE_BOX: {\n vec3 q = abs(sdfPos) - sizes.xyz + sizes.w;\n distance = length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0) - sizes.w;\n break;\n }\n case SDF_TYPE_ELLIPSOID: {\n vec3 sizes = sizes.xyz;\n float k0 = length(sdfPos / sizes);\n float k1 = length(sdfPos / dot(sizes, sizes));\n distance = k0 * (k0 - 1.0) / k1;\n break;\n }\n case SDF_TYPE_CYLINDER: {\n vec2 d = abs(vec2(length(sdfPos.xz), sdfPos.y)) - sizes.wy;\n distance = min(max(d.x, d.y), 0.0) + length(max(d, 0.0));\n break;\n }\n case SDF_TYPE_CAPSULE: {\n sdfPos.y -= clamp(sdfPos.y, -0.5 * sizes.y, 0.5 * sizes.y);\n distance = length(sdfPos) - sizes.w;\n break;\n }\n case SDF_TYPE_INFINITE_CONE: {\n float angle = 0.25 * PI * sizes.w;\n vec2 c = vec2(sin(angle), cos(angle));\n vec2 q = vec2(length(sdfPos.xy), -sdfPos.z);\n float d = length(q - c * max(dot(q, c), 0.0));\n distance = d * (((q.x * c.y - q.y * c.x) < 0.0) ? -1.0 : 1.0);\n break;\n }\n }\n\n if ((flags & SDF_FLAG_INVERT) != 0u) {\n distance = -distance;\n }\n\n if (smoothK == 0.0) {\n if (distance < distanceAccum) {\n distanceAccum = distance;\n for (int i = 0; i < numValues; ++i) {\n outValues[i] = values[i];\n }\n }\n } else {\n float scaledDistance = -distance / smoothK;\n if (scaledDistance > maxExp) {\n float scale = exp(maxExp - scaledDistance);\n distanceAccum *= scale;\n for (int i = 0; i < numValues; ++i) {\n outValues[i] *= scale;\n }\n maxExp = scaledDistance;\n }\n\n float weight = exp(scaledDistance - maxExp);\n distanceAccum += weight;\n for (int i = 0; i < numValues; ++i) {\n outValues[i] += weight * values[i];\n }\n }\n }\n\n if (smoothK == 0.0) {\n return distanceAccum;\n } else {\n // Very distant SDFs may result in 0 accumulation\n if (distanceAccum == 0.0) {\n return 1.0 / 0.0;\n }\n for (int i = 0; i < numValues; ++i) {\n outValues[i] /= distanceAccum;\n }\n return (-log(distanceAccum) - maxExp) * smoothK;\n }\n }\n\n float modulateSdfArray(\n usampler2D sdfTexture, int numSdfs, int sdfFirst, int sdfCount, vec3 pos,\n float smoothK, int numValues, out vec4 values[4],\n float softEdge, bool invert\n ) {\n float distance = evaluateSdfArray(sdfTexture, numSdfs, sdfFirst, sdfCount, pos, smoothK, numValues, values);\n if (invert) {\n distance = -distance;\n }\n\n return (softEdge == 0.0) ? ((distance < 0.0) ? 1.0 : 0.0)\n : clamp(-distance / softEdge + 0.5, 0.0, 1.0);\n }\n"),$o=j("\n const uint EDIT_FLAG_BLEND = 0xFFu;\n const uint EDIT_BLEND_MULTIPLY = 0u;\n const uint EDIT_BLEND_SET_RGB = 1u;\n const uint EDIT_BLEND_ADD_RGBA = 2u;\n const uint EDIT_FLAG_INVERT = 0x100u;\n\n void decodeEdit(\n uvec4 packedEdit, out int sdfFirst, out int sdfCount,\n out bool invert, out uint rgbaBlendMode, out float softEdge, out float sdfSmooth\n ) {\n rgbaBlendMode = packedEdit.x & EDIT_FLAG_BLEND;\n invert = (packedEdit.x & EDIT_FLAG_INVERT) != 0u;\n\n sdfFirst = int(packedEdit.y & 0xFFFFu);\n sdfCount = int(packedEdit.y >> 16u);\n\n softEdge = uintBitsToFloat(packedEdit.z);\n sdfSmooth = uintBitsToFloat(packedEdit.w);\n }\n\n void applyRgbaDisplaceEdit(\n usampler2D sdfTexture, int numSdfs, int sdfFirst, int sdfCount, inout vec3 pos,\n float smoothK, float softEdge, bool invert, uint rgbaBlendMode, inout vec4 rgba\n ) {\n vec4 values[4];\n float modulate = modulateSdfArray(sdfTexture, numSdfs, sdfFirst, sdfCount, pos, smoothK, 2, values, softEdge, invert);\n // On Android, moving values[0] is necessary to work around a compiler bug.\n vec4 sdfRgba = values[0];\n vec4 sdfDisplaceScale = values[1];\n\n vec4 target;\n switch (rgbaBlendMode) {\n case EDIT_BLEND_MULTIPLY:\n target = rgba * sdfRgba;\n break;\n case EDIT_BLEND_SET_RGB:\n target = vec4(sdfRgba.rgb, rgba.a * sdfRgba.a);\n break;\n case EDIT_BLEND_ADD_RGBA:\n target = rgba + sdfRgba;\n break;\n default:\n // Debug output if blend mode not set\n target = vec4(fract(pos), 1.0);\n }\n rgba = mix(rgba, target, modulate);\n pos += sdfDisplaceScale.xyz * modulate;\n }\n\n void applyPackedRgbaDisplaceEdit(uvec4 packedEdit, usampler2D sdfTexture, int numSdfs, inout vec3 pos, inout vec4 rgba) {\n int sdfFirst, sdfCount;\n bool invert;\n uint rgbaBlendMode;\n float softEdge, sdfSmooth;\n decodeEdit(packedEdit, sdfFirst, sdfCount, invert, rgbaBlendMode, softEdge, sdfSmooth);\n applyRgbaDisplaceEdit(sdfTexture, numSdfs, sdfFirst, sdfCount, pos, sdfSmooth, softEdge, invert, rgbaBlendMode, rgba);\n }\n");const Do=new Float32Array(1);class zo{constructor(){this.scale=new ie({value:Number.NEGATIVE_INFINITY}),this.rotate=new ge({value:new t.Quaternion(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}),this.translate=new xe({value:new t.Vector3(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)})}apply(t){return qi(t,{scale:this.scale,rotate:this.rotate,translate:this.translate})}applyDir(t){return Ui(t,{rotate:this.rotate})}applyGsplat(t){return ut(t,{scale:this.scale,rotate:this.rotate,translate:this.translate})}updateFromMatrix(e){const n=new t.Vector3,a=new t.Quaternion,s=new t.Vector3;e.decompose(s,a,n);const r=(n.x+n.y+n.z)/3;let i=!1;return r!==this.scale.value&&(this.scale.value=r,i=!0),s.equals(this.translate.value)||(this.translate.value.copy(s),i=!0),a.equals(this.rotate.value)||(this.rotate.value.copy(a),i=!0),i}update(t){return t.updateMatrixWorld(),this.updateFromMatrix(t.matrixWorld)}}class Io{constructor(){this.basis=new Te({value:new t.Matrix3}),this.offset=new xe({value:new t.Vector3})}apply(t){const e=rs(this.basis,t);return as(e,this.offset)}applyDir(t){return rs(this.basis,t)}applyCovSplat(t){return new B({inTypes:{covsplat:J,basis:"mat3",offset:"vec3"},outTypes:{covsplat:J},inputs:{covsplat:t,basis:this.basis,offset:this.offset},statements:({inputs:t,outputs:e})=>{const{covsplat:n,basis:a,offset:s}=t;return n&&a&&s?W(`\n ${e.covsplat}.flags = 0u;\n if (isCovSplatActive(${n}.flags)) {\n ${e.covsplat}.flags = ${n}.flags;\n ${e.covsplat}.index = ${n}.index;\n ${e.covsplat}.rgba = ${n}.rgba;\n\n ${e.covsplat}.center = ${a} * ${n}.center + ${s};\n \n mat3 cov = mat3(\n ${n}.xxyyzz.x, ${n}.xyxzyz.x, ${n}.xyxzyz.y,\n ${n}.xyxzyz.x, ${n}.xxyyzz.y, ${n}.xyxzyz.z,\n ${n}.xyxzyz.y, ${n}.xyxzyz.z, ${n}.xxyyzz.z\n );\n cov = ${a} * cov * transpose(${a});\n ${e.covsplat}.xxyyzz = vec3(cov[0][0], cov[1][1], cov[2][2]);\n ${e.covsplat}.xyxzyz = vec3(cov[0][1], cov[0][2], cov[1][2]);\n }\n `):[`${e.covsplat}.flags = 0u;`]}}).outputs.covsplat}updateFromMatrix(e){const n=(new t.Matrix3).setFromMatrix4(e),a=(new t.Vector3).setFromMatrixColumn(e,3),s=!n.equals(this.basis.value)||!a.equals(this.offset.value);return s&&(this.basis.value.copy(n),this.offset.value.copy(a)),s}update(t){return t.updateMatrixWorld(),this.updateFromMatrix(t.matrixWorld)}}class Eo extends t.Object3D{constructor({numSplats:t,generator:e,covGenerator:n,construct:a,update:s}){if(super(),this.numSplats=t??0,this.generator=e,this.covGenerator=n,this.frameUpdate=s,this.version=0,this.mappingVersion=0,a){const t=a(this);Object.assign(this,t)}}updateVersion(){this.version+=1}updateMappingVersion(){this.mappingVersion+=1,this.version+=1}set needsUpdate(t){t&&this.updateVersion()}}class Ao{static __wrap(t){t>>>=0;const e=Object.create(Ao.prototype);return e.__wbg_ptr=t,Vo.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Vo.unregister(this),t}free(){const t=this.__destroy_into_raw();cl.__wbg_chunkdecoder_free(t,0)}finish(){const t=this.__destroy_into_raw(),e=cl.chunkdecoder_finish(t);if(e[2])throw rl(e[1]);return rl(e[0])}push(t){const e=cl.chunkdecoder_push(this.__wbg_ptr,t);if(e[1])throw rl(e[0])}}Symbol.dispose&&(Ao.prototype[Symbol.dispose]=Ao.prototype.free);class Fo{static __wrap(t){t>>>=0;const e=Object.create(Fo.prototype);return e.__wbg_ptr=t,Bo.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,Bo.unregister(this),t}free(){const t=this.__destroy_into_raw();cl.__wbg_csplatarray_free(t,0)}bhatt_lod(t){cl.csplatarray_bhatt_lod(this.__wbg_ptr,t)}has_lod(){return 0!==cl.csplatarray_has_lod(this.__wbg_ptr)}inject_rgba8(t){cl.csplatarray_inject_rgba8(this.__wbg_ptr,t)}len(){return cl.csplatarray_len(this.__wbg_ptr)>>>0}tiny_lod(t,e){cl.csplatarray_tiny_lod(this.__wbg_ptr,t,e)}to_extsplats(){const t=cl.csplatarray_to_extsplats(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}to_extsplats_lod(){const t=cl.csplatarray_to_extsplats_lod(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}to_packedsplats(){const t=cl.csplatarray_to_packedsplats(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}to_packedsplats_lod(){const t=cl.csplatarray_to_packedsplats_lod(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}get maxShDegree(){return cl.__wbg_get_csplatarray_maxShDegree(this.__wbg_ptr)>>>0}get numSplats(){return cl.__wbg_get_csplatarray_numSplats(this.__wbg_ptr)>>>0}set maxShDegree(t){cl.__wbg_set_csplatarray_maxShDegree(this.__wbg_ptr,t)}set numSplats(t){cl.__wbg_set_csplatarray_numSplats(this.__wbg_ptr,t)}}Symbol.dispose&&(Fo.prototype[Symbol.dispose]=Fo.prototype.free);class Po{static __wrap(t){t>>>=0;const e=Object.create(Po.prototype);return e.__wbg_ptr=t,No.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){const t=this.__wbg_ptr;return this.__wbg_ptr=0,No.unregister(this),t}free(){const t=this.__destroy_into_raw();cl.__wbg_gsplatarray_free(t,0)}get maxShDegree(){return cl.__wbg_get_gsplatarray_maxShDegree(this.__wbg_ptr)>>>0}get numSplats(){return cl.__wbg_get_gsplatarray_numSplats(this.__wbg_ptr)>>>0}bhatt_lod(t){cl.gsplatarray_bhatt_lod(this.__wbg_ptr,t)}concat(t){!function(t,e){if(!(t instanceof e))throw new Error(`expected instance of ${e.name}`)}(t,Po);const e=cl.gsplatarray_concat(this.__wbg_ptr,t.__wbg_ptr);if(e[1])throw rl(e[0])}encode_to_spz(t,e){const n=this.__destroy_into_raw(),a=cl.gsplatarray_encode_to_spz(n,t,e);if(a[2])throw rl(a[1]);return rl(a[0])}has_lod(){return 0!==cl.gsplatarray_has_lod(this.__wbg_ptr)}inject_rgba8(t){cl.gsplatarray_inject_rgba8(this.__wbg_ptr,t)}len(){return cl.gsplatarray_len(this.__wbg_ptr)>>>0}tiny_lod(t,e){cl.gsplatarray_tiny_lod(this.__wbg_ptr,t,e)}to_extsplats(){const t=cl.gsplatarray_to_extsplats(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}to_extsplats_lod(){const t=cl.gsplatarray_to_extsplats_lod(this.__wbg_ptr);if(t[2])throw rl(t[1]);return rl(t[0])}to_packedsplats(t){const e=cl.gsplatarray_to_packedsplats(this.__wbg_ptr,t);if(e[2])throw rl(e[1]);return rl(e[0])}to_packedsplats_lod(t){const e=cl.gsplatarray_to_packedsplats_lod(this.__wbg_ptr,t);if(e[2])throw rl(e[1]);return rl(e[0])}transform(t){const e=cl.gsplatarray_transform(this.__wbg_ptr,t);if(e[1])throw rl(e[0])}set maxShDegree(t){cl.__wbg_set_gsplatarray_maxShDegree(this.__wbg_ptr,t)}set numSplats(t){cl.__wbg_set_gsplatarray_numSplats(this.__wbg_ptr,t)}}function Co(t){const e=cl.decode_rad_header(t);if(e[2])throw rl(e[1]);return rl(e[0])}function Lo(t,e){var n=al(t)?0:sl(t,cl.__wbindgen_malloc,cl.__wbindgen_realloc),a=pl,s=al(e)?0:sl(e,cl.__wbindgen_malloc,cl.__wbindgen_realloc),r=pl;const i=cl.decode_to_gsplatarray(n,a,s,r);if(i[2])throw rl(i[1]);return Ao.__wrap(i[0])}function Ro(t,e,n,a,s,r,i,o,l,u){return cl.raycast_ext_buffers(t,e,n,a,s,r,i,o,l,u)}function qo(t,e,n,a,s,r,i,o,l,u,c,p,d){return cl.raycast_packed_buffer(t,e,n,a,s,r,i,o,l,u,c,p,d)}function Uo(){const t={__proto__:null,__wbg_Error_2e59b1b37a9a34c3:function(t,e){return Error(Yo(t,e))},__wbg___wbindgen_boolean_get_a86c216575a75c30:function(t){const e="boolean"==typeof t?t:void 0;return al(e)?16777215:e?1:0},__wbg___wbindgen_debug_string_dd5d2d07ce9e6c57:function(t,e){const n=sl(Go(e),cl.__wbindgen_malloc,cl.__wbindgen_realloc),a=pl;Ko().setInt32(t+4,a,!0),Ko().setInt32(t+0,n,!0)},__wbg___wbindgen_in_4bd7a57e54337366:function(t,e){return t in e},__wbg___wbindgen_is_falsy_c6ddfae1bb56d5ef:function(t){return!t},__wbg___wbindgen_is_function_49868bde5eb1e745:function(t){return"function"==typeof t},__wbg___wbindgen_is_object_40c5a80572e8f9d3:function(t){return"object"==typeof t&&null!==t},__wbg___wbindgen_is_undefined_c0cca72b82b86f4d:function(t){return void 0===t},__wbg___wbindgen_jsval_loose_eq_3a72ae764d46d944:function(t,e){return t==e},__wbg___wbindgen_number_get_7579aab02a8a620c:function(t,e){const n="number"==typeof e?e:void 0;Ko().setFloat64(t+8,al(n)?0:n,!0),Ko().setInt32(t+0,!al(n),!0)},__wbg___wbindgen_string_get_914df97fcfa788f2:function(t,e){const n="string"==typeof e?e:void 0;var a=al(n)?0:sl(n,cl.__wbindgen_malloc,cl.__wbindgen_realloc),s=pl;Ko().setInt32(t+4,s,!0),Ko().setInt32(t+0,a,!0)},__wbg___wbindgen_throw_81fc77679af83bc6:function(t,e){throw new Error(Yo(t,e))},__wbg_call_7f2987183bb62793:function(){return nl((function(t,e){return t.call(e)}),arguments)},__wbg_csplatarray_new:function(t){return Fo.__wrap(t)},__wbg_done_547d467e97529006:function(t){return t.done},__wbg_error_a6fa202b58aa1cd3:function(t,e){let n,a;try{n=t,a=e}finally{cl.__wbindgen_free(n,a,1)}},__wbg_get_4848e350b40afc16:function(t,e){return t[e>>>0]},__wbg_get_ed0642c4b9d31ddf:function(){return nl((function(t,e){return Reflect.get(t,e)}),arguments)},__wbg_get_f96702c6245e4ef9:function(){return nl((function(t,e){return Reflect.get(t,e)}),arguments)},__wbg_get_unchecked_7d7babe32e9e6a54:function(t,e){return t[e>>>0]},__wbg_get_with_ref_key_6412cf3094599694:function(t,e){return t[e]},__wbg_gsplatarray_new:function(t){return Po.__wrap(t)},__wbg_instanceof_ArrayBuffer_ff7c1337a5e3b33a:function(t){let e;try{e=t instanceof ArrayBuffer}catch(n){e=!1}return e},__wbg_instanceof_Uint8Array_4b8da683deb25d72:function(t){let e;try{e=t instanceof Uint8Array}catch(n){e=!1}return e},__wbg_isArray_db61795ad004c139:function(t){return Array.isArray(t)},__wbg_iterator_de403ef31815a3e6:function(){return Symbol.iterator},__wbg_length_0c32cb8543c8e4c8:function(t){return t.length},__wbg_length_1e701798fdcaa3b4:function(t){return t.length},__wbg_length_6e821edde497a532:function(t){return t.length},__wbg_length_a4ca9e78359b5f1f:function(t){return t.length},__wbg_length_fd4646b401926788:function(t){return t.length},__wbg_new_227d7c05414eb861:function(){return new Error},__wbg_new_4f9fafbb3909af72:function(){return new Object},__wbg_new_a560378ea1240b14:function(t){return new Uint8Array(t)},__wbg_new_f3c9df4f38f3f798:function(){return new Array},__wbg_new_from_slice_2580ff33d0d10520:function(t,e){return new Uint8Array(jo(t,e))},__wbg_new_with_length_26bffbe236bf73f9:function(t){return new Float32Array(t>>>0)},__wbg_new_with_length_41a22191b9bdfd66:function(t){return new Uint32Array(t>>>0)},__wbg_next_01132ed6134b8ef5:function(t){return t.next},__wbg_next_b3713ec761a9dbfd:function(){return nl((function(t){return t.next()}),arguments)},__wbg_prototypesetcall_3e05eb9545565046:function(t,e,n){Uint8Array.prototype.set.call(jo(t,e),n)},__wbg_prototypesetcall_64c287a27cc24d27:function(t,e,n){var a,s;Uint16Array.prototype.set.call((a=t,s=e,a>>>=0,(null!==Jo&&0!==Jo.byteLength||(Jo=new Uint16Array(cl.memory.buffer)),Jo).subarray(a/2,a/2+s)),n)},__wbg_prototypesetcall_e42275e601e14eeb:function(t,e,n){Uint32Array.prototype.set.call(Wo(t,e),n)},__wbg_push_6bdbc990be5ac37b:function(t,e){return t.push(e)},__wbg_set_448126769bf7c181:function(t,e,n){t.set(Wo(e,n))},__wbg_set_6be42768c690e380:function(t,e,n){t[e]=n},__wbg_set_6c60b2e8ad0e9383:function(t,e,n){t[e>>>0]=n},__wbg_set_81b4174352e6a095:function(t,e,n){t.set(e,n>>>0)},__wbg_set_8ee2d34facb8466e:function(){return nl((function(t,e,n){return Reflect.set(t,e,n)}),arguments)},__wbg_set_a98c8da6557e63de:function(t,e,n){t.set(Ho(e,n))},__wbg_set_index_338a66e40fc45dee:function(t,e,n){t[e>>>0]=n>>>0},__wbg_stack_3b0d974bbf31e44f:function(t,e){const n=sl(e.stack,cl.__wbindgen_malloc,cl.__wbindgen_realloc),a=pl;Ko().setInt32(t+4,a,!0),Ko().setInt32(t+0,n,!0)},__wbg_subarray_0f98d3fb634508ad:function(t,e,n){return t.subarray(e>>>0,n>>>0)},__wbg_subarray_517cd0f1811ab872:function(t,e,n){return t.subarray(e>>>0,n>>>0)},__wbg_subarray_d51e89458b3fdbf6:function(t,e,n){return t.subarray(e>>>0,n>>>0)},__wbg_value_7f6052747ccf940f:function(t){return t.value},__wbindgen_cast_0000000000000001:function(t){return t},__wbindgen_cast_0000000000000002:function(t,e){return Ho(t,e)},__wbindgen_cast_0000000000000003:function(t,e){return Wo(t,e)},__wbindgen_cast_0000000000000004:function(t,e){return Yo(t,e)},__wbindgen_cast_0000000000000005:function(t){return BigInt.asUintN(64,t)},__wbindgen_init_externref_table:function(){const t=cl.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)}};return{__proto__:null,"./spark_rs_bg.js":t}}Symbol.dispose&&(Po.prototype[Symbol.dispose]=Po.prototype.free);const Vo="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((t=>cl.__wbg_chunkdecoder_free(t>>>0,1))),Bo="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((t=>cl.__wbg_csplatarray_free(t>>>0,1))),No="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((t=>cl.__wbg_gsplatarray_free(t>>>0,1)));function Oo(t){const e=cl.__externref_table_alloc();return cl.__wbindgen_externrefs.set(e,t),e}function Go(t){const e=typeof t;if("number"==e||"boolean"==e||null==t)return`${t}`;if("string"==e)return`"${t}"`;if("symbol"==e){const e=t.description;return null==e?"Symbol":`Symbol(${e})`}if("function"==e){const e=t.name;return"string"==typeof e&&e.length>0?`Function(${e})`:"Function"}if(Array.isArray(t)){const e=t.length;let n="[";e>0&&(n+=Go(t[0]));for(let a=1;a<e;a++)n+=", "+Go(t[a]);return n+="]",n}const n=/\[object ([^\]]+)\]/.exec(toString.call(t));let a;if(!(n&&n.length>1))return toString.call(t);if(a=n[1],"Object"==a)try{return"Object("+JSON.stringify(t)+")"}catch(s){return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:a}function Ho(t,e){return t>>>=0,function(){null!==Xo&&0!==Xo.byteLength||(Xo=new Float32Array(cl.memory.buffer));return Xo}().subarray(t/4,t/4+e)}function Wo(t,e){return t>>>=0,function(){null!==Zo&&0!==Zo.byteLength||(Zo=new Uint32Array(cl.memory.buffer));return Zo}().subarray(t/4,t/4+e)}function jo(t,e){return t>>>=0,el().subarray(t/1,t/1+e)}let Qo=null;function Ko(){return(null===Qo||!0===Qo.buffer.detached||void 0===Qo.buffer.detached&&Qo.buffer!==cl.memory.buffer)&&(Qo=new DataView(cl.memory.buffer)),Qo}let Xo=null;function Yo(t,e){return function(t,e){ll+=e,ll>=ol&&(il=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),il.decode(),ll=e);return il.decode(el().subarray(t,t+e))}(t>>>=0,e)}let Jo=null;let Zo=null;let tl=null;function el(){return null!==tl&&0!==tl.byteLength||(tl=new Uint8Array(cl.memory.buffer)),tl}function nl(t,e){try{return t.apply(this,e)}catch(sc){const e=Oo(sc);cl.__wbindgen_exn_store(e)}}function al(t){return null==t}function sl(t,e,n){if(void 0===n){const n=ul.encode(t),a=e(n.length,1)>>>0;return el().subarray(a,a+n.length).set(n),pl=n.length,a}let a=t.length,s=e(a,1)>>>0;const r=el();let i=0;for(;i<a;i++){const e=t.charCodeAt(i);if(e>127)break;r[s+i]=e}if(i!==a){0!==i&&(t=t.slice(i)),s=n(s,a,a=i+3*t.length,1)>>>0;const e=el().subarray(s+i,s+a);i+=ul.encodeInto(t,e).written,s=n(s,a,i,1)>>>0}return pl=i,s}function rl(t){const e=cl.__wbindgen_externrefs.get(t);return cl.__externref_table_dealloc(t),e}let il=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});il.decode();const ol=2146435072;let ll=0;const ul=new TextEncoder;"encodeInto"in ul||(ul.encodeInto=function(t,e){const n=ul.encode(t);return e.set(n),{read:t.length,written:n.length}});let cl,pl=0;const dl=("function"==typeof WebAssembly.compileStreaming?WebAssembly.compileStreaming(fetch("undefined"==typeof document?require("url").pathToFileURL(__dirname+"/assets/viewer/spark-a62bdfe36d20.wasm").href:new URL("assets/viewer/spark-a62bdfe36d20.wasm",document.currentScript&&"SCRIPT"===document.currentScript.tagName.toUpperCase()&&document.currentScript.src||document.baseURI).href)):Promise.reject()).catch((()=>fetch("undefined"==typeof document?require("url").pathToFileURL(__dirname+"/assets/viewer/spark-a62bdfe36d20.wasm").href:new URL("assets/viewer/spark-a62bdfe36d20.wasm",document.currentScript&&"SCRIPT"===document.currentScript.tagName.toUpperCase()&&document.currentScript.src||document.baseURI).href).then((t=>t.arrayBuffer())).then((t=>WebAssembly.compile(t)))));let hl=!1;const xl=async function(t){if(void 0!==cl)return cl;void 0!==t&&Object.getPrototypeOf(t)===Object.prototype&&({module_or_path:t}=t);const e=Uo();("string"==typeof t||"function"==typeof Request&&t instanceof Request||"function"==typeof URL&&t instanceof URL)&&(t=fetch(t));const{instance:n,module:a}=await async function(t,e){if("function"==typeof Response&&t instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(t,e)}catch(sc){if(!t.ok||!function(t){switch(t){case"basic":case"cors":case"default":return!0}return!1}(t.type)||"application/wasm"===t.headers.get("Content-Type"))throw sc}const n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}{const n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}}(await t,e);return function(t){return cl=t.exports,Qo=null,Xo=null,Jo=null,Zo=null,tl=null,cl.__wbindgen_start(),cl}(n)}({module_or_path:dl}).then((t=>{hl=!0}));const fl="undefined"==typeof document?require("url").pathToFileURL(__dirname+"/assets/viewer/spark-worker-c1a6c013b888.js").href:new URL("assets/viewer/spark-worker-c1a6c013b888.js",document.currentScript&&"SCRIPT"===document.currentScript.tagName.toUpperCase()&&document.currentScript.src||document.baseURI).href;function ml(t){const e=new URL(fl,globalThis.location.href);return new Worker(e,{name:null==t?void 0:t.name})}const yl=class t{constructor(){this.queue=null,this.messages={},this.worker=new ml,this.worker.onmessage=t=>this.onMessage(t),dl.then((t=>{this.worker.postMessage({name:"init-wasm",module:t})}))}onMessage(t){var e;const{id:n,result:a,error:s,status:r}=t.data,i=this.messages[n];i&&(void 0!==s?(delete this.messages[n],i.reject(s)):void 0!==r?null==(e=i.onStatus)||e.call(i,r):(delete this.messages[n],i.resolve(a)))}tryExclusive(t){return null==this.queue?this.exclusive(t):null}async exclusive(t){const e=this.queue;null!=e?await new Promise((t=>{e.push((()=>t(void 0)))})):this.queue=[];try{return await t(this)}finally{if(null!=this.queue)if(0===this.queue.length)this.queue=null;else{this.queue.shift()()}}}async call(e,n,a={}){const s=++t.currentId,r=new Promise(((t,e)=>{this.messages[s]={resolve:t,reject:e,onStatus:a.onStatus}}));return this.worker.postMessage({id:s,name:e,args:n},{transfer:jn(n)}),await r}dispose(){this.worker.terminate();const t=Object.values(this.messages);this.messages={};for(const e of t)e.reject(new Error("Worker terminate"))}};yl.currentId=0;let gl=yl;const vl=new class{constructor(t=4){this.numWorkers=0,this.freelist=[],this.queue=[],this.maxWorkers=t}async withWorker(t){const e=await this.allocWorker();try{return await t(e)}finally{this.freeWorker(e)}}async allocWorker(){const t=this.freelist.pop();if(t)return t;if(this.numWorkers<this.maxWorkers){const t=new gl;return this.numWorkers+=1,t}return new Promise((t=>{this.queue.push(t)}))}freeWorker(t){if(this.numWorkers>this.maxWorkers)return void(this.numWorkers-=1);const e=this.queue.shift();e?e(t):this.freelist.push(t)}},wl=class e{constructor(e={}){this.maxSplats=0,this.numSplats=0,this.packedArray=null,this.maxSh=3,this.isInitialized=!1,this.target=null,this.source=null,this.needsUpdate=!0,this.extra={},this.dyno=new Sl({packedSplats:this}),this.dynoRgbMinMaxLnScaleMinMax=new ge({key:"rgbMinMaxLnScaleMinMax",value:new t.Vector4(0,1,n,9),update:t=>{var e,a,s,r;return t.set((null==(e=this.splatEncoding)?void 0:e.rgbMin)??0,(null==(a=this.splatEncoding)?void 0:a.rgbMax)??1,(null==(s=this.splatEncoding)?void 0:s.lnScaleMin)??n,(null==(r=this.splatEncoding)?void 0:r.lnScaleMax)??9),t}}),this.dynoNumSh=new re({key:"numSh",value:0,update:()=>Math.min(this.getNumSh(),this.maxSh)}),this.dynoShMax=new xe({key:"shMax",value:new t.Vector3,update:t=>{var e,n,a;return t.set((null==(e=this.splatEncoding)?void 0:e.sh1Max)??1,(null==(n=this.splatEncoding)?void 0:n.sh2Max)??1,(null==(a=this.splatEncoding)?void 0:a.sh3Max)??1),t}}),this.initialized=Promise.resolve(this),this.reinitialize(e)}reinitialize(t){this.isInitialized=!1,this.extra={},this.maxSplats=t.maxSplats??0,this.splatEncoding=t.splatEncoding,this.lod=t.lod,this.nonLod=t.nonLod,t.url||t.fileBytes||t.stream||t.construct?this.initialized=this.asyncInitialize(t).then((()=>(this.isInitialized=!0,this))):(this.initialize(t),this.isInitialized=!0,this.initialized=Promise.resolve(this))}initialize(t){this.extra=t.extra??{},this.splatEncoding=t.splatEncoding??this.splatEncoding,this.lodSplats=t.lodSplats,t.packedArray?(this.packedArray=t.packedArray,this.numSplats=t.numSplats??this.packedArray.length/4,this.maxSplats=Math.floor(this.packedArray.length/4),this.maxSplats=Math.floor(this.maxSplats/i)*i,this.numSplats=Math.min(this.maxSplats,t.numSplats??Number.POSITIVE_INFINITY)):(this.maxSplats=t.maxSplats??0,this.numSplats=0)}async asyncInitialize(t){const{url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,construct:o,lod:l,nonLod:u,lodAbove:c}=t;this.lod=l,this.nonLod=u;const p=new $l;if((n||e||r)&&await p.loadInternalAsync({packedSplats:this,url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,onProgress:t.onProgress,lodAbove:c}),o){const t=o(this);t instanceof Promise&&await t}}dispose(){this.target&&(this.target.dispose(),this.target.texture.source.data=null,this.target=null),this.source&&(this.source.dispose(),this.source.source.data=null,this.source=null),this.packedArray=null;for(const t in this.extra){const e=this.extra[t];if(e instanceof ne){const t=e.value;(null==t?void 0:t.isTexture)&&(t.dispose(),t.source.data=null)}}this.extra={},this.disposeLodSplats()}prepareFetchSplat(){}getNumSplats(){return this.numSplats}hasRgbDir(){return Math.min(this.getNumSh(),this.maxSh)>0}getNumSh(){return this.extra.sh1?this.extra.sh2?this.extra.sh3?3:2:1:0}setMaxSh(t){this.maxSh=t}fetchSplat({index:t,viewOrigin:e}){let n=nt(this.dyno,t);if(this.hasRgbDir()&&e){const a=it(n).outputs.center,s=Qr(ss(a,e)),{sh1Texture:r,sh2Texture:i,sh3Texture:o}=this.ensureShTextures();let{rgb:l}=kl({coord:ct(t),viewDir:s,numSh:this.dynoNumSh,sh1Texture:r,sh2Texture:i,sh3Texture:o,shMax:this.dynoShMax});l=as(l,it(n).outputs.rgb),n=ot({gsplat:n,rgb:l})}return n}ensureShTextures(){if(!this.extra.sh1)return{};let e=this.extra.sh1Texture;if(!e){let n=this.extra.sh1;const{width:a,height:s,depth:r,maxSplats:i}=ea(n.length/2);if(n.length<2*i){const t=new Uint32Array(2*i);t.set(n),this.extra.sh1=t,n=t}const o=new t.DataArrayTexture(n,a,s,r);o.format=t.RGIntegerFormat,o.type=t.UnsignedIntType,o.internalFormat="RG32UI",o.needsUpdate=!0,e=new Pe({value:o,key:"sh1"}),this.extra.sh1Texture=e}if(!this.extra.sh2)return{sh1Texture:e};let n=this.extra.sh2Texture;if(!n){let e=this.extra.sh2;const{width:a,height:s,depth:r,maxSplats:i}=ea(e.length/4);if(e.length<4*i){const t=new Uint32Array(4*i);t.set(e),this.extra.sh2=t,e=t}const o=new t.DataArrayTexture(e,a,s,r);o.format=t.RGBAIntegerFormat,o.type=t.UnsignedIntType,o.internalFormat="RGBA32UI",o.needsUpdate=!0,n=new Pe({value:o,key:"sh2"}),this.extra.sh2Texture=n}if(!this.extra.sh3)return{sh1Texture:e,sh2Texture:n};let a=this.extra.sh3Texture;if(!a){let e=this.extra.sh3;const{width:n,height:s,depth:r,maxSplats:i}=ea(e.length/4);if(e.length<4*i){const t=new Uint32Array(4*i);t.set(e),this.extra.sh3=t,e=t}const o=new t.DataArrayTexture(e,n,s,r);o.format=t.RGBAIntegerFormat,o.type=t.UnsignedIntType,o.internalFormat="RGBA32UI",o.needsUpdate=!0,a=new Pe({value:o,key:"sh3"}),this.extra.sh3Texture=a}return{sh1Texture:e,sh2Texture:n,sh3Texture:a}}ensureSplats(t){const e=t<=this.maxSplats?this.maxSplats:Math.max(t,2*this.maxSplats),n=this.packedArray?this.packedArray.length/4:0;if(!this.packedArray||e>n){this.maxSplats=ea(e).maxSplats;const t=new Uint32Array(4*this.maxSplats);this.packedArray&&t.set(this.packedArray),this.packedArray=t}return this.packedArray}ensureSplatsSh(t,e){let n,a;if(0===t)return this.ensureSplats(e);if(1===t)n=2,a="sh1";else if(2===t)n=4,a="sh2";else{if(3!==t)throw new Error(`Invalid level: ${t}`);n=4,a="sh3"}let s=this.extra[a]?this.extra[a].length/n:0;const r=e<=s?s:Math.max(e,2*s);if(!this.extra[a]||r>s){s=ea(r).maxSplats;const t=new Uint32Array(s*n);this.extra[a]&&t.set(this.extra[a]),this.extra[a]=t}return this.extra[a]}getSplat(t){if(!this.packedArray||t>=this.numSplats)throw new Error("Invalid index");return ta(this.packedArray,t,this.splatEncoding)}setSplat(t,e,n,a,s,r){Yn(this.ensureSplats(t+1),t,e.x,e.y,e.z,n.x,n.y,n.z,a.x,a.y,a.z,a.w,s,r.r,r.g,r.b),this.numSplats=Math.max(this.numSplats,t+1)}pushSplat(t,e,n,a,s){Yn(this.ensureSplats(this.numSplats+1),this.numSplats,t.x,t.y,t.z,e.x,e.y,e.z,n.x,n.y,n.z,n.w,a,s.r,s.g,s.b),++this.numSplats}forEachSplat(t){if(this.packedArray&&this.numSplats)for(let e=0;e<this.numSplats;++e){const n=ta(this.packedArray,e,this.splatEncoding);t(e,n.center,n.scales,n.quaternion,n.opacity,n.color)}}ensureGenerate(e){if(this.target&&(e??1)<=this.maxSplats)return!1;this.target&&this.target.dispose();const n=ea(e??1),{width:a,height:s,depth:r}=n;return this.maxSplats=n.maxSplats,this.target=new t.WebGLArrayRenderTarget(a,s,r,{depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1,magFilter:t.NearestFilter,minFilter:t.NearestFilter}),this.target.texture.format=t.RGBAIntegerFormat,this.target.texture.type=t.UnsignedIntType,this.target.texture.internalFormat="RGBA32UI",this.target.scissorTest=!0,!0}generateMapping(t){let e=0;const n=t.map((t=>{const n=e,a=Math.ceil(t/i)*i;return e+=a,{base:n,count:t}}));return{maxSplats:e,mapping:n}}getTexture(){if(this.target)return this.target.texture;if(this.source||this.packedArray){return this.maybeUpdateSource()}return e.getEmptyArray}maybeUpdateSource(){if(!this.packedArray)throw new Error("No packed splats");if(this.needsUpdate||!this.source){if(this.needsUpdate=!1,this.source){const{width:t,height:e,depth:n}=this.source.image;this.maxSplats!==t*e*n&&(this.source.dispose(),this.source=null)}if(this.source)this.packedArray.buffer!==this.source.image.data.buffer&&(this.source.image.data=new Uint8Array(this.packedArray.buffer));else{const{width:e,height:n,depth:a}=ea(this.maxSplats);this.source=new t.DataArrayTexture(this.packedArray,e,n,a),this.source.format=t.RGBAIntegerFormat,this.source.type=t.UnsignedIntType,this.source.internalFormat="RGBA32UI",this.source.needsUpdate=!0}this.source.needsUpdate=!0}return this.source}prepareProgramMaterial(t){let n=e.generatorProgram.get(t);if(!n){const a=O({index:"int"},{},(({index:e},n,{roots:a})=>{t.inputs.index=e;const s=t.outputs.gsplat,r=Bt(s,this.dynoRgbMinMaxLnScaleMinMax);a.push(r)}));e.programTemplate||(e.programTemplate=new Ma(xo().computeUvec4Template)),n=new _a({graph:a,inputs:{index:"_index"},outputs:{output:"target"},template:e.programTemplate}),Object.assign(n.uniforms,{targetLayer:{value:0},targetBase:{value:0},targetCount:{value:0}}),e.generatorProgram.set(t,n)}const a=n.prepareMaterial();return e.fullScreenQuad.material=a,{program:n,material:a}}saveRenderState(t){return{target:t.getRenderTarget(),xrEnabled:t.xr.enabled,autoClear:t.autoClear}}resetRenderState(t,e){t.setRenderTarget(e.target),t.xr.enabled=e.xrEnabled,t.autoClear=e.autoClear}generate({generator:t,base:n,count:a,renderer:s}){if(!this.target)throw new Error("Target must be initialized with ensureSplats");if(n+a>this.maxSplats)throw new Error("Base + count exceeds maxSplats");const{program:r,material:l}=this.prepareProgramMaterial(t);r.update();const u=this.saveRenderState(s),c=Math.ceil((n+a)/i)*i,p=4194304;for(l.uniforms.targetBase.value=n,l.uniforms.targetCount.value=a;n<c;){const t=Math.floor(n/p);l.uniforms.targetLayer.value=t;const a=t*p,r=Math.floor((n-a)/i),u=Math.min(o,Math.ceil((c-a)/i));this.target.scissor.set(0,r,i,u-r),s.setRenderTarget(this.target,t),s.xr.enabled=!1,s.autoClear=!1,e.fullScreenQuad.render(s),n+=i*(u-r)}return this.resetRenderState(s,u),{nextBase:c}}disposeLodSplats(){this.lodSplats&&(this.lodSplats.dispose(),this.lodSplats=void 0)}async createLodSplats({rgbaArray:t,quality:n}={}){const a="number"==typeof this.lod?Math.max(1.1,Math.min(2,this.lod)):n?1.75:1.5,s=this.packedArray.slice(),r=t?(await t.getArray()).slice():void 0,i={sh1:this.extra.sh1?this.extra.sh1.slice():void 0,sh2:this.extra.sh2?this.extra.sh2.slice():void 0,sh3:this.extra.sh3?this.extra.sh3.slice():void 0},o=await vl.withWorker((async t=>await t.call(n?"qualityLodPackedSplats":"tinyLodPackedSplats",{numSplats:this.numSplats,packedArray:s,extra:i,lodBase:a,rgba:r,encoding:this.splatEncoding??u}))),l=new e(o);this.lodSplats&&this.lodSplats.dispose(),this.lodSplats=l,this.nonLod=!0,this.lod=!n||"quality"}extractSplats(t,n){const a=ea(t.length).maxSplats,s=new e({maxSplats:a});for(let e=0;e<t.length;e++){const a=this.getSplat(t[e]);if(n){let n=.61803398875*(t[e]>>>16);n-=Math.floor(n);const s=Math.max(0,Math.min(1,Math.abs(6*n-3)-1)),r=Math.max(0,Math.min(1,Math.abs(6*n+1)-1)),i=Math.max(0,Math.min(1,Math.abs(6*n-1)-1));a.color.r*=s,a.color.g*=r,a.color.b*=i}s.pushSplat(a.center,a.scales,a.quaternion,a.opacity,a.color)}return s}};wl.getEmptyArray=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})(),wl.programTemplate=null,wl.generatorProgram=new WeakMap,wl.fullScreenQuad=new e.FullScreenQuad(new t.RawShaderMaterial({visible:!1})),wl.emptyUint32x4=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})(),wl.emptyUint32x2=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(2*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RG32UI",i.needsUpdate=!0,i})();let bl=wl;class Sl extends ne{constructor({packedSplats:e}={}){super({key:"packedSplats",type:Z,globals:()=>[xt],value:{textureArray:bl.getEmptyArray,numSplats:0,rgbMinMaxLnScaleMinMax:new t.Vector4(0,1,n,9),lodOpacity:!1},update:t=>{var e,a,s,r,i,o,l,u,c,p,d,h;return t.textureArray=(null==(e=this.packedSplats)?void 0:e.getTexture())??bl.getEmptyArray,t.numSplats=(null==(a=this.packedSplats)?void 0:a.numSplats)??0,t.rgbMinMaxLnScaleMinMax.set((null==(r=null==(s=this.packedSplats)?void 0:s.splatEncoding)?void 0:r.rgbMin)??0,(null==(o=null==(i=this.packedSplats)?void 0:i.splatEncoding)?void 0:o.rgbMax)??1,(null==(u=null==(l=this.packedSplats)?void 0:l.splatEncoding)?void 0:u.lnScaleMin)??n,(null==(p=null==(c=this.packedSplats)?void 0:c.splatEncoding)?void 0:p.lnScaleMax)??9),t.lodOpacity=(null==(h=null==(d=this.packedSplats)?void 0:d.splatEncoding)?void 0:h.lodOpacity)??!1,t}}),this.packedSplats=e}}const Tl=j("\n vec3 evaluatePackedSH1(uvec2 packedData, vec3 viewDir, float sh1Max) {\n // Extract sint7 values packed into 2 x uint32\n vec3 sh1_0 = vec3(ivec3(\n int(packedData.x << 25u) >> 25,\n int(packedData.x << 18u) >> 25,\n int(packedData.x << 11u) >> 25\n ));\n vec3 sh1_1 = vec3(ivec3(\n int(packedData.x << 4u) >> 25,\n int((packedData.x >> 3u) | (packedData.y << 29u)) >> 25,\n int(packedData.y << 22u) >> 25\n ));\n vec3 sh1_2 = vec3(ivec3(\n int(packedData.y << 15u) >> 25,\n int(packedData.y << 8u) >> 25,\n int(packedData.y << 1u) >> 25\n ));\n\n vec3 rgb = sh1_0 * (-0.4886025 * viewDir.y)\n + sh1_1 * (0.4886025 * viewDir.z)\n + sh1_2 * (-0.4886025 * viewDir.x);\n return rgb * (sh1Max / 63.0);\n }\n"),_l=j("\n vec3 evaluatePackedSH2(uvec4 packedData, vec3 viewDir, float sh2Max) {\n // Extract sint8 values packed into 4 x uint32\n vec3 sh2_0 = vec3(ivec3(\n int(packedData.x << 24u) >> 24,\n int(packedData.x << 16u) >> 24,\n int(packedData.x << 8u) >> 24\n ));\n vec3 sh2_1 = vec3(ivec3(\n int(packedData.x) >> 24,\n int(packedData.y << 24u) >> 24,\n int(packedData.y << 16u) >> 24\n ));\n vec3 sh2_2 = vec3(ivec3(\n int(packedData.y << 8u) >> 24,\n int(packedData.y) >> 24,\n int(packedData.z << 24u) >> 24\n ));\n vec3 sh2_3 = vec3(ivec3(\n int(packedData.z << 16u) >> 24,\n int(packedData.z << 8u) >> 24,\n int(packedData.z) >> 24\n ));\n vec3 sh2_4 = vec3(ivec3(\n int(packedData.w << 24u) >> 24,\n int(packedData.w << 16u) >> 24,\n int(packedData.w << 8u) >> 24\n ));\n\n vec3 rgb = sh2_0 * (1.0925484 * viewDir.x * viewDir.y)\n + sh2_1 * (-1.0925484 * viewDir.y * viewDir.z)\n + sh2_2 * (0.3153915 * (2.0 * viewDir.z * viewDir.z - viewDir.x * viewDir.x - viewDir.y * viewDir.y))\n + sh2_3 * (-1.0925484 * viewDir.x * viewDir.z)\n + sh2_4 * (0.5462742 * (viewDir.x * viewDir.x - viewDir.y * viewDir.y));\n return rgb * (sh2Max / 127.0);\n }\n"),Ml=j("\n vec3 evaluatePackedSH3(uvec4 packedData, vec3 viewDir, float sh3Max) {\n // Extract sint6 values packed into 4 x uint32\n vec3 sh3_0 = vec3(ivec3(\n int(packedData.x << 26u) >> 26,\n int(packedData.x << 20u) >> 26,\n int(packedData.x << 14u) >> 26\n ));\n vec3 sh3_1 = vec3(ivec3(\n int(packedData.x << 8u) >> 26,\n int(packedData.x << 2u) >> 26,\n int((packedData.x >> 4u) | (packedData.y << 28u)) >> 26\n ));\n vec3 sh3_2 = vec3(ivec3(\n int(packedData.y << 22u) >> 26,\n int(packedData.y << 16u) >> 26,\n int(packedData.y << 10u) >> 26\n ));\n vec3 sh3_3 = vec3(ivec3(\n int(packedData.y << 4u) >> 26,\n int((packedData.y >> 2u) | (packedData.z << 30u)) >> 26,\n int(packedData.z << 24u) >> 26\n ));\n vec3 sh3_4 = vec3(ivec3(\n int(packedData.z << 18u) >> 26,\n int(packedData.z << 12u) >> 26,\n int(packedData.z << 6u) >> 26\n ));\n vec3 sh3_5 = vec3(ivec3(\n int(packedData.z) >> 26,\n int(packedData.w << 26u) >> 26,\n int(packedData.w << 20u) >> 26\n ));\n vec3 sh3_6 = vec3(ivec3(\n int(packedData.w << 14u) >> 26,\n int(packedData.w << 8u) >> 26,\n int(packedData.w << 2u) >> 26\n ));\n\n float xx = viewDir.x * viewDir.x;\n float yy = viewDir.y * viewDir.y;\n float zz = viewDir.z * viewDir.z;\n float xy = viewDir.x * viewDir.y;\n float yz = viewDir.y * viewDir.z;\n float zx = viewDir.z * viewDir.x;\n\n vec3 rgb = sh3_0 * (-0.5900436 * viewDir.y * (3.0 * xx - yy))\n + sh3_1 * (2.8906114 * xy * viewDir.z) +\n + sh3_2 * (-0.4570458 * viewDir.y * (4.0 * zz - xx - yy))\n + sh3_3 * (0.3731763 * viewDir.z * (2.0 * zz - 3.0 * xx - 3.0 * yy))\n + sh3_4 * (-0.4570458 * viewDir.x * (4.0 * zz - xx - yy))\n + sh3_5 * (1.4453057 * viewDir.z * (xx - yy))\n + sh3_6 * (-0.5900436 * viewDir.x * (xx - 3.0 * yy));\n return rgb * (sh3Max / 31.0);\n }\n");function kl({coord:t,viewDir:e,numSh:n,sh1Texture:a,sh2Texture:s,sh3Texture:r,shMax:i}){return new B({inTypes:{coord:"ivec3",viewDir:"vec3",numSh:"int",sh1Texture:"usampler2DArray",sh2Texture:"usampler2DArray",sh3Texture:"usampler2DArray",shMax:"vec3"},outTypes:{rgb:"vec3"},inputs:{coord:t,viewDir:e,numSh:n,sh1Texture:a,sh2Texture:s,sh3Texture:r,shMax:i},globals:()=>[Tl,_l,Ml],statements:({inputs:t,outputs:e})=>{const n=["vec3 rgb = vec3(0.0);"];return t.sh1Texture&&(n.push(...W(`\n if (${t.numSh} >= 1) {\n vec3 sh1Rgb = evaluatePackedSH1(texelFetch(${t.sh1Texture}, ${t.coord}, 0).rg, ${t.viewDir}, ${t.shMax}.x);\n rgb += sh1Rgb;\n `)),t.sh2Texture&&(n.push(...W(`\n if (${t.numSh} >= 2) {\n vec3 sh2Rgb = evaluatePackedSH2(texelFetch(${t.sh2Texture}, ${t.coord}, 0), ${t.viewDir}, ${t.shMax}.y);\n rgb += sh2Rgb;\n `)),t.sh3Texture&&n.push(...W(`\n if (${t.numSh} >= 3) {\n vec3 sh3Rgb = evaluatePackedSH3(texelFetch(${t.sh3Texture}, ${t.coord}, 0), ${t.viewDir}, ${t.shMax}.z);\n rgb += sh3Rgb;\n }\n `)),n.push("}")),n.push("}")),n.push(`${e.rgb} = rgb;`),n}}).outputs}class $l extends t.Loader{constructor(e){super(e),this.fileLoader=new t.FileLoader(e)}load(t,e,n,a){return this.loadInternal({url:t,onLoad:e,onProgress:n,onError:a})}async loadAsync(t,e){return new Promise(((n,a)=>{this.load(t,(t=>{n(t)}),e,a)}))}parse(t){return new Yl({packedSplats:t})}loadInternal({packedSplats:t,extSplats:e,url:n,fileBytes:a,fileType:s,fileName:r,stream:i,streamLength:o,onLoad:l,onProgress:u,onError:c,lod:p,nonLod:d,lodAbove:h,lodBase:x}){a instanceof ArrayBuffer&&(a=new Uint8Array(a));const f=a?void 0:this.manager.resolveURL((this.path??"")+(n??""));let m=null==i?void 0:i.getReader();this.manager.itemStart(f??""),vl.withWorker((async n=>{const c=(null==t?void 0:t.lod)??(null==e?void 0:e.lod);c&&(p=c);const y=(null==t?void 0:t.nonLod)??(null==e?void 0:e.nonLod);void 0!==y&&(d=y);const g=f?new URL(f,window.location.href).toString():void 0,v=await n.call(e?"loadExtSplats":"loadPackedSplats",{url:g,requestHeader:this.requestHeader,withCredentials:this.withCredentials,fileBytes:null==a?void 0:a.slice(),fileType:s,pathName:f||r,chunked:void 0!==i,chunkedLength:o,encoding:null==t?void 0:t.splatEncoding,lod:p,lodBase:x,nonLod:d,lodAbove:h},{onStatus:async t=>{const{loaded:e,total:a}=t;if(void 0!==e&&u&&u(new ProgressEvent("progress",{lengthComputable:0!==a,loaded:e,total:a})),t.nextChunk){let t;if(m){const{done:e,value:n}=await m.read();e?(m.releaseLock(),m=void 0,t=new Uint8Array(0)):t=n}else t=new Uint8Array(0);n.call("nextChunk",{chunk:t})}}}),w=v;let b;"lodSplats"in v&&(w.lodSplats=e?new El({...v.lodSplats}):new bl({...v.lodSplats,maxSplats:null==t?void 0:t.maxSplats})),e?(b=e,e.initialize(w)):(b=t??new bl,b.initialize(w)),null==l||l(b)})).catch((t=>{this.manager.itemError(f??""),null==c||c(t)})).finally((()=>{this.manager.itemEnd(f??"")}))}async loadInternalAsync({packedSplats:t,extSplats:e,url:n,fileBytes:a,fileType:s,fileName:r,stream:i,streamLength:o,onProgress:l,lod:u,nonLod:c,lodAbove:p,lodBase:d}){return new Promise(((h,x)=>{this.loadInternal({packedSplats:t,extSplats:e,url:n,fileBytes:a,fileType:s,fileName:r,stream:i,streamLength:o,onLoad:h,onProgress:l,onError:x,lod:u,nonLod:c,lodAbove:p,lodBase:d})}))}}function Dl(t){const e=new DataView(t.buffer).getUint32(0,!0);if(7957616==(16777215&e))return l.PLY;if(559903==(16777215&e)){const e=ba(t,4);return 1347635022===new DataView(e.buffer).getUint32(0,!0)?l.SPZ:void 0}return 67324752===e?function(t){try{const e=t instanceof ArrayBuffer?new Uint8Array(t):t;let n=null;const a=function(t,e){for(var n={},a=t.length-22;101010256!=Sn(t,a);--a)(!a||t.length-a>65558)&&gn(13);var s=bn(t,a+8);if(!s)return{};var r=Sn(t,a+16),i=4294967295==r||65535==s;if(i){var o=Sn(t,a-12);(i=101075792==Sn(t,o))&&(s=Sn(t,o+32),r=Sn(t,o+48))}for(var l=e&&e.filter,u=0;u<s;++u){var c=In(t,r,i),p=c[0],d=c[1],h=c[2],x=c[3],f=c[4],m=c[5],y=zn(t,m);r=f,l&&!l({name:x,size:d,originalSize:h,compression:p})||(p?8==p?n[x]=Mn(t.subarray(y,y+d),{out:new We(h)}):gn(14,"unknown compression type "+p):n[x]=mn(t,y,y+d))}return n}(e,{filter:({name:t})=>"meta.json"===t.split(/[\\/]/).pop()&&(n=t,!0)});if(!n)return;const s=function(t){try{let e;if("string"==typeof t)e=t;else{const n=t instanceof ArrayBuffer?new Uint8Array(t):t;if(n.length>65536)return;e=(new TextDecoder).decode(n)}const n=JSON.parse(e);if(!n||"object"!=typeof n||Array.isArray(n))return;const a=2===n.version;for(const t of["means","scales","quats","sh0"]){if(!n[t]||"object"!=typeof n[t]||Array.isArray(n[t]))return;if(a){if(!n[t].files)return;if(("scales"===t||"sh0"===t)&&!n[t].codebook)return;if(!("means"!==t||n[t].mins&&n[t].maxs))return}else{if(!n[t].shape||!n[t].files)return;if(!("quats"===t||n[t].mins&&n[t].maxs))return}}return n}catch{return}}(a[n]);if(!s)return;return{name:n,json:s}}catch{return}}(t)?l.PCSOGSZIP:void 0:809779538===e?l.RAD:void 0}function zl(t){const e=function(t){const e=t.split(/[?#]/,1)[0],n=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\")),a=e.slice(n+1),s=a.lastIndexOf(".");return s<=0||s===a.length-1?"":a.slice(s+1).toLowerCase()}(t);return"ply"===e?l.PLY:"spz"===e?l.SPZ:"splat"===e?l.SPLAT:"ksplat"===e?l.KSPLAT:"sog"===e?l.PCSOGSZIP:"rad"===e?l.RAD:void 0}const Il=class e{constructor(t={}){this.maxSplats=0,this.numSplats=0,this.extra={},this.maxSh=3,this.isInitialized=!1,this.extArrays=[new Uint32Array(0),new Uint32Array(0)],this.textures=[e.emptyTexture,e.emptyTexture],this.extra={},this.dyno=new Al({extSplats:this}),this.dynoNumSh=new re({key:"numSh",value:0,update:()=>Math.min(this.getNumSh(),this.maxSh)}),this.initialized=Promise.resolve(this),this.reinitialize(t)}reinitialize(t){this.isInitialized=!1,this.extra={},this.maxSplats=t.maxSplats??0,this.lod=t.lod,this.nonLod=t.nonLod,t.url||t.fileBytes||t.stream||t.construct?this.initialized=this.asyncInitialize(t).then((()=>(this.isInitialized=!0,this))):(this.initialize(t),this.isInitialized=!0,this.initialized=Promise.resolve(this))}initialize(t){this.extra=t.extra??{},this.lodSplats=t.lodSplats,t.extArrays?(this.extArrays=t.extArrays,this.maxSplats=Math.floor(Math.min(this.extArrays[0].length/4,this.extArrays[1].length/4)),this.numSplats=t.numSplats??this.maxSplats,this.maxSplats=Math.floor(this.maxSplats/i)*i,this.numSplats=Math.min(this.maxSplats,t.numSplats??Number.POSITIVE_INFINITY),this.updateTextures()):(this.maxSplats=t.maxSplats??0,this.numSplats=0,this.extArrays=[new Uint32Array(0),new Uint32Array(0)])}async asyncInitialize(t){const{url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,construct:o,lod:l,nonLod:u,lodAbove:c}=t;this.lod=l,this.nonLod=u;const p=new $l;if((n||e||r)&&await p.loadInternalAsync({extSplats:this,url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,onProgress:t.onProgress,lodAbove:c}),o){const t=o(this);t instanceof Promise&&await t}}dispose(){this.textures[0]!==e.emptyTexture&&(this.textures[0].dispose(),this.textures[0].source.data=null,this.textures[0]=e.emptyTexture),this.textures[1]!==e.emptyTexture&&(this.textures[1].dispose(),this.textures[1].source.data=null,this.textures[1]=e.emptyTexture),this.extArrays=[new Uint32Array(0),new Uint32Array(0)];for(const t in this.extra){const e=this.extra[t];if(e instanceof ne){const t=e.value;(null==t?void 0:t.isTexture)&&(t.dispose(),t.source.data=null)}}this.extra={},this.disposeLodSplats()}prepareFetchSplat(){}getNumSplats(){return this.numSplats}hasRgbDir(){return Math.min(this.getNumSh(),this.maxSh)>0}getNumSh(){return this.extra.sh1?this.extra.sh2?this.extra.sh3a&&this.extra.sh3b?3:2:1:0}setMaxSh(t){this.maxSh=t}fetchSplat({index:t,viewOrigin:e}){let n=st(this.dyno,t);if(this.hasRgbDir()&&e){const a=it(n).outputs.center,s=Qr(ss(a,e)),{sh1Texture:r,sh2Texture:i,sh3TextureA:o,sh3TextureB:l}=this.ensureShTextures();let{rgb:u}=Ll({coord:ct(t),viewDir:s,numSh:this.dynoNumSh,sh1Texture:r,sh2Texture:i,sh3TextureA:o,sh3TextureB:l});u=as(u,it(n).outputs.rgb),n=ot({gsplat:n,rgb:u})}return n}ensureShTextures(){if(!this.extra.sh1)return{};let e=this.extra.sh1Texture;if(!e){let n=this.extra.sh1;const{width:a,height:s,depth:r,maxSplats:i}=ea(n.length/4);if(n.length<4*i){const t=new Uint32Array(4*i);t.set(n),this.extra.sh1=t,n=t}const o=Rl(n,a,s,r,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI");e=new Pe({value:o,key:"sh1"}),this.extra.sh1Texture=e}if(!this.extra.sh2)return{sh1Texture:e};let n=this.extra.sh2Texture;if(!n){let e=this.extra.sh2;const{width:a,height:s,depth:r,maxSplats:i}=ea(e.length/4);if(e.length<4*i){const t=new Uint32Array(4*i);t.set(e),this.extra.sh2=t,e=t}const o=Rl(e,a,s,r,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI");n=new Pe({value:o,key:"sh2"}),this.extra.sh2Texture=n}if(!this.extra.sh3a||!this.extra.sh3b)return{sh1Texture:e,sh2Texture:n};let a=this.extra.sh3TextureA;if(!a){let e=this.extra.sh3a;const{width:n,height:s,depth:r,maxSplats:i}=ea(e.length/4);if(e.length<4*i){const t=new Uint32Array(4*i);t.set(e),this.extra.sh3a=t,e=t}const o=Rl(e,n,s,r,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI");a=new Pe({value:o,key:"sh3"}),this.extra.sh3TextureA=a}let s=this.extra.sh3TextureB;if(!s){let e=this.extra.sh3b;const{width:n,height:a,depth:r,maxSplats:i}=ea(e.length/4);if(e.length<4*i){const t=new Uint32Array(4*i);t.set(e),this.extra.sh3b=t,e=t}const o=Rl(e,n,a,r,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI");s=new Pe({value:o,key:"sh3b"}),this.extra.sh3TextureB=s}return{sh1Texture:e,sh2Texture:n,sh3TextureA:a,sh3TextureB:s}}ensureSplats(t){const e=t<=this.maxSplats?this.maxSplats:Math.max(t,2*this.maxSplats),n=this.extArrays[0]?this.extArrays[0].length/4:0;if(!this.extArrays[0]||e>n){this.maxSplats=ea(e).maxSplats;const t=new Uint32Array(4*this.maxSplats),n=new Uint32Array(4*this.maxSplats);this.extArrays[0]&&(t.set(this.extArrays[0]),n.set(this.extArrays[1])),this.extArrays[0]=t,this.extArrays[1]=n}return this.extArrays}getSplat(t){if(t>=this.numSplats)throw new Error("Invalid index");return Xn(this.extArrays,t)}setSplat(t,e,n,a,s,r){Kn(this.ensureSplats(t+1),t,e.x,e.y,e.z,n.x,n.y,n.z,a.x,a.y,a.z,a.w,s,r.r,r.g,r.b),this.numSplats=Math.max(this.numSplats,t+1)}pushSplat(t,e,n,a,s){Kn(this.ensureSplats(this.numSplats+1),this.numSplats,t.x,t.y,t.z,e.x,e.y,e.z,n.x,n.y,n.z,n.w,a,s.r,s.g,s.b),++this.numSplats}forEachSplat(t){if(this.numSplats)for(let e=0;e<this.numSplats;++e){const n=Xn(this.extArrays,e);t(e,n.center,n.scales,n.quaternion,n.opacity,n.color)}}updateTextures(){if(this.textures[0]!==e.emptyTexture){const{width:t,height:n,depth:a}=this.textures[0].image;this.maxSplats!==t*n*a&&(this.textures[0].dispose(),this.textures[0]=e.emptyTexture,this.textures[1].dispose(),this.textures[1]=e.emptyTexture)}if(this.textures[0]===e.emptyTexture){const{width:e,height:n,depth:a}=ea(this.maxSplats);this.textures[0]=Rl(this.extArrays[0],e,n,a,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI"),this.textures[1]=Rl(this.extArrays[1],e,n,a,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI")}else this.extArrays[0].buffer!==this.textures[0].image.data.buffer&&(this.textures[0].image.data=new Uint8Array(this.extArrays[0].buffer),this.textures[1].image.data=new Uint8Array(this.extArrays[1].buffer),this.textures[0].needsUpdate=!0,this.textures[1].needsUpdate=!0)}extractSplats(t,n){const a=ea(t.length).maxSplats,s=new e({maxSplats:a});for(let e=0;e<t.length;e++){const a=this.getSplat(t[e]);if(n){let n=.61803398875*(t[e]>>>16);n-=Math.floor(n);const s=Math.max(0,Math.min(1,Math.abs(6*n-3)-1)),r=Math.max(0,Math.min(1,Math.abs(6*n+1)-1)),i=Math.max(0,Math.min(1,Math.abs(6*n-1)-1));a.color.r*=s,a.color.g*=r,a.color.b*=i}s.pushSplat(a.center,a.scales,a.quaternion,a.opacity,a.color)}return s}disposeLodSplats(){this.lodSplats&&(this.lodSplats.dispose(),this.lodSplats=void 0)}async createLodSplats({rgbaArray:t,quality:n}={}){const a="number"==typeof this.lod?Math.max(1.1,Math.min(2,this.lod)):n?1.75:1.5,s=[this.extArrays[0].slice(),this.extArrays[1].slice()],r=t?(await t.getArray()).slice():void 0,i={sh1:this.extra.sh1?this.extra.sh1.slice():void 0,sh2:this.extra.sh2?this.extra.sh2.slice():void 0,sh3:this.extra.sh3?this.extra.sh3.slice():void 0},o=await vl.withWorker((async t=>await t.call(n?"qualityLodExtSplats":"tinyLodExtSplats",{numSplats:this.numSplats,extArrays:s,extra:i,lodBase:a,rgba:r}))),l=new e(o);this.lodSplats&&this.lodSplats.dispose(),this.lodSplats=l,this.nonLod=!0,this.lod=!n||"quality"}};Il.emptyArray=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})(),Il.emptyTexture=Rl(null,1,1,1,t.RGBAIntegerFormat,t.UnsignedIntType,"RGBA32UI"),Il.emptyUint32x4=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})();let El=Il;class Al extends ne{constructor({extSplats:t}={}){super({key:"extSplats",type:tt,globals:()=>[vt],value:{textureArray1:El.emptyTexture,textureArray2:El.emptyTexture,numSplats:0},update:t=>{var e,n,a;return t.textureArray1=(null==(e=this.extSplats)?void 0:e.textures[0])??El.emptyTexture,t.textureArray2=(null==(n=this.extSplats)?void 0:n.textures[1])??El.emptyTexture,t.numSplats=(null==(a=this.extSplats)?void 0:a.numSplats)??0,t}}),this.extSplats=t}}const Fl=j("\n vec3 evaluateExtSH1(uvec4 packedData, vec3 viewDir) {\n vec3 sh1_0 = decodeExtRgb(packedData.x);\n vec3 sh1_1 = decodeExtRgb(packedData.y);\n vec3 sh1_2 = decodeExtRgb(packedData.z);\n\n return sh1_0 * (-0.4886025 * viewDir.y)\n + sh1_1 * (0.4886025 * viewDir.z)\n + sh1_2 * (-0.4886025 * viewDir.x);\n }\n"),Pl=j("\n vec3 evaluateExtSH12(uvec4 packed1, uvec4 packed2, vec3 viewDir) {\n vec3 sh1_0 = decodeExtRgb(packed1.x);\n vec3 sh1_1 = decodeExtRgb(packed1.y);\n vec3 sh1_2 = decodeExtRgb(packed1.z);\n\n vec3 sh2_0 = decodeExtRgb(packed1.w);\n vec3 sh2_1 = decodeExtRgb(packed2.x);\n vec3 sh2_2 = decodeExtRgb(packed2.y);\n vec3 sh2_3 = decodeExtRgb(packed2.z);\n vec3 sh2_4 = decodeExtRgb(packed2.w);\n\n vec3 sh1Rgb = sh1_0 * (-0.4886025 * viewDir.y)\n + sh1_1 * (0.4886025 * viewDir.z)\n + sh1_2 * (-0.4886025 * viewDir.x);\n\n vec3 sh2Rgb = sh2_0 * (1.0925484 * viewDir.x * viewDir.y)\n + sh2_1 * (-1.0925484 * viewDir.y * viewDir.z)\n + sh2_2 * (0.3153915 * (2.0 * viewDir.z * viewDir.z - viewDir.x * viewDir.x - viewDir.y * viewDir.y))\n + sh2_3 * (-1.0925484 * viewDir.x * viewDir.z)\n + sh2_4 * (0.5462742 * (viewDir.x * viewDir.x - viewDir.y * viewDir.y));\n\n return sh1Rgb + sh2Rgb;\n }\n"),Cl=j("\n vec3 evaluateExtSH3(uvec4 packedA, uvec4 packedB, vec3 viewDir) {\n vec3 sh3_0 = decodeExtRgb(packedA.x);\n vec3 sh3_1 = decodeExtRgb(packedA.y);\n vec3 sh3_2 = decodeExtRgb(packedA.z);\n vec3 sh3_3 = decodeExtRgb(packedA.w);\n vec3 sh3_4 = decodeExtRgb(packedB.x);\n vec3 sh3_5 = decodeExtRgb(packedB.y);\n vec3 sh3_6 = decodeExtRgb(packedB.z);\n\n float xx = viewDir.x * viewDir.x;\n float yy = viewDir.y * viewDir.y;\n float zz = viewDir.z * viewDir.z;\n float xy = viewDir.x * viewDir.y;\n float yz = viewDir.y * viewDir.z;\n float zx = viewDir.z * viewDir.x;\n\n return sh3_0 * (-0.5900436 * viewDir.y * (3.0 * xx - yy))\n + sh3_1 * (2.8906114 * xy * viewDir.z) +\n + sh3_2 * (-0.4570458 * viewDir.y * (4.0 * zz - xx - yy))\n + sh3_3 * (0.3731763 * viewDir.z * (2.0 * zz - 3.0 * xx - 3.0 * yy))\n + sh3_4 * (-0.4570458 * viewDir.x * (4.0 * zz - xx - yy))\n + sh3_5 * (1.4453057 * viewDir.z * (xx - yy))\n + sh3_6 * (-0.5900436 * viewDir.x * (xx - 3.0 * yy));\n }\n");function Ll({coord:t,viewDir:e,numSh:n,sh1Texture:a,sh2Texture:s,sh3TextureA:r,sh3TextureB:i}){return new B({inTypes:{coord:"ivec3",viewDir:"vec3",numSh:"int",sh1Texture:"usampler2DArray",sh2Texture:"usampler2DArray",sh3TextureA:"usampler2DArray",sh3TextureB:"usampler2DArray"},outTypes:{rgb:"vec3"},inputs:{coord:t,viewDir:e,numSh:n,sh1Texture:a,sh2Texture:s,sh3TextureA:r,sh3TextureB:i},globals:()=>[Fl,Pl,Cl],statements:({inputs:t,outputs:e})=>{const n=["vec3 rgb = vec3(0.0);"];return t.sh1Texture&&(t.sh2Texture?(n.push(...W(`\n if (${t.numSh} == 1) {\n rgb = evaluateExtSH1(texelFetch(${t.sh1Texture}, ${t.coord}, 0), ${t.viewDir});\n } else if (${t.numSh} >= 2) {\n rgb = evaluateExtSH12(texelFetch(${t.sh1Texture}, ${t.coord}, 0), texelFetch(${t.sh2Texture}, ${t.coord}, 0), ${t.viewDir});\n `)),t.sh3TextureA&&t.sh3TextureB&&n.push(...W(`\n if (${t.numSh} >= 3) {\n rgb += evaluateExtSH3(texelFetch(${t.sh3TextureA}, ${t.coord}, 0), texelFetch(${t.sh3TextureB}, ${t.coord}, 0), ${t.viewDir});\n }\n `)),n.push("}")):n.push(...W(`\n if (${t.numSh} >= 1) {\n rgb = evaluateExtSH1(texelFetch(${t.sh1Texture}, ${t.coord}, 0), ${t.viewDir});\n }\n `))),n.push(`${e.rgb} = rgb;`),n}}).outputs}function Rl(e,n,a,s,r,i,o){const l=new t.DataArrayTexture(e,n,a,s);return l.format=r,l.type=i,l.internalFormat=o,l.needsUpdate=!0,l}const ql=class e{constructor(t={}){if(this.capacity=0,this.count=0,this.array=null,this.readback=null,this.source=null,this.needsUpdate=!0,this.dyno=new ne({key:"rgbaArray",type:Vl,globals:()=>[Bl],value:{texture:e.getEmpty(),count:0},update:t=>(t.texture=this.getTexture(),t.count=this.count,t)}),t.array){this.array=t.array;const e=Math.floor(this.array.length/4);this.capacity=Math.ceil(e/i)*i,this.capacity>e&&(this.array=new Uint8Array(4*this.capacity),this.array.set(t.array)),this.count=Math.min(e,t.count??Number.POSITIVE_INFINITY)}else this.capacity=t.capacity??0,this.count=0}dispose(){this.readback&&(this.readback.dispose(),this.readback=null),this.source&&(this.source.dispose(),this.source=null)}ensureCapacity(t){var e;if(!this.array||t>((null==(e=this.array)?void 0:e.length)??0)/4){this.capacity=ea(t).maxSplats;const e=new Uint8Array(4*this.capacity);this.array&&e.set(this.array),this.array=e}return this.array}getTexture(){var t;let n=null==(t=this.readback)?void 0:t.getTexture();return(this.source||this.array)&&(n=this.maybeUpdateSource()),n??e.getEmpty()}maybeUpdateSource(){if(!this.array)throw new Error("No array");if(this.needsUpdate||!this.source){if(this.needsUpdate=!1,this.source){const{width:t,height:e,depth:n}=this.source.image;this.capacity!==t*e*n&&(this.source.dispose(),this.source=null)}if(this.source)this.array.buffer!==this.source.image.data.buffer&&(this.source.image.data=new Uint8Array(this.array.buffer));else{const{width:e,height:n,depth:a}=ea(this.capacity);this.source=new t.DataArrayTexture(this.array,e,n,a),this.source.format=t.RGBAFormat,this.source.type=t.UnsignedByteType,this.source.internalFormat="RGBA8",this.source.needsUpdate=!0}this.source.needsUpdate=!0}return this.source}render({reader:t,count:e,renderer:n}){this.readback||(this.readback=new mo({renderer:n})),this.readback.render({reader:t,count:e,renderer:n}),this.capacity=this.readback.capacity,this.count=this.readback.count}fromPackedSplats({packedSplats:t,base:n,count:a,renderer:s}){const{dynoSplats:r,dynoBase:i,dynoCount:o,reader:l}=e.makeDynos();return r.packedSplats=t,i.value=n,o.value=a,this.render({reader:l,count:a,renderer:s}),this}async read(){if(!this.readback)throw new Error("No readback");(!this.array||this.array.length<4*this.count)&&(this.array=new Uint8Array(4*this.capacity));return(await this.readback.readback({readback:this.array})).subarray(0,4*this.count)}async getArray(){if(this.readback)return await this.read();if(this.array)return this.array;throw new Error("No array")}static getEmpty(){if(!e.emptySource){const n=new Uint8Array(4);e.emptySource=new t.DataArrayTexture(n,1,1,1),e.emptySource.format=t.RGBAFormat,e.emptySource.type=t.UnsignedByteType,e.emptySource.internalFormat="RGBA8",e.emptySource.needsUpdate=!0}return e.emptySource}static makeDynos(){if(!e.dynos){const t=new Sl,n=new re({value:0}),a=new re({value:0}),s=O({index:"int"},{rgba8:"vec4"},(({index:e})=>{if(!e)throw new Error("index is undefined");e=as(e,n);const s=at(t,e,n,a);return{rgba8:it(s).outputs.rgba}}));e.dynos={dynoSplats:t,dynoBase:n,dynoCount:a,reader:s}}return e.dynos}};ql.emptySource=null,ql.dynos=null;let Ul=ql;const Vl={type:"RgbaArray"},Bl=j("\n struct RgbaArray {\n sampler2DArray texture;\n int count;\n };\n");const Nl=65536;class Ol{constructor(e){var a;if(this.abortController=new AbortController,this.pager=e.pager,this.rootUrl=e.rootUrl??"",this.requestHeader=e.requestHeader,this.withCredentials=e.withCredentials,this.numSh=0,this.maxSh=(null==(a=e.pager)?void 0:a.maxSh)??3,this.numSplats=0,this.dynoNumSplats=new re({value:0}),this.dynoIndices=new Ee({value:Hl.emptyIndicesTexture}),this.rgbMinMaxLnScaleMinMax=new ge({value:new t.Vector4(0,1,n,9)}),this.lodOpacity=new ae({value:!1}),this.dynoNumSh=new re({value:0}),this.shMax=new xe({value:new t.Vector3}),this.fileBytes=e.fileBytes,this.fileType=e.fileType,!this.fileType&&this.fileBytes&&(this.fileType=Dl(this.fileBytes)),!this.fileType&&this.rootUrl&&(this.fileType=zl(this.rootUrl)),!this.fileType)throw new Error("Unable to determine file type");this.fileType===l.RAD&&(this.radMetaPromise=this.getRadMeta())}dispose(){this.dynoIndices.value!==Hl.emptyIndicesTexture&&(this.dynoIndices.value.dispose(),this.dynoIndices.value=Hl.emptyIndicesTexture),this.abortController.abort()}setMaxSh(t){this.maxSh=t}getRadMeta(){return this.radMetaPromise||(this.radMetaPromise=(async()=>{if(await xl,this.fileBytes){const t=Co(this.fileBytes.slice(0,1048576));if(t)return t;throw new Error("Failed to decode RAD header")}if(!this.rootUrl)throw new Error("No url or fileBytes provided");for(const t of[65536,262144,1048576]){const e=Co(await Ql({url:this.rootUrl,requestHeader:this.requestHeader,withCredentials:this.withCredentials,offset:0,bytes:t}));if(e)return e}throw new Error("Failed to decode RAD header")})().then((t=>t)),this.radMetaPromise.catch((t=>{}))),this.radMetaPromise}chunkUrl(t){return this.rootUrl.replace(/-lod-0\./,`-lod-${t}.`)}async fetchDecodeChunk(t){let e;if(this.fileType===l.RAD){const{meta:n,chunksStart:a}=await this.getRadMeta();if(t<0||t>=n.chunks.length)throw new Error(`Chunk index out of range: ${t} (max: ${n.chunks.length-1})`);let{offset:s,bytes:r,filename:i}=n.chunks[t];if(i){if(this.fileBytes)throw new Error("Chunked RAD file not supported with fileBytes");const t=new URL(this.rootUrl,window.location.href).toString(),n=new URL(i,t).toString();e=await Ql({url:n,requestHeader:this.requestHeader,withCredentials:this.withCredentials,signal:this.abortController.signal})}else if(s+=a,this.fileBytes){if(s<0||s+r>this.fileBytes.length)throw new Error(`Invalid chunk offset or bytes: ${s} + ${r} > ${this.fileBytes.length}`);e=this.fileBytes.slice(s,s+r)}else{if(!this.rootUrl)throw new Error("No url or fileBytes provided");e=await Ql({url:this.rootUrl,requestHeader:this.requestHeader,withCredentials:this.withCredentials,offset:s,bytes:r,signal:this.abortController.signal})}}else if(this.fileBytes);else{if(!this.rootUrl)throw new Error("No url or fileBytes provided");{const n=this.chunkUrl(t),a=new Request(n,{headers:this.requestHeader?new Headers(this.requestHeader):void 0,credentials:this.withCredentials?"include":"same-origin",signal:this.abortController.signal}),s=await fetch(a);if(!s.ok||!s.body)throw new Error(`Failed to fetch "${n}": ${s.status} ${s.statusText}`);e=new Uint8Array(await s.arrayBuffer())}}return await vl.withWorker((async a=>{var s,r,i,o,l;if(!this.pager)throw new Error("PagedSplats.pager not set");if(!this.pager.extSplats){const o=await a.call("loadPackedSplats",{fileBytes:e,pathName:this.chunkUrl(t),sh1Codes:null==(s=this.sh1Codes)?void 0:s.slice(),sh2Codes:null==(r=this.sh2Codes)?void 0:r.slice(),sh3Codes:null==(i=this.sh3Codes)?void 0:i.slice()});if(!("lodSplats"in o))throw new Error("Loaded chunk does not contain LoD splats");const l=o.lodSplats;return this.splatEncoding||(this.splatEncoding=l.splatEncoding,this.numSh=l.extra.sh3?3:l.extra.sh2?2:l.extra.sh1?1:0,this.rgbMinMaxLnScaleMinMax.value.set(this.splatEncoding.rgbMin??0,this.splatEncoding.rgbMax??1,this.splatEncoding.lnScaleMin??n,this.splatEncoding.lnScaleMax??9),this.lodOpacity.value=this.splatEncoding.lodOpacity??!1,this.shMax.value.set(this.splatEncoding.sh1Max??1,this.splatEncoding.sh2Max??1,this.splatEncoding.sh3Max??1)),this.sh1Codes=l.extra.sh1Codes??this.sh1Codes,this.sh2Codes=l.extra.sh2Codes??this.sh2Codes,this.sh3Codes=l.extra.sh3Codes??this.sh3Codes,l}const c=this.sh3Codes,p=await a.call("loadExtSplats",{fileBytes:e,pathName:this.chunkUrl(t),sh1Codes:null==(o=this.sh1Codes)?void 0:o.slice(),sh2Codes:null==(l=this.sh2Codes)?void 0:l.slice(),sh3Codes:c?[c[0].slice(),c[1].slice()]:void 0});if(!("lodSplats"in p))throw new Error("Loaded chunk does not contain LoD splats");const d=p.lodSplats;return this.splatEncoding||(this.splatEncoding=u,this.numSh=d.extra.sh3a&&d.extra.sh3b?3:d.extra.sh2?2:d.extra.sh1?1:0),this.sh1Codes=d.extra.sh1Codes??this.sh1Codes,this.sh2Codes=d.extra.sh2Codes??this.sh2Codes,this.sh3Codes=d.extra.sh3Codes??this.sh3Codes,d}))}update(e,n){if(!this.pager)throw new Error("PagedSplats.pager not set");const a=this.pager.renderer;this.numSplats=e,this.dynoNumSplats.value=this.numSplats;const s=Math.ceil(e/16384);let r=this.dynoIndices.value===Hl.emptyIndicesTexture?void 0:this.dynoIndices.value;if(r&&s>r.image.height&&(r.dispose(),r=void 0),r){const t=r.image.data;t.set(n.subarray(0,e)),Sa(a,r,4096,s,t)}else r=new t.DataTexture(n,4096,s,t.RGBAIntegerFormat,t.UnsignedIntType),r.internalFormat="RGBA32UI",r.needsUpdate=!0,a.initTexture(r),this.dynoIndices.value=r}prepareFetchSplat(){}getNumSplats(){return this.numSplats}hasRgbDir(){return!!this.pager&&Math.min(this.numSh,this.pager.maxSh)>0}getNumSh(){return this.numSh}fetchSplat({index:t,viewOrigin:e}){if(!this.pager)throw new Error("PagedSplats.pager not set");const n=this.pager.readIndex.apply({index:t,numSplats:this.dynoNumSplats,indices:this.dynoIndices}).index;return this.pager.extSplats?this.hasRgbDir()&&e?(this.dynoNumSh.value=Math.min(this.numSh,this.maxSh,this.pager.maxSh),this.pager.readSplatExtDir.apply({index:n,viewOrigin:e,numSh:this.dynoNumSh}).gsplat):this.pager.readSplatExt.apply({index:n}).gsplat:this.hasRgbDir()&&e?(this.dynoNumSh.value=Math.min(this.numSh,this.maxSh,this.pager.maxSh),this.pager.readSplatDir.apply({index:n,rgbMinMaxLnScaleMinMax:this.rgbMinMaxLnScaleMinMax,lodOpacity:this.lodOpacity,viewOrigin:e,numSh:this.dynoNumSh,shMax:this.shMax}).gsplat):this.pager.readSplat.apply({index:n,rgbMinMaxLnScaleMinMax:this.rgbMinMaxLnScaleMinMax,lodOpacity:this.lodOpacity}).gsplat}forEachSplat(t){if(!this.pager||!this.numSplats)return;const e=this.pager.extSplats,n=this.dynoIndices.value.image.data,a=this.pager.packedTexture.value.image.data,s=[a,this.pager.extTexture.value.image.data];for(let r=0;r<this.numSplats;++r){const i=n[r],o=e?Xn(s,i):ta(a,i,this.splatEncoding);t(r,o.center,o.scales,o.quaternion,o.opacity,o.color)}}}const Gl=class e{constructor(t){this.fetchPause=0,this.splatsChunkToPage=new Map,this.pageToSplatsChunk=[],this.renderer=t.renderer,this.extSplats=t.extSplats??!1,this.pageSplats=Nl,this.maxSplats=t.maxSplats??16777216,this.maxPages=Math.ceil(this.maxSplats/Nl),this.maxSplats=this.maxPages*Nl,this.maxSh=t.maxSh??3,this.curSh=0,this.autoDrive=t.autoDrive??!0,this.numFetchers=t.numFetchers??3,this.splatsChunkToPage=new Map,this.pageToSplatsChunk=new Array(this.maxPages),this.pageFreelist=Array.from({length:this.maxPages},((t,e)=>e)),this.pageLru=new Set,this.freeablePages=[],this.newUploads=[],this.readyUploads=[],this.lodTreeUpdates=[],this.fetchers=[],this.fetched=[],this.fetchPriority=[],this.packedTexture=new Pe({value:this.newUint32ArrayTexture(4)}),this.extTexture=new Pe({value:this.extSplats?this.newUint32ArrayTexture(4):e.emptyExtTexture});const n=this.extSplats?e.emptyExtShTextures:e.emptyShTextures;this.shTextures=n.map((t=>new Pe({value:t}))),this.readIndex=O({index:"int",numSplats:"int",indices:"usampler2D"},{index:"int"},(({index:t,numSplats:e,indices:n})=>new B({inTypes:{index:"int",numSplats:"int",indices:"usampler2D"},outTypes:{index:"int"},inputs:{index:t,numSplats:e,indices:n},statements:({inputs:t,outputs:e})=>W(`\n if (${t.index} >= ${t.numSplats}) {\n return;\n }\n\n ivec2 indexCoord = ivec2((${t.index} >> 2) & 4095, ${t.index} >> 14);\n uint index = texelFetch(${t.indices}, indexCoord, 0)[${t.index} & 3];\n ${e.index} = int(index);\n `)}).outputs)),this.readSplat=O({index:"int",rgbMinMaxLnScaleMinMax:"vec4",lodOpacity:"bool"},{gsplat:Y},(({index:t,rgbMinMaxLnScaleMinMax:e,lodOpacity:n})=>new B({inTypes:{index:"int",packedTexture:"usampler2DArray",rgbMinMaxLnScaleMinMax:"vec4",lodOpacity:"bool"},outTypes:{gsplat:Y},inputs:{index:t,packedTexture:this.packedTexture,rgbMinMaxLnScaleMinMax:e,lodOpacity:n},globals:()=>[dt],statements:({inputs:t,outputs:e})=>W(`\n int index = ${t.index};\n ivec3 splatCoord = pagedSplatTexCoord(index);\n uvec4 packedData = texelFetch(${t.packedTexture}, splatCoord, 0);\n\n unpackSplatEncoding(packedData, ${e.gsplat}.center, ${e.gsplat}.scales, ${e.gsplat}.quaternion, ${e.gsplat}.rgba, ${t.rgbMinMaxLnScaleMinMax});\n if ((${e.gsplat}.rgba.a == 0.0) || all(equal(${e.gsplat}.scales, vec3(0.0, 0.0, 0.0)))) {\n return;\n }\n \n ${e.gsplat}.index = index;\n ${e.gsplat}.flags = GSPLAT_FLAG_ACTIVE;\n if (${t.lodOpacity}) {\n ${e.gsplat}.rgba.a *= 2.0;\n }\n `)}).outputs)),this.readSplatDir=O({index:"int",rgbMinMaxLnScaleMinMax:"vec4",lodOpacity:"bool",viewOrigin:"vec3",numSh:"int",shMax:"vec3"},{gsplat:Y},(({index:t,rgbMinMaxLnScaleMinMax:e,lodOpacity:n,viewOrigin:a,numSh:s,shMax:r})=>{if(!(t&&e&&n&&a&&s&&r))throw new Error("index and viewOrigin are required");let i=this.readSplat.apply({index:t,rgbMinMaxLnScaleMinMax:e,lodOpacity:n}).gsplat;const o=it(i).outputs.center,l=Qr(ss(o,a));let u=kl({coord:pt(t),viewDir:l,numSh:s,sh1Texture:this.shTextures[0],sh2Texture:this.shTextures[1],sh3Texture:this.shTextures[2],shMax:r}).rgb;return u=as(u,it(i).outputs.rgb),i=ot({gsplat:i,rgb:u}),{gsplat:i}})),this.readSplatExt=O({index:"int"},{gsplat:Y},(({index:t})=>new B({inTypes:{index:"int",extTexture1:"usampler2DArray",extTexture2:"usampler2DArray"},outTypes:{gsplat:Y},inputs:{index:t,extTexture1:this.packedTexture,extTexture2:this.extTexture},globals:()=>[dt],statements:({inputs:t,outputs:e})=>W(`\n int index = ${t.index};\n ivec3 splatCoord = ivec3(index & 255, (index >> 8) & 255, index >> 16);\n uvec4 ext1 = texelFetch(${t.extTexture1}, splatCoord, 0);\n float alpha = unpackSplatExtAlpha(ext1);\n if (alpha == 0.0) {\n return;\n }\n\n uvec4 ext2 = texelFetch(${t.extTexture2}, splatCoord, 0);\n unpackSplatExt(ext1, ext2, ${e.gsplat}.center, ${e.gsplat}.scales, ${e.gsplat}.quaternion, ${e.gsplat}.rgba);\n if (all(equal(${e.gsplat}.scales, vec3(0.0, 0.0, 0.0)))) {\n return;\n }\n\n ${e.gsplat}.index = index;\n ${e.gsplat}.flags = GSPLAT_FLAG_ACTIVE;\n `)}).outputs)),this.readSplatExtDir=O({index:"int",viewOrigin:"vec3",numSh:"int"},{gsplat:Y},(({index:t,viewOrigin:e,numSh:n})=>{if(!t||!e||!n)throw new Error("index and viewOrigin are required");let a=this.readSplatExt.apply({index:t}).gsplat;const s=it(a).outputs.center,r=Qr(ss(s,e));let i=Ll({coord:pt(t),viewDir:r,numSh:n,sh1Texture:this.shTextures[0],sh2Texture:this.shTextures[1],sh3TextureA:this.shTextures[2],sh3TextureB:this.shTextures[3]}).rgb;return i=as(i,it(a).outputs.rgb),a=ot({gsplat:a,rgb:i}),{gsplat:a}}))}dispose(){this.autoDrive=!1,this.numFetchers=0,this.packedTexture.value.dispose(),this.packedTexture.value.source.data=null,this.extTexture.value!==e.emptyExtTexture&&(this.extTexture.value.dispose(),this.extTexture.value.source.data=null);const t=this.extSplats?e.emptyExtShTextures:e.emptyShTextures;for(let e=0;e<t.length;e++){const n=this.shTextures[e].value;n!==t[e]&&(n.dispose(),n.source.data=null)}}ensureShTextures(t){this.curSh=Math.max(this.curSh,t);const n=this.extSplats?e.emptyExtShTextures:e.emptyShTextures;for(let a=0;a<this.curSh;a++)if(this.shTextures[a].value===n[a]){const t=this.shTextures[a].value===e.emptyUint32x2?2:4;this.shTextures[a].value=this.newUint32ArrayTexture(t)}}allocatePage(){return this.pageFreelist.shift()}getSplatsChunk(t,e){const n=this.splatsChunkToPage.get(t);if(n)return n[e]}insertSplatsChunkPage(t,e,n,a){this.splatsChunkToPage.has(t)||this.splatsChunkToPage.set(t,[]);const s=this.splatsChunkToPage.get(t);if(!s)throw new Error("impossible");e>=s.length&&(s.length=e+1);const r={page:n,lru:a};return s[e]=r,this.pageLru.add(r),this.pageToSplatsChunk[n]={splats:t,chunk:e,time:performance.now()},this.pageToSplatsChunk[n]}removeSplatsChunkPage(t,e,n){const a=this.splatsChunkToPage.get(t);if(!a)throw new Error("impossible");const s=a[e];if(!s)throw new Error(`pageLru not found for splats: ${t}, chunk: ${e}, page: ${n}`);for(this.pageLru.delete(s),a[e]=void 0;a.length>0&&void 0===a[a.length-1];)a.pop();for(0===a.length&&this.splatsChunkToPage.delete(t),this.pageToSplatsChunk[n]=void 0;this.pageToSplatsChunk.length>0&&void 0===this.pageToSplatsChunk[this.pageToSplatsChunk.length-1];)this.pageToSplatsChunk.pop()}removeSplats(t){const e=this.splatsChunkToPage.get(t);if(!e)return;const n=new Set;for(;e.length>0;){const t=e.pop();if(t){const{page:e}=t;this.pageToSplatsChunk[e]=void 0,n.add(e),this.pageFreelist.push(e),this.pageLru.delete(t)}}this.splatsChunkToPage.delete(t),this.freeablePages=this.freeablePages.filter((t=>!n.has(t)))}uploadPage(e,n,a,s){const r=e*Nl;jl(this.packedTexture,e,4*r,n),s&&jl(this.extTexture,e,4*r,s);const i=Math.min(a.length,3);this.ensureShTextures(i);for(let o=0;o<a.length;o++){const n=a[o],s=this.shTextures[o].value.format===t.RGIntegerFormat?2:4;jl(this.shTextures[o],e,r*s,n)}}newUint32ArrayTexture(e){const n=new Uint32Array(256*this.maxPages*256*e),a=new t.DataArrayTexture(n,256,256,this.maxPages);return a.format=2===e?t.RGIntegerFormat:t.RGBAIntegerFormat,a.type=t.UnsignedIntType,a.internalFormat=2===e?"RG32UI":"RGBA32UI",a.needsUpdate=!0,a.source.dataReady=!1,this.renderer.initTexture(a),a}driveFetchers(){const t=[],e=[];let n=0;for(const{splats:r,chunk:i}of this.fetchPriority){const a=this.getSplatsChunk(r,i);if(a)n>=this.maxPages?e.push(a):t.push(a),n+=1;else if(this.fetched.some((({splats:t,chunk:e})=>r===t&&i===e))||this.fetchers.some((({splats:t,chunk:e})=>r===t&&i===e)))n+=1;else if(n<this.maxPages&&this.fetchers.length<this.numFetchers){n+=1;const t={splats:r,chunk:i};this.fetchers.push(t);r.fetchDecodeChunk(i).then((async t=>{r.abortController.signal.aborted||(this.fetched.push({splats:r,chunk:i,data:t}),this.fetchPause>0&&await new Promise((t=>setTimeout(t,this.fetchPause))))}),(async t=>{t.name;const e=250+500*Math.random();await new Promise((t=>setTimeout(t,e)))})).finally((()=>{const e=this.fetchers.indexOf(t);this.fetchers[e]=this.fetchers[this.fetchers.length-1],this.fetchers.length--,this.processFetched()})).then((t=>{this.autoDrive&&this.driveFetchers()}))}}const a=performance.now();for(const r of e.reverse())r.lru=a,this.pageLru.delete(r),this.pageLru.add(r);const s=new Set(this.pageLru);for(const r of t.reverse())s.delete(r),r.lru=a,this.pageLru.delete(r),this.pageLru.add(r);this.freeablePages=Array.from(s).map((({page:t})=>t))}allocateFreeable(){const t=this.freeablePages.shift();if(void 0===t)return;const e=this.pageToSplatsChunk[t];if(!e)throw new Error(`splatsChunk not found for page: ${t}`);const{splats:n,chunk:a}=e;return this.removeSplatsChunkPage(n,a,t),this.lodTreeUpdates.push({splats:n,page:t,chunk:a,numSplats:Nl}),t}processFetched(){const t=performance.now();for(;;){const e=this.fetched.shift();if(!e)break;const{splats:n,chunk:a,data:s}=e;let r=this.allocatePage();if(void 0===r&&(r=this.allocateFreeable(),void 0===r))return;this.insertSplatsChunkPage(n,a,r,t);const{numSplats:i,extra:o}=s;if(this.lodTreeUpdates.push({splats:n,page:r,chunk:a,numSplats:i,lodTree:o.lodTree}),Wl(s,this.extSplats)){const t=s.extArrays,e=t[0],n=t[1],a=[s.extra.sh1,s.extra.sh2,s.extra.sh3a,s.extra.sh3b],o=a.findIndex((t=>!t));o>=0&&(a.length=o),this.newUploads.push({page:r,numSplats:i,packedArray:e,extArray:n,shArrays:a})}else{const t=s.packedArray,e=[s.extra.sh1,s.extra.sh2,s.extra.sh3],n=e.findIndex((t=>!t));n>=0&&(e.length=n),this.newUploads.push({page:r,numSplats:i,packedArray:t,shArrays:e})}}}processUploads(){for(;;){const t=this.readyUploads.shift();if(!t)break;const{page:e,numSplats:n,packedArray:a,extArray:s,shArrays:r}=t;this.uploadPage(e,a,r,s)}}consumeLodTreeUpdates(){const t=this.lodTreeUpdates;return this.lodTreeUpdates=[],this.readyUploads.push(...this.newUploads),this.newUploads=[],t}};Gl.emptyUint32x4=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})(),Gl.emptyUint32x2=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(2*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RG32UI",i.needsUpdate=!0,i})(),Gl.emptyIndicesTexture=(()=>{const e=new Uint32Array(16384),n=new t.DataTexture(e,4096,1);return n.format=t.RGBAIntegerFormat,n.type=t.UnsignedIntType,n.internalFormat="RGBA32UI",n.needsUpdate=!0,n})(),Gl.emptyPackedTexture=Gl.emptyUint32x4,Gl.emptyExtTexture=Gl.emptyUint32x4,Gl.emptyShTextures=[Gl.emptyUint32x2,Gl.emptyUint32x4,Gl.emptyUint32x4],Gl.emptyExtShTextures=[Gl.emptyUint32x4,Gl.emptyUint32x4,Gl.emptyUint32x4,Gl.emptyUint32x4];let Hl=Gl;function Wl(t,e){return e}function jl(t,e,n,a){t.value.image.data.subarray(n,n+a.length).set(a),t.value.addLayerUpdate(e),t.value.needsUpdate=!0,t.value.source.dataReady=!0}async function Ql({url:t,requestHeader:e,withCredentials:n,offset:a,bytes:s,signal:r}){const i=new Request(t,{headers:e?new Headers(e):void 0,credentials:n?"include":"same-origin",signal:r});void 0!==a&&void 0!==s&&i.headers.set("Range",`bytes=${a}-${a+s-1}`);const o=await fetch(i);if(!o.ok||!o.body)throw new Error(`Failed to fetch "${t}": ${o.status} ${o.statusText}`);return new Uint8Array(await o.arrayBuffer())}class Kl{constructor(){this.fetchDyno=new B({inTypes:{},outTypes:{gsplat:Y},globals:()=>[dt],statements:({outputs:t})=>W(`\n ${t.gsplat}.flags = 0u;\n return;\n `)}).outputs.gsplat}prepareFetchSplat(){}dispose(){}getNumSplats(){return 0}hasRgbDir(){return!1}getNumSh(){return 0}setMaxSh(t){}fetchSplat({index:t}){return this.fetchDyno}forEachSplat(){}}const Xl=class e extends Eo{constructor(e={}){if(super({update:t=>this.update(t)}),this.isInitialized=!1,this.recolor=new t.Color(1,1,1),this.opacity=1,this.generatorDirty=!0,this.enableViewToObject=!1,this.enableViewToWorld=!1,this.enableWorldToView=!1,this.skinning=null,this.edits=null,this.rgbaDisplaceEdits=null,this.splatRgba=null,this.maxSh=3,this.showLodPageDyno=new re({value:0}),this.objectToRender=new t.Matrix4,this.objectToRenderOffset=new t.Vector3,this.worldToObject=new t.Matrix4,this.worldToView=new t.Matrix4,this.viewToObjectMatrix=new t.Matrix4,e.splats)this.splats=e.splats,this.numSplats=e.splats.getNumSplats();else if(e.paged){e.extSplats;const t=e.url??"";if(e.paged instanceof Ol)this.paged=e.paged;else{const n={rootUrl:t};if(e.paged instanceof Hl)n.pager=e.paged;else{if(!0!==e.paged)throw new Error("Invalid paged option");n.fileType=e.fileType}this.paged=new Ol(n)}this.splats=this.paged}else e.extSplats?(this.extSplats=e.extSplats instanceof El?e.extSplats:new El,e.extSplats=this.extSplats,this.numSplats=this.extSplats.numSplats,this.splats=this.extSplats):e.packedSplats?(this.packedSplats=e.packedSplats,this.packedSplats.splatEncoding=e.splatEncoding??{...u},this.splats=this.packedSplats):this.packedSplats=new bl;if(this.editable=e.editable??!0,this.raycastable=e.raycastable??!0,this.minRaycastOpacity=e.minRaycastOpacity??.2,this.onFrame=e.onFrame,this.context={transform:new zo,viewToWorld:new zo,worldToView:new zo,viewToObject:new zo,covTransform:new Io,covViewToWorld:new Io,covWorldToView:new Io,covViewToObject:new Io,recolor:new ge({value:(new t.Vector4).setScalar(Number.NEGATIVE_INFINITY)}),time:new ie({value:0}),deltaTime:new ie({value:0}),numSplats:new re({value:0}),splats:new Kl,enableLod:new ae({value:!1}),lodIndices:new Ee({value:tu,key:"lodIndices"})},this.covSplats=e.covSplats??!1,this.covSplats&&!this.extSplats)throw new Error("CovSplats requires ExtSplats");if(this.objectModifiers=e.objectModifier?[e.objectModifier]:void 0,this.worldModifiers=e.worldModifier?[e.worldModifier]:void 0,e.objectModifiers&&(this.objectModifiers=e.objectModifiers),e.worldModifiers&&(this.worldModifiers=e.worldModifiers),this.enableLod=e.enableLod,this.lodScale=e.lodScale??1,this.behindFoveate=e.behindFoveate,this.coneFov0=e.coneFov0,this.coneFov=e.coneFov,this.coneFoveate=e.coneFoveate,this.updateGenerator(),e.url||e.fileBytes||e.stream||e.constructSplats||e.packedSplats&&!e.packedSplats.isInitialized||this.extSplats&&!this.extSplats.isInitialized)this.initialized=this.asyncInitialize(e).then((async()=>{if(this.updateGenerator(),this.isInitialized=!0,e.onLoad){const t=e.onLoad(this);t instanceof Promise&&await t}return this}));else if(this.isInitialized=!0,this.initialized=Promise.resolve(this),e.onLoad){const t=e.onLoad(this);t instanceof Promise&&(this.initialized=t.then((()=>this)))}}async asyncInitialize(t){const{url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,maxSplats:o,constructSplats:l,onProgress:u,splatEncoding:c,lod:p,nonLod:d,lodAbove:h}=t;if(this.packedSplats){if(e||n||r||l){const t={url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,maxSplats:o,construct:l,onProgress:u,splatEncoding:c,lod:p,nonLod:d,lodAbove:h};this.packedSplats.reinitialize(t)}await this.packedSplats.initialized,this.splats=this.packedSplats}else if(this.extSplats&&(e||n||r||l)){const t=l;this.extSplats.reinitialize({url:e,fileBytes:n,fileType:a,fileName:s,stream:r,streamLength:i,maxSplats:o,construct:t,onProgress:u,lod:p,nonLod:d,lodAbove:h}),await this.extSplats.initialized,this.splats=this.extSplats}this.splats&&(this.numSplats=this.splats.getNumSplats(),this.updateGenerator())}pushSplat(t,e,n,a,s){this.packedSplats?this.packedSplats.pushSplat(t,e,n,a,s):this.extSplats&&this.extSplats.pushSplat(t,e,n,a,s)}forEachSplat(t){var e;null==(e=this.splats)||e.forEachSplat(t)}dispose(){var t;null==(t=super.dispose)||t.call(this),this.splats&&this.splats!==this.packedSplats&&this.splats!==this.extSplats&&(this.splats.dispose(),this.splats=void 0),this.packedSplats&&(this.packedSplats.dispose(),this.packedSplats=void 0),this.extSplats&&(this.extSplats.dispose(),this.extSplats=void 0)}getBoundingBox(e=!0){var n;if(!this.initialized)throw new Error("Cannot get bounding box before SplatMesh is initialized");const a=new t.Vector3(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),s=new t.Vector3(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),r=new t.Vector3,i=[-1,1];null==(n=this.splats)||n.forEachSplat((function(t,n,o,l,u,c){if(e)a.min(n),s.max(n);else for(const e of i)for(const t of i)for(const u of i)r.set(e*o.x,t*o.y,u*o.z),r.applyQuaternion(l),r.add(n),a.min(r),s.max(r)}));return new t.Box3(a,s)}set objectModifier(t){this.objectModifiers=t?[t]:void 0}set worldModifier(t){this.worldModifiers=t?[t]:void 0}constructGenerator(t){if(this.covSplats)return this.constructCovGenerator(t);const{transform:e,viewToObject:n,recolor:a}=t,s=O({index:"int"},{gsplat:Y},(({index:s})=>{if(!s)throw new Error("index is undefined");s=Jl(t.lodIndices,s,t.numSplats,t.enableLod,this.showLodPageDyno),t.splats.setMaxSh(this.maxSh),t.splats.prepareFetchSplat();let r=t.splats.fetchSplat({index:s,viewOrigin:n.translate});if(this.splatRgba&&(r=Zl(r,this.splatRgba.dyno,s,t.enableLod)),this.skinning&&(r=this.skinning.modify(r)),this.objectModifiers)for(const t of this.objectModifiers)r=t.apply({gsplat:r}).gsplat;r=e.applyGsplat(r);const i=rs(a,it(r).outputs.rgba);if(r=ot({gsplat:r,rgba:i}),this.rgbaDisplaceEdits&&(r=this.rgbaDisplaceEdits.modify(r)),this.worldModifiers)for(const t of this.worldModifiers)r=t.apply({gsplat:r}).gsplat;return{gsplat:r}}));this.generator=s,this.covGenerator=void 0}constructCovGenerator(t){const{covTransform:e,covViewToObject:n,recolor:a}=t,s=O({index:"int"},{covsplat:J},(({index:s})=>{if(!s)throw new Error("index is undefined");s=Jl(t.lodIndices,s,t.numSplats,t.enableLod,this.showLodPageDyno),t.splats.prepareFetchSplat();let r=t.splats.fetchSplat({index:s,viewOrigin:n.offset});if(this.splatRgba&&(r=Zl(r,this.splatRgba.dyno,s,t.enableLod)),this.objectModifiers)for(const t of this.objectModifiers)r=t.apply({gsplat:r}).gsplat;let i=rt(r);if(this.skinning&&(i=this.skinning.modifyCov(i)),this.covObjectModifiers)for(const t of this.covObjectModifiers)i=t.apply({covsplat:i}).covsplat;i=e.applyCovSplat(i);const o=rs(a,Ct(i).outputs.rgba);if(i=Lt({covsplat:i,rgba:o}),this.rgbaDisplaceEdits&&(i=this.rgbaDisplaceEdits.modifyCov(i)),this.covWorldModifiers)for(const t of this.covWorldModifiers)i=t.apply({covsplat:i}).covsplat;return{covsplat:i}}));this.generator=void 0,this.covGenerator=s}updateGenerator(){this.generatorDirty=!0}update({renderer:n,time:a,deltaTime:s,viewToWorld:r,renderOrigin:i,camera:o,renderSize:l,globalEdits:u,lodIndices:c}){var p,d,h;this.context.time.value=a,this.context.deltaTime.value=s,e.dynoTime.value=a,this.showLodPageDyno.value=this.showLodPage??-1;const x=this.splats??this.packedSplats??this.extSplats;x&&(this.context.splats=x),this.numSplats=this.context.splats.getNumSplats();let f=!1;const m=(null==(p=this.packedSplats)?void 0:p.lodSplats)??(null==(d=this.extSplats)?void 0:d.lodSplats);this.context.enableLod.value=null!=m&&null!=c,!1===this.enableLod&&(this.context.enableLod.value=!1),this.context.lodIndices.value=(null==c?void 0:c.texture)??tu,this.context.enableLod.value&&m&&(this.context.splats=m,this.numSplats=(null==c?void 0:c.numSplats)??0),this.context.numSplats.value=this.numSplats,this.context.splats!==this.lastSplats&&(this.lastSplats=this.context.splats,this.generatorDirty=!0),this.updateMatrixWorld();const y=this.objectToRender.copy(this.matrixWorld);if(y.setPosition(this.objectToRenderOffset.setFromMatrixPosition(this.matrixWorld).sub(i)),this.covSplats){this.context.covTransform.updateFromMatrix(y)&&(f=!0),this.context.covViewToWorld.updateFromMatrix(r)&&this.enableViewToWorld&&(f=!0);const t=this.worldToView.copy(r).invert();this.context.covWorldToView.updateFromMatrix(t)&&this.enableWorldToView&&(f=!0);const e=this.viewToObjectMatrix.multiplyMatrices(this.worldToObject.copy(y).invert(),r);this.context.covViewToObject.updateFromMatrix(e)&&(this.enableViewToObject||this.context.splats.hasRgbDir())&&(f=!0)}else{this.context.transform.updateFromMatrix(y)&&(f=!0),this.context.viewToWorld.updateFromMatrix(r)&&this.enableViewToWorld&&(f=!0);const t=this.worldToView.copy(r).invert();this.context.worldToView.updateFromMatrix(t)&&this.enableWorldToView&&(f=!0);const e=this.viewToObjectMatrix.multiplyMatrices(this.worldToObject.copy(y).invert(),r);this.context.viewToObject.updateFromMatrix(e)&&(this.enableViewToObject||this.context.splats.hasRgbDir())&&(f=!0)}const g=new t.Vector4(this.recolor.r,this.recolor.g,this.recolor.b,this.opacity);g.equals(this.context.recolor.value)||(this.context.recolor.value.copy(g),f=!0);const v=this.editable?(this.edits??[]).concat(u):[];this.editable&&!this.edits&&this.traverseVisible((t=>{t instanceof To&&v.push(t)})),v.sort(((t,e)=>t.ordering-e.ordering));const w=v.map((t=>{if(null!=t.sdfs)return{edit:t,sdfs:t.sdfs};const e=[];return t.traverseVisible((t=>{t instanceof bo&&e.push(t)})),{edit:t,sdfs:e}}));if(w.length>0&&!this.rgbaDisplaceEdits){const t=w.length,e=w.reduce(((t,e)=>t+e.sdfs.length),0);this.rgbaDisplaceEdits=new _o({maxEdits:t,maxSdfs:e}),this.generatorDirty=!0}if(this.rgbaDisplaceEdits){const t=this.rgbaDisplaceEdits.update(w);f||(f=t.updated),t.dynoUpdated&&(this.generatorDirty=!0)}this.generatorDirty&&(this.constructGenerator(this.context),this.generatorDirty=!1,f=!0),f&&this.updateVersion(),null==(h=this.onFrame)||h.call(this,{mesh:this,time:a,deltaTime:s})}raycast(a,s){var r,i,o,l,u,c,p,d,h,x,f,m,y,g,v,w,b,S,T,_,M,k,$;if(!hl||!this.raycastable||!this.packedSplats&&!this.extSplats&&!this.paged)return;const D=null!=this.paged,z=D?(null==(i=null==(r=this.paged)?void 0:r.pager)?void 0:i.extSplats)??!1:null!=this.extSplats,{near:I,far:E,ray:A}=a,F=this.matrixWorld.clone().invert(),P=(new t.Matrix3).setFromMatrix4(F),C=A.origin.clone().applyMatrix4(F),L=A.direction.clone().applyMatrix3(P),R=cl.get_raycast_buffer(),q=R.length/4;let U=0;const V=(null==(o=this.raycastIndices)?void 0:o.numSplats)??(D?null==(l=this.paged)?void 0:l.numSplats:this.context.numSplats.value)??0,B=(null==(u=this.raycastIndices)?void 0:u.indices)??(D?null==(c=this.paged)?void 0:c.dynoIndices.value.image.data:this.context.enableLod.value?this.context.lodIndices.value.image.data:null)??null;if(z){const t=cl.get_raycast_buffer2(),e=D?null==(v=null==(g=this.paged)?void 0:g.pager)?void 0:v.packedTexture.value.image.data:B?null==(b=null==(w=this.extSplats)?void 0:w.lodSplats)?void 0:b.extArrays[0]:null==(S=this.extSplats)?void 0:S.extArrays[0],n=D?null==(_=null==(T=this.paged)?void 0:T.pager)?void 0:_.extTexture.value.image.data:B?null==(k=null==(M=this.extSplats)?void 0:M.lodSplats)?void 0:k.extArrays[1]:null==($=this.extSplats)?void 0:$.extArrays[1];if(!e||!n)return;for(let a=0;a<V;a+=q){const s=Math.min(q,V-a);if(B)for(let i=0;i<s;++i){const s=4*i,r=4*B[a+i];R[s]=e[r],R[s+1]=e[r+1],R[s+2]=e[r+2],R[s+3]=e[r+3],t[s]=n[r],t[s+1]=n[r+1],t[s+2]=n[r+2],t[s+3]=n[r+3]}else R.set(e.subarray(4*a,4*(a+s))),t.set(n.subarray(4*a,4*(a+s)));const r=Ro(C.x,C.y,C.z,L.x,L.y,L.z,this.minRaycastOpacity,I,E,s);U=this.appendRaycastBuffer(U,r)}}else{const t=D?null==(d=null==(p=this.paged)?void 0:p.pager)?void 0:d.packedTexture.value.image.data:B?null==(x=null==(h=this.packedSplats)?void 0:h.lodSplats)?void 0:x.packedArray:null==(f=this.packedSplats)?void 0:f.packedArray;if(!t)return;const e=D?null==(m=this.paged)?void 0:m.splatEncoding:null==(y=this.packedSplats)?void 0:y.splatEncoding;for(let a=0;a<V;a+=q){const s=Math.min(q,V-a);if(B)for(let e=0;e<s;++e){const n=4*e,s=4*B[a+e];R[n]=t[s],R[n+1]=t[s+1],R[n+2]=t[s+2],R[n+3]=t[s+3]}else R.set(t.subarray(4*a,4*(a+s)));const r=qo(C.x,C.y,C.z,L.x,L.y,L.z,this.minRaycastOpacity,I,E,s,(null==e?void 0:e.lnScaleMin)??n,(null==e?void 0:e.lnScaleMax)??9,(null==e?void 0:e.lodOpacity)??!1);U=this.appendRaycastBuffer(U,r)}}for(const t of e.raycastBuffer.subarray(0,U)){const e=A.direction.clone().multiplyScalar(t).add(A.origin);s.push({distance:t,point:e,object:this})}}appendRaycastBuffer(t,n){const a=t+n.length;let s=e.raycastBuffer.length;if(a>s){for(;s<a;)s*=2;const n=new Float32Array(s);n.set(e.raycastBuffer.subarray(0,t)),e.raycastBuffer=n}return e.raycastBuffer.set(n,t),t+n.length}async createLodSplats({rgbaArray:t,quality:e}={}){this.packedSplats?await this.packedSplats.createLodSplats({quality:e,rgbaArray:t}):this.extSplats&&await this.extSplats.createLodSplats({quality:e,rgbaArray:t})}};Xl.dynoTime=new ie({value:0}),Xl.raycastBuffer=new Float32Array(1024);let Yl=Xl;function Jl(t,e,n,a,s){return G({inTypes:{lodIndices:"usampler2D",index:"int",numSplats:"int",enableLod:"bool",showLodPage:"int"},outTypes:{index:"int"},inputs:{lodIndices:t,index:e,numSplats:n,enableLod:a,showLodPage:s},statements:({inputs:t,outputs:e})=>W(`\n int index = ${t.index};\n if (${t.showLodPage} < 0) {\n if (index >= ${t.numSplats}) {\n return;\n }\n if (${t.enableLod}) {\n ivec2 lodIndexCoord = ivec2((index >> 2) & 4095, index >> 14);\n uint splatIndex = texelFetch(${t.lodIndices}, lodIndexCoord, 0)[index & 3];\n ${e.index} = int(splatIndex);\n } else {\n ${e.index} = index;\n }\n } else {\n int start = ${t.showLodPage} << 16;\n if (index >= 65536) {\n return;\n }\n ${e.index} = start + index;\n }\n `)}).outputs.index}function Zl(t,e,n,a){return G({inTypes:{gsplat:Y,rgba:Vl,index:"int",enableLod:"bool"},outTypes:{gsplat:Y},inputs:{gsplat:t,rgba:e,index:n,enableLod:a},statements:({inputs:t,outputs:e})=>W(`\n ${e.gsplat} = ${t.gsplat};\n if (!${t.enableLod} && (${t.index} >= 0) && (${t.index} < ${t.rgba}.count)) {\n ${e.gsplat}.rgba = texelFetch(${t.rgba}.texture, splatTexCoord(${t.index}), 0);\n }\n `)}).outputs.gsplat}const tu=(()=>{const e=new t.DataTexture(new Uint32Array(16384),4096,1,t.RGBAIntegerFormat,t.UnsignedIntType);return e.internalFormat="RGBA32UI",e.needsUpdate=!0,e})(),eu=class e{constructor({extSplats:e,covSplats:n}={}){if(this.time=0,this.deltaTime=0,this.viewToWorld=new t.Matrix4,this.renderOrigin=new t.Vector3,this.viewDirection=new t.Vector3,this.maxSplats=0,this.numSplats=0,this.target=null,this.mapping=[],this.version=-1,this.mappingVersion=-1,this.readback=null,this.readbackSplats=[],!Fn)throw new Error("Spark requires THREE.js r179 or above");this.extSplats=e??!0,this.covSplats=n??!1}dispose(){this.target&&(this.target.dispose(),this.target=null)}getTextures(){return this.target?this.target.textures:e.emptyTextures}generateMapping(t){let e=0;const n=t.map((t=>{const n=e,a=Math.ceil(t/i)*i;return e+=a,{base:n,count:t}}));return{maxSplats:e,mapping:n}}ensureGenerate({maxSplats:e}){if(this.target&&(e??1)<=this.maxSplats)return!1;this.dispose();const n=ea(e??1),{width:a,height:s,depth:r}=n;if(this.maxSplats=n.maxSplats,this.target=new t.WebGLArrayRenderTarget(a,s,r,{depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1,magFilter:t.NearestFilter,minFilter:t.NearestFilter,format:t.RGBAIntegerFormat,type:t.UnsignedIntType}),this.target.scissorTest=!0,this.extSplats){const e=this.target.texture.clone(),n=this.target.texture.clone();n.format=t.RGBAFormat,n.type=t.UnsignedByteType,n.internalFormat="RGBA8",this.target.textures=[this.target.texture,e,n]}else{const e=this.target.texture.clone();e.format=t.RGBAFormat,e.type=t.UnsignedByteType,e.internalFormat="RGBA8",this.target.textures=[this.target.texture,e]}return!0}saveRenderState(t){return{target:t.getRenderTarget(),activeCubeFace:t.getActiveCubeFace(),activeMipmapLevel:t.getActiveMipmapLevel(),xrEnabled:t.xr.enabled,autoClear:t.autoClear}}resetRenderState(t,e){t.setRenderTarget(e.target,e.activeCubeFace,e.activeMipmapLevel),t.xr.enabled=e.xrEnabled,t.autoClear=e.autoClear}prepareProgramMaterial(t,a){const s=t??a;if(!s)throw new Error("Either generator or covGenerator must be provided");let r=e.generatorProgram.get(s);if(!r){const i=O({index:"int"},{},(({index:s},r,{roots:i})=>{if(t&&(t.inputs.index=s),a&&(a.inputs.index=s),this.extSplats)if(this.covSplats)if(a){const t=Gt(a.outputs.covsplat);i.push(t)}else{if(!t)throw new Error("Generator must be provided");{const e=rt(t.outputs.gsplat),n=Gt(e);i.push(n)}}else{if(!t)throw new Error("Generator must be provided");{const e=Ot(t.outputs.gsplat);i.push(e)}}else{if(this.covSplats){let s;if(a)s=a.outputs.covsplat;else{if(!t)throw new Error("Generator must be provided");s=rt(t.outputs.gsplat)}const r=ss(Ct(s).outputs.center,e.viewCenterUniform),o=rs(Ct(s).outputs.opacity,R("float",.5));s=Lt({covsplat:s,center:r,opacity:o});const l=Nt(s,R("vec4",[0,1,n,9]));i.push(l)}else{if(!t)throw new Error("Generator must be provided");{const a=ss(it(t.outputs.gsplat).outputs.center,e.viewCenterUniform),s=rs(it(t.outputs.gsplat).outputs.opacity,R("float",.5)),r=ot({gsplat:t.outputs.gsplat,center:a,opacity:s}),o=Bt(r,R("vec4",[0,1,n,9]));i.push(o)}}if(!t)throw new Error("Generator must be provided")}if(t){const n=Ht(t.outputs.gsplat,e.viewCenterUniform,e.viewDirUniform,e.sortRadialUniform);i.push(n)}if(a){const t=Wt(a.outputs.covsplat,e.viewCenterUniform,e.viewDirUniform,e.sortRadialUniform);i.push(t)}}));r=new _a({graph:i,inputs:{index:"_index"},outputs:{},template:this.extSplats?e.programExtTemplate:e.programTemplate}),e.generatorProgram.set(s,r)}Object.assign(r.uniforms,{targetLayer:{value:0},targetBase:{value:0},targetCount:{value:0}});const i=r.prepareMaterial();return e.fullScreenQuad.material=i,{program:r,material:i}}generate({generator:t,covGenerator:n,base:a,count:s,renderer:r}){if(!this.target)throw new Error("Target must be initialized with ensureGenerate");if(a+s>this.maxSplats)throw new Error("Base + count exceeds maxSplats");const{program:l,material:u}=this.prepareProgramMaterial(t,n);l.update();const c=this.saveRenderState(r),p=Math.ceil((a+s)/i)*i,d=4194304;for(u.uniforms.targetBase.value=a,u.uniforms.targetCount.value=s;a<p;){const t=Math.floor(a/d);u.uniforms.targetLayer.value=t;const n=t*d,s=Math.floor((a-n)/i),l=Math.min(o,Math.ceil((p-n)/i));this.target.scissor.set(0,s,i,l-s),r.setRenderTarget(this.target,t),r.xr.enabled=!1,r.autoClear=!1,e.fullScreenQuad.render(r),a+=i*(l-s)}return this.resetRenderState(r,c),{nextBase:p}}prepareGenerate({renderer:t,scene:n,timer:a,camera:s,sortRadial:r,renderSize:i,previous:o,lodInstances:l}){var u;s.getWorldPosition(this.renderOrigin),this.viewToWorld.copy(s.matrixWorld).setPosition(0,0,0),s.getWorldDirection(this.viewDirection),e.viewCenterUniform.value.set(0,0,0),e.viewDirUniform.value.copy(this.viewDirection),e.sortRadialUniform.value=r,this.time=a.getElapsed(),this.deltaTime=a.getDelta();const c=[];n.traverse((t=>{t instanceof Eo&&(s.layers&&!s.layers.test(t.layers)||c.push(t))}));const p=new Set;n.traverseVisible((t=>{if(t instanceof To){let e=t.parent;for(;null!=e&&!(e instanceof Yl);)e=e.parent;null==e&&p.add(t)}}));const d=Array.from(p);for(const e of c)try{null==(u=e.frameUpdate)||u.call(e,{renderer:t,object:e,time:this.time,deltaTime:this.deltaTime,viewToWorld:this.viewToWorld,renderOrigin:this.renderOrigin,camera:s,renderSize:i,globalEdits:d,lodIndices:l&&e instanceof Yl?l.get(e):void 0})}catch(w){e.generator=void 0,e.covGenerator=void 0,e.generatorError=w}const h=[];n.traverseVisible((t=>{t instanceof Eo&&(s.layers&&!s.layers.test(t.layers)||h.push(t))}));const x=h.map((t=>t.numSplats)),{maxSplats:f,mapping:m}=this.generateMapping(x),y=o.mapping.reduce(((t,e)=>(t.set(e.node,e),t)),new Map);this.mapping=[],this.numSplats=0,m.forEach((({base:t,count:e},n)=>{const a=h[n],s=y.get(a);s&&s.count!==a.numSplats&&a.updateMappingVersion();const{generator:r,covGenerator:i}=a;if((r||i)&&e>0){const{version:n,mappingVersion:s}=a;this.mapping.push({node:a,generator:r,covGenerator:i,version:n,mappingVersion:s,base:t,count:e}),this.numSplats=Math.max(this.numSplats,t+e)}}));const{splatsUpdated:g,mappingUpdated:v}=o.checkVersions(this.mapping);return this.version=o.version+(g?1:0),this.mappingVersion=o.mappingVersion+(v?1:0),{sameMapping:!v,version:this.version,mappingVersion:this.mappingVersion,visibleGenerators:h,generate:()=>{this.ensureGenerate({maxSplats:f});for(const{node:e,base:n,count:a}of this.mapping){const{generator:s,covGenerator:r}=e;(s||r)&&a>0&&this.generate({generator:s,covGenerator:r,base:n,count:a,renderer:t})}},readback:async()=>{const e=this.getTextures();0===this.readbackSplats.length&&(this.readbackSplats=[new Pe({value:e[0],key:"extSplats"}),new Pe({value:e[1],key:"extSplats"})]),this.readbackSplats[0].value=e[0],this.readbackSplats[1].value=e[1],this.readback||(this.readback=new mo({renderer:t}));const n=this.readback,a=this.extSplats?8:4,s=n.ensureBuffer(this.numSplats*a,new Uint32Array(0)),r=O({index:"int"},{rgba8:"vec4"},(({index:t})=>({rgba8:new B({inTypes:{index:"int",extSplats1:"usampler2DArray",extSplats2:"usampler2DArray"},outTypes:{rgba8:"vec4"},inputs:{index:t,extSplats1:this.readbackSplats[0],extSplats2:this.readbackSplats[1]},statements:({inputs:t,outputs:e})=>this.extSplats?W(`\n int indexDiv8 = ${t.index} >> 3;\n ivec3 coord = splatTexCoord(indexDiv8);\n uvec4 packedData;\n if ((${t.index} & 4) == 0) {\n packedData = texelFetch(${t.extSplats1}, coord, 0);\n } else {\n packedData = texelFetch(${t.extSplats2}, coord, 0);\n }\n\n int indexMod4 = ${t.index} & 3;\n uint data = (indexMod4 == 0) ? packedData.x\n : (indexMod4 == 1) ? packedData.y\n : (indexMod4 == 2) ? packedData.z\n : packedData.w;\n ${e.rgba8} = uintToVec4(data);\n `):W(`\n int indexDiv4 = ${t.index} >> 2;\n ivec3 coord = splatTexCoord(indexDiv4);\n uvec4 packedData = texelFetch(${t.extSplats1}, coord, 0);\n\n int indexMod4 = ${t.index} & 3;\n uint data = (indexMod4 == 0) ? packedData.x\n : (indexMod4 == 1) ? packedData.y\n : (indexMod4 == 2) ? packedData.z\n : packedData.w;\n ${e.rgba8} = uintToVec4(data);\n `)}).outputs.rgba8})));return await n.renderReadback({reader:r,count:this.numSplats*a,renderer:t,readback:s})}}}checkVersions(t){if(this.mapping.length!==t.length)return{splatsUpdated:!0,mappingUpdated:!0};const e=this.mapping.some(((e,n)=>{const a=t[n];return e.node!==a.node||e.base!==a.base||e.count!==a.count||e.mappingVersion!==a.mappingVersion}));if(e)return{splatsUpdated:!0,mappingUpdated:!0};const n=this.mapping.some(((e,n)=>e.version!==t[n].version));return{splatsUpdated:n,mappingUpdated:e}}};eu.viewCenterUniform=new xe({value:new t.Vector3}),eu.viewDirUniform=new xe({value:new t.Vector3}),eu.sortRadialUniform=new ae({value:!0}),eu.emptyTexture=(()=>{const{width:e,height:n,depth:a,maxSplats:s}=ea(1),r=new Uint32Array(4*s),i=new t.DataArrayTexture(r,e,n,a);return i.format=t.RGBAIntegerFormat,i.type=t.UnsignedIntType,i.internalFormat="RGBA32UI",i.needsUpdate=!0,i})(),eu.emptyTextures=[eu.emptyTexture,eu.emptyTexture],eu.programExtTemplate=new Ma(xo().computeUvec4x2Vec4Template),eu.programTemplate=new Ma(xo().computeUvec4Vec4Template),eu.generatorProgram=new WeakMap,eu.fullScreenQuad=new e.FullScreenQuad(new t.RawShaderMaterial({visible:!1}));let nu=eu;class au extends t.InstancedBufferGeometry{constructor(){super(),this.setAttribute("position",new t.BufferAttribute(su,3)),this.setIndex(new t.BufferAttribute(ru,1))}}const su=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),ru=new Uint16Array([0,1,2,0,2,3]),iu=class e extends t.Mesh{constructor(n){if(!n)throw new Error("SparkRenderer options are required");if(!n.renderer)throw new Error("renderer is required in SparkRenderer options");const a=e.makeUniforms();Object.assign(a,n.extraUniforms??{});const s=xo(),r=n.premultipliedAlpha??!0,i=new au,o=new t.ShaderMaterial({glslVersion:t.GLSL3,vertexShader:n.vertexShader??s.splatVertex,fragmentShader:n.fragmentShader??s.splatFragment,uniforms:a,premultipliedAlpha:r,transparent:n.transparent??!0,depthTest:n.depthTest??!0,depthWrite:n.depthWrite??!1,side:t.DoubleSide,allowOverride:!1});super(i,o),this.renderSize=new t.Vector2,this.lastFrame=-1,this.updateTimeoutId=-1,this.orderingTexture=null,this.maxSplats=0,this.activeSplats=0,this.accumulators=[],this.sorting=!1,this.sortDirty=!1,this.lastSortTime=0,this.sortWorker=null,this.sortTimeoutId=-1,this.sortedCenter=(new t.Vector3).setScalar(Number.NEGATIVE_INFINITY),this.sortedDir=(new t.Vector3).setScalar(0),this.accumToCamera=new t.Matrix4,this.accumToCameraScale=new t.Vector3,this.renderCameraToWorld=new t.Matrix4,this.renderCameraOrigin=new t.Vector3,this.lodCameraToWorld=new t.Matrix4,this.lodCameraScale=new t.Vector3,this.lodViewToObject=new t.Matrix4,this.lodMeshOrigin=new t.Vector3,this.readback32=new Uint32Array(0),this.lastLodRaycastTime=0,this.lodWorker=null,this.lodMeshes=[],this.lodDirty=!1,this.lodIds=new Map,this.lodIdToSplats=new Map,this.lodInitQueue=[],this.lodInstances=new Map,this.lodUpdates=[],this.lastTraverseTime=0,this.pagerId=0,this.superXY=1,this.flushAfterGenerate=!1,this.flushAfterRead=!1,this.readPause=1,this.sortPause=0,this.sortDelay=0,this.pageSizeWarning=!1,this.material=o,this.uniforms=a,this.frustumCulled=!1,this.renderer=n.renderer,this.onDirty=n.onDirty,this.dirty=!0,this.autoUpdate=n.autoUpdate??!0,this.preUpdate=n.preUpdate??!0,this.maxStdDev=n.maxStdDev??Math.sqrt(8),this.minPixelRadius=n.minPixelRadius??0,this.maxPixelRadius=n.maxPixelRadius??512,this.accumExtSplats=n.accumExtSplats??!1,this.covSplats=n.covSplats??!1,this.minAlpha=n.minAlpha??1/255*.5,this.enable2DGS=n.enable2DGS??!1,this.preBlurAmount=n.preBlurAmount??0,this.blurAmount=n.blurAmount??.3,this.focalDistance=n.focalDistance??0,this.apertureAngle=n.apertureAngle??0,this.falloff=n.falloff??1,this.clipXY=n.clipXY??1.4,this.focalAdjustment=n.focalAdjustment??1,this.sortRadial=n.sortRadial??!0,this.minSortIntervalMs=n.minSortIntervalMs??0,this.enableLod=n.enableLod??!0,this.enableDriveLod=n.enableDriveLod??this.enableLod,this.enableLodFetching=n.enableLodFetching??!0,this.lodSplatCount=n.lodSplatCount,this.lodSplatScale=n.lodSplatScale??1,this.lodRenderScale=n.lodRenderScale??1,this.lodInflate=n.lodInflate??!1,this.lodTraverseMode=n.lodTraverseMode??"standard",this.pagedExtSplats=n.pagedExtSplats??!1;const l=na()?ia()?96:128:256;this.maxPagedSplats=n.maxPagedSplats??65536*l,this.numLodFetchers=n.numLodFetchers??3,this.behindFoveate=n.behindFoveate??.2,this.coneFov0=n.coneFov0??90,this.coneFov=n.coneFov??120,this.coneFoveate=n.coneFoveate??.4,this.lodRaycast=void 0===n.lodRaycast?na()?1e4:25e3:n.lodRaycast,this.lodRaycastIntervalMs=n.lodRaycastIntervalMs??500,this.timer=n.timer??new t.Timer,this.ownsTimer=!!n.timer;const u={extSplats:this.accumExtSplats,covSplats:this.covSplats};this.display=new nu(u),this.current=this.display,this.accumulators.push(new nu(u)),this.accumulators.push(new nu(u));const c=this.renderer.getContext().getExtension("WEBGL_provoking_vertex");if(c&&c.provokingVertexWEBGL(c.FIRST_VERTEX_CONVENTION_WEBGL),n.target){const{width:e,height:a,doubleBuffer:s,superXY:r,...i}=n.target,o=Math.max(1,Math.min(4,r??1));if(e*o>8192||a*o>8192)throw new Error("Target size too large");this.superXY=o;const l=e*o,u=a*o,c={format:t.RGBAFormat,type:t.UnsignedByteType,colorSpace:t.SRGBColorSpace,...i};this.target=new t.WebGLRenderTarget(l,u,c),s&&(this.backTarget=new t.WebGLRenderTarget(l,u,c))}}static makeUniforms(){return{renderSize:{value:new t.Vector2},near:{value:.1},far:{value:1e3},renderToViewQuat:{value:new t.Quaternion},renderToViewPos:{value:new t.Vector3},renderToViewBasis:{value:new t.Matrix3},renderToViewOffset:{value:new t.Vector3},maxStdDev:{value:1},minPixelRadius:{value:0},maxPixelRadius:{value:512},minAlpha:{value:1/255*.5},enable2DGS:{value:!1},lodInflate:{value:!1},preBlurAmount:{value:0},blurAmount:{value:.3},focalDistance:{value:0},apertureAngle:{value:0},falloff:{value:1},clipXY:{value:1.4},focalAdjustment:{value:1},encodeLinear:{value:!1},ordering:{type:"t",value:e.emptyOrdering},enableExtSplats:{value:!1},enableCovSplats:{value:!1},extSplats:{type:"t",value:nu.emptyTexture},extSplats2:{type:"t",value:nu.emptyTexture},time:{value:0},deltaTime:{value:0},debugFlag:{value:!1}}}dispose(){if(this.viewerDisposed)return;var t;this.viewerDisposed=!0,this.autoUpdate=!1,this.sortDirty=!1,clearTimeout(this.sortTimeoutId),this.sortTimeoutId=-1,null==(t=super.dispose)||t.call(this),this.target&&(this.target.dispose(),this.target=void 0),this.backTarget&&(this.backTarget.dispose(),this.backTarget=void 0),this.orderingTexture&&(this.orderingTexture.dispose(),this.orderingTexture=null);const e=new Set;e.add(this.display),e.add(this.current);for(const a of this.accumulators)e.add(a);for(const a of e)a.dispose();const n=Array.from(this.lodInstances.values());this.lodInstances.clear();for(const a of n)a.texture.dispose();this.sortWorker&&(this.sortWorker.dispose(),this.sortWorker=null),this.lodWorker&&(this.lodWorker.dispose(),this.lodWorker=null),this.pager&&(this.pager.dispose(),this.pager=void 0)}setDirty(){var t;this.dirty||(this.dirty=!0,null==(t=this.onDirty)||t.call(this))}onBeforeRender(n,a,s){var r;const i=e.sparkOverride??this,o=n.info.render.frame,l=o!==i.lastFrame;if(i.lastFrame=o,i.autoUpdate&&l){const t=i.preUpdate&&!n.xr.isPresenting,e=n.xr.isPresenting?n.xr.getCamera():s;t?i.updateInternal({scene:a,camera:e,autoUpdate:!0}):-1===i.updateTimeoutId&&(i.updateTimeoutId=setTimeout((()=>{i.updateTimeoutId=-1,i.updateInternal({scene:a,camera:e,autoUpdate:!0})}),1))}const u=n.getRenderTarget(),c=null==(p=u)?void 0:p.isXRRenderTarget;var p;if(u){if(i.renderSize.set(u.width,u.height),c&&1===i.renderSize.x&&1===i.renderSize.y){const t=null==(r=n.xr.getSession())?void 0:r.renderState.baseLayer;t&&(i.renderSize.x=t.framebufferWidth,i.renderSize.y=t.framebufferHeight)}}else n.getDrawingBufferSize(i.renderSize);this.uniforms.renderSize.value.copy(i.renderSize);const d=s;this.uniforms.near.value=d.near,this.uniforms.far.value=d.far;this.geometry.instanceCount=i.activeSplats;const h=this.renderCameraToWorld.copy(s.matrixWorld).setPosition(this.renderCameraOrigin.setFromMatrixPosition(s.matrixWorld).sub(i.display.renderOrigin)),x=this.accumToCamera.copy(h).invert();x.decompose(this.uniforms.renderToViewPos.value,this.uniforms.renderToViewQuat.value,this.accumToCameraScale),this.uniforms.renderToViewBasis.value.setFromMatrix4(x),this.uniforms.maxStdDev.value=i.maxStdDev,this.uniforms.minPixelRadius.value=i.minPixelRadius,this.uniforms.maxPixelRadius.value=i.maxPixelRadius,this.uniforms.minAlpha.value=i.minAlpha,this.uniforms.enable2DGS.value=i.enable2DGS,this.uniforms.lodInflate.value=i.lodInflate,this.uniforms.preBlurAmount.value=i.preBlurAmount,this.uniforms.blurAmount.value=i.blurAmount,this.uniforms.focalDistance.value=i.focalDistance,this.uniforms.apertureAngle.value=i.apertureAngle,this.uniforms.falloff.value=i.falloff,this.uniforms.clipXY.value=i.clipXY,this.uniforms.focalAdjustment.value=i.focalAdjustment;const f=null===u?n.outputColorSpace:c?u.texture.colorSpace:t.ColorManagement.workingColorSpace;if(this.uniforms.encodeLinear.value=f!==t.SRGBColorSpace,this.uniforms.ordering.value=i.orderingTexture??e.emptyOrdering,this.uniforms.enableExtSplats.value=this.display.extSplats,this.uniforms.enableCovSplats.value=this.display.covSplats,this.display.extSplats){const t=i.display.getTextures();this.uniforms.extSplats.value=t[0],this.uniforms.extSplats2.value=t[1]}else{const t=i.display.getTextures();this.uniforms.extSplats.value=t[0],this.uniforms.extSplats2.value=t[0]}this.uniforms.time.value=i.display.time,this.uniforms.deltaTime.value=i.display.deltaTime,this.uniforms.debugFlag.value=performance.now()/1e3%2<1,i.dirty=!1}clearSplats(){this.activeSplats=0,this.display.numSplats=0,this.setDirty()}async update({scene:t,camera:e}){await this.updateInternal({scene:t,camera:e,autoUpdate:!1})}async updateInternal({scene:e,camera:n,autoUpdate:a}){if(this.viewerDisposed)return;const s=this.renderer;this.ownsTimer&&this.timer.update();const r=n.getWorldPosition(new t.Vector3),i=n.getWorldDirection(new t.Vector3),o=r.distanceTo(this.sortedCenter)>.001||i.dot(this.sortedDir)<.999,l=this.accumulators.pop();if(!l)throw new Error("No next accumulator");if(l===this.current)throw new Error("Next accumulator is the same as the current accumulator");const{version:u,mappingVersion:c,visibleGenerators:p,generate:d}=l.prepareGenerate({renderer:s,scene:e,timer:this.timer,camera:n,sortRadial:this.sortRadial??!0,renderSize:this.renderSize,previous:this.current,lodInstances:this.enableLod?this.lodInstances:void 0});let h=!0;const x=o||u!==this.current.version;if(a&&!x&&(h=!1),c!==this.display.mappingVersion&&this.sorting&&(h=!1),h){if(d(),this.flushAfterGenerate){s.getContext().flush()}this.display.mappingVersion===l.mappingVersion?(this.accumulators.push(this.display),this.display=l):this.display!==this.current&&this.accumulators.push(this.current),this.current=l,this.sortDirty=!0,this.setDirty()}else this.accumulators.push(l);this.enableDriveLod&&this.driveLod({visibleGenerators:p,camera:n,scene:e}),await this.driveSort()}async driveSort(){if(this.viewerDisposed||this.sorting||!this.sortDirty)return;-1!==this.sortTimeoutId&&(clearTimeout(this.sortTimeoutId),this.sortTimeoutId=-1);const e=performance.now(),n=this.lastSortTime?this.lastSortTime+this.minSortIntervalMs:e;if(e<n)this.sortTimeoutId=setTimeout((()=>{this.sortTimeoutId=-1,this.driveSort()}),n-e);else{this.sorting=!0;try{if(this.sortDirty=!1,this.lastSortTime=e,this.readPause>0&&await new Promise((t=>setTimeout(t,this.readPause))),this.viewerDisposed)return;const n=this.current;this.sortedCenter.copy(n.renderOrigin),this.sortedDir.copy(n.viewDirection);const{numSplats:a,maxSplats:s}=n,r=Math.max(1,Math.ceil(s/16384)),i=16384*r;this.maxSplats=Math.max(this.maxSplats,i);const o=new Uint32Array(this.maxSplats),l=mo.ensureBuffer(s,this.readback32);if(this.readback32=l,await this.readbackDepth({current:n,renderer:this.renderer,numSplats:a,readback:l}),this.viewerDisposed)return;if(this.sortPause>0&&await new Promise((t=>setTimeout(t,this.sortPause))),this.viewerDisposed)return;this.sortWorker||(this.sortWorker=new gl);const u=await this.sortWorker.call("sortSplats32",{numSplats:a,readback:l,ordering:o});if(this.viewerDisposed)return;if(this.sortDelay>0&&await new Promise((t=>setTimeout(t,this.sortDelay))),this.viewerDisposed)return;if(this.readback32=u.readback,this.activeSplats=u.activeSplats,this.orderingTexture&&r>this.orderingTexture.image.height&&(this.orderingTexture.dispose(),this.orderingTexture=null),this.orderingTexture){const t=this.renderer;t.properties.has(this.orderingTexture)?Sa(t,this.orderingTexture,4096,r,u.ordering):this.orderingTexture.needsUpdate=!0}else{const e=new t.DataTexture(u.ordering,4096,r,t.RGBAIntegerFormat,t.UnsignedIntType);e.internalFormat="RGBA32UI",e.needsUpdate=!0,this.orderingTexture=e}this.current.mappingVersion===n.mappingVersion&&this.current.mappingVersion!==this.display.mappingVersion&&(this.accumulators.push(this.display),this.display=this.current),this.sorting=!1,this.setDirty(),this.driveSort()}catch(a){if(!this.viewerDisposed)throw a}finally{this.viewerDisposed&&(this.sorting=!1)}}}ensureLodWorker(){return this.lodWorker||(this.lodWorker=new gl),this.lodWorker}defaultSplatTarget(){return sa()?5e5:oa()?75e4:aa()?1e6:ia()?15e5:25e5}driveLod({visibleGenerators:e,camera:n,scene:a}){if(this.viewerDisposed)return;var s,r;const i=this.defaultSplatTarget(),o=(this.lodSplatCount??i)*this.lodSplatScale;let l=0;if(n instanceof t.PerspectiveCamera){const t=Math.tan(.5*n.fov*Math.PI/180);l=2*t/this.renderSize.y}else if(n instanceof t.OrthographicCamera){const t=(n.top-n.bottom)/n.zoom,e=(n.right-n.left)/n.zoom,a=t/Math.max(1,this.renderSize.y),s=e/Math.max(1,this.renderSize.x);l=Math.min(s,a)}l*=this.lodRenderScale;const u=new t.Vector3,c=new t.Quaternion;this.current.viewToWorld.decompose(u,c,new t.Vector3);const p=this.lodPosOverride??this.current.renderOrigin;if(this.lodPosOverride&&u.copy(this.lodPosOverride).sub(this.current.renderOrigin),this.lodQuatOverride&&c.copy(this.lodQuatOverride).normalize(),this.lastLod){this.lastLod.pixelScaleLimit===l&&this.lastLod.maxSplats===o||(this.lodDirty=!0);const t=p.distanceTo(this.lastLod.pos),e=Math.max(0,1-t/1),n=c.dot(this.lastLod.quat);e*Math.max(0,1-(1-n)/.01)<.999&&(this.lodDirty=!0)}const d=this.enableLod?e.filter((t=>{var e,n;return t instanceof Yl&&((null==(e=t.packedSplats)?void 0:e.lodSplats)||(null==(n=t.extSplats)?void 0:n.lodSplats)||t.paged)&&!1!==t.enableLod})):[],h=d.some((t=>t.paged));(this.lodMeshes.length!==d.length||d.some(((t,e)=>t!==this.lodMeshes[e].mesh||t.version>this.lodMeshes[e].version)))&&(this.lodDirty=!0),this.lodMeshes=d.map((t=>({mesh:t,version:t.version+1}))),this.lodInitQueue=[];const x=performance.now();for(const t of d){const e=(null==(s=t.packedSplats)?void 0:s.lodSplats)??(null==(r=t.extSplats)?void 0:r.lodSplats)??t.paged;if(e){const t=this.lodIds.get(e);t?t.lastTouched=x:this.lodInitQueue.push(e)}}this.ensureLodWorker().tryExclusive((async e=>{try{if(this.viewerDisposed)return;if(h&&!this.pager){this.pager=new Hl({renderer:this.renderer,extSplats:this.pagedExtSplats,maxSplats:this.maxPagedSplats,numFetchers:this.numLodFetchers});const{lodId:t}=await e.call("newLodTree",{capacity:this.pager.maxSplats});if(this.viewerDisposed)return;this.pagerId=t}if(this.pager)for(const{mesh:t}of this.lodMeshes)t.paged&&!t.paged.pager&&(t.paged.pager=this.pager);if(this.lodInitQueue.length>0){const t=this.lodInitQueue;for(this.lodInitQueue=[];t.length>0;){const n=t.shift();if(n){if(await this.initLodTree(e,n),this.viewerDisposed)return;this.lodDirty=!0}}}if(this.pager){const t=this.pager.consumeLodTreeUpdates();for(const{splats:e,page:n,chunk:a,numSplats:s,lodTree:r}of t){const t=this.lodIds.get(e);t&&(r&&0===a&&(t.rootPage=n),this.lodUpdates.push({lodId:t.lodId,pageBase:n*this.pager.pageSplats,chunkBase:a*this.pager.pageSplats,count:s,lodTreeData:r}))}}if(this.lodUpdates.length>0){const t=this.lodUpdates;if(this.lodUpdates=[],await e.call("updateLodTrees",{ranges:t}),this.viewerDisposed)return;this.lodDirty=!0}if(this.lodDirty){const n=performance.now(),a=new t.Vector3;if(this.lastLod){const t=Math.max(1,n-this.lastLod.timestamp);a.copy(p).sub(this.lastLod.pos).multiplyScalar(this.lastTraverseTime/t)}if(this.lastLod={pos:p.clone(),quat:c,pixelScaleLimit:l,maxSplats:o,timestamp:n},this.lodDirty=!1,await this.updateLodInstances(e,a,d,o,this.lastLod.pos,u,c,this.current.renderOrigin,l),this.viewerDisposed)return;this.currentLod=this.lastLod,this.setDirty()}await this.cleanupLodTrees(e)}catch(n){if(!this.viewerDisposed)throw n}}))}async initLodTree(t,e){if(e instanceof bl||e instanceof El){const{lodId:n}=await t.call("initLodTree",{numSplats:e.numSplats??0,lodTree:e.extra.lodTree.slice()});if(this.viewerDisposed)return;this.lodIds.set(e,{lodId:n,lastTouched:performance.now()}),this.lodIdToSplats.set(n,e)}else{const{lodId:n}=await t.call("newSharedLodTree",{lodId:this.pagerId});if(this.viewerDisposed)return;this.lodIds.set(e,{lodId:n,lastTouched:performance.now()}),this.lodIdToSplats.set(n,e)}}async updateLodInstances(e,n,a,s,r,i,o,l,u){const c=new Map,p=this.lodCameraToWorld.compose(i,o,this.lodCameraScale.setScalar(1)),d=a.reduce(((t,e)=>{var n,a;c.set(e.uuid,e);const s=this.lodViewToObject.copy(e.matrixWorld).setPosition(this.lodMeshOrigin.setFromMatrixPosition(e.matrixWorld).sub(l)).invert().multiply(p),r=(null==(n=e.packedSplats)?void 0:n.lodSplats)??(null==(a=e.extSplats)?void 0:a.lodSplats)??e.paged;if(!r)return t;const i=this.lodIds.get(r);return i?(this.pager&&e.paged&&void 0===i.rootPage||(t[e.uuid]={instanceId:e.uuid,lodId:i.lodId,rootPage:i.rootPage,viewToObjectCols:s.elements.slice(),lodScale:e.lodScale,behindFoveate:e.behindFoveate??this.behindFoveate,coneFov0:e.coneFov0??this.coneFov0,coneFov:e.coneFov??this.coneFov,coneFoveate:e.coneFoveate??this.coneFoveate}),t):t}),{}),h=performance.now(),x=await e.call("traverseLodTrees",{maxSplats:s,pixelScaleLimit:u,lastPixelLimit:this.lastPixelLimit,instances:d,traverseMode:this.lodTraverseMode});if(this.viewerDisposed)return;this.lastTraverseTime=performance.now()-h;const{keyIndices:f,chunks:m,pixelLimit:y}=x;this.lastPixelLimit=y;const g=Object.values(f).reduce(((t,{numSplats:e})=>t+e),0);if(this.updateLodIndices(c,f),this.pager){this.pager.processUploads();const e=a.map((e=>{if(!e.paged||!this.pager)return null;const n=e.getWorldPosition(new t.Vector3);return{splats:e.paged,distance:n.distanceTo(r)}})).filter((t=>null!==t));!this.pageSizeWarning&&e.length>this.pager.maxPages&&(this.pageSizeWarning=!0),e.sort(((t,e)=>t.distance-e.distance)),this.pager.fetchPriority=e.map((({splats:t})=>({splats:t,chunk:0})));for(const[t,n]of m){const e=this.lodIdToSplats.get(t);e instanceof Ol&&0!==n&&this.pager.fetchPriority.push({splats:e,chunk:n})}this.pager.autoDrive=this.enableLodFetching,this.enableLodFetching&&this.pager.driveFetchers()}if(this.lodRaycast&&performance.now()-this.lastLodRaycastTime>=this.lodRaycastIntervalMs){this.lastLodRaycastTime=performance.now();performance.now();const t=await e.call("traverseLodTrees",{maxSplats:Math.min(this.lodRaycast,Math.round(.1*g)),pixelScaleLimit:u,instances:d,traverseMode:this.lodTraverseMode});if(this.viewerDisposed)return;performance.now();const{keyIndices:n}=t;Object.values(n).reduce(((t,{numSplats:e})=>t+e),0);for(const[e,a]of Object.entries(n)){c.get(e).raycastIndices=a}}}async cleanupLodTrees(t){var e;const n=performance.now();let a=null;for(const[s,r]of this.lodIds.entries())(null==a||r.lastTouched<a.lastTouched)&&(a={splats:s,lastTouched:r.lastTouched,lodId:r.lodId});if(a&&!(a.lastTouched>n-3e3)){this.lodIds.delete(a.splats),this.lodIdToSplats.delete(a.lodId);for(const[t,e]of this.lodInstances.entries())e.lodId===a.lodId&&(e.texture.dispose(),this.lodInstances.delete(t));a.splats instanceof Ol&&(null==(e=this.pager)||e.removeSplats(a.splats)),await t.call("disposeLodTree",{lodId:a.lodId})}}updateLodIndices(e,n){for(const[a,s]of Object.entries(n)){const{lodId:n,numSplats:r,indices:i}=s,o=e.get(a);if(o.paged)o.paged.update(r,i);else{let e=this.lodInstances.get(o);e&&i.length>e.indices.length&&(e.texture.dispose(),e=void 0);const a=Math.ceil(i.length/16384);if(e){e.numSplats=r;const t=this.renderer;t.properties.has(e.texture)&&Sa(t,e.texture,4096,a,i)}else{const s=16384*a;if(i.length!==s)throw new Error("Indices length != capacity");const l=new t.DataTexture(i,4096,a,t.RGBAIntegerFormat,t.UnsignedIntType);l.internalFormat="RGBA32UI",l.needsUpdate=!0,e={lodId:n,numSplats:r,indices:i,texture:l},this.lodInstances.set(o,e)}}o.updateMappingVersion()}}async readbackDepth({current:t,renderer:e,numSplats:n,readback:a}){if(!e)throw new Error("No renderer");if(!t.target)throw new Error("No target");const s=Math.ceil(n/i)*i;if(a.byteLength<4*s)throw new Error(`Readback buffer too small: ${a.byteLength} < ${4*s}`);const r=new Uint8Array(a.buffer),l=this.saveRenderState(e),u=4194304;let c=0;const p=[];for(;c<n;){const a=Math.floor(c/u),s=a*u,l=Math.min(o,Math.ceil((n-s)/i)),d=i*l*4,h=r.subarray(4*s,4*s+d);e.setRenderTarget(t.target,a);const x=e.readRenderTargetPixelsAsync(t.target,0,0,i,l,h,void 0,t.extSplats?2:1);if(p.push(x),this.flushAfterRead){e.getContext().flush()}c+=i*l}return this.resetRenderState(e,l),Promise.all(p).then((()=>a))}saveRenderState(t){return{target:t.getRenderTarget(),xrEnabled:t.xr.enabled,autoClear:t.autoClear}}resetRenderState(t,e){t.setRenderTarget(e.target),t.xr.enabled=e.xrEnabled,t.autoClear=e.autoClear}render(t,n){try{e.sparkOverride=this,this.renderer.render(t,n)}finally{e.sparkOverride=void 0}}renderTarget({scene:t,camera:n}){const a=this.backTarget??this.target;if(!a)throw new Error("No target");const s=this.renderer.getRenderTarget();try{this.renderer.setRenderTarget(a),e.sparkOverride=this,this.renderer.render(t,n)}finally{e.sparkOverride=void 0,this.renderer.setRenderTarget(s)}return a!==this.target&&([this.target,this.backTarget]=[this.backTarget,this.target]),a}async readTarget(){if(!this.target)throw new Error("Must initialize with target");const{width:t,height:e}=this.target,n=t*e*4;(!this.superPixels||this.superPixels.length<n)&&(this.superPixels=new Uint8Array(n));const a=this.superPixels;await this.renderer.readRenderTargetPixelsAsync(this.target,0,0,t,e,a);const{superXY:s}=this;if(1===s)return a;const r=t/s,i=e/s,o=r*i*4;(!this.targetPixels||this.targetPixels.length<o)&&(this.targetPixels=new Uint8Array(o));const l=this.targetPixels,u=s*s;for(let c=0;c<i;c++){const e=c*r;for(let n=0;n<r;n++){const r=n*s;let i=0,o=0,p=0,d=0;for(let e=0;e<s;e++){const n=(c*s+e)*t;for(let t=0;t<s;t++){const e=4*(n+r+t);i+=a[e],o+=a[e+1],p+=a[e+2],d+=a[e+3]}}const h=4*(e+n);l[h]=i/u,l[h+1]=o/u,l[h+2]=p/u,l[h+3]=d/u}}return l}async renderReadTarget({scene:t,camera:e}){return this.renderTarget({scene:t,camera:e}),this.readTarget()}async renderCubeMap({scene:n,worldCenter:a,size:s=256,near:r=.1,far:i=1e3,hideObjects:o=[],update:l=!0,filter:u=!1}){if(!e.cubeRender||e.cubeRender.target.width!==s||e.cubeRender.near!==r||e.cubeRender.far!==i){e.cubeRender&&e.cubeRender.target.dispose();const n=new t.WebGLCubeRenderTarget(s,{format:t.RGBAFormat,type:t.UnsignedByteType,generateMipmaps:u,minFilter:u?t.LinearMipMapLinearFilter:t.LinearFilter,magFilter:t.LinearFilter,colorSpace:u?t.LinearSRGBColorSpace:t.SRGBColorSpace}),a=new t.CubeCamera(r,i,n);e.cubeRender={target:n,cubeCamera:a,near:r,far:i}}const{target:c,cubeCamera:p}=e.cubeRender;p.position.copy(a);const d=new Map;for(const t of o)d.set(t,t.visible),t.visible=!1;if(l){const e=new t.Camera;e.position.copy(a),await this.update({scene:n,camera:e})}try{e.sparkOverride=this,p.update(this.renderer,n)}finally{e.sparkOverride=void 0}for(const[t,e]of d.entries())t.visible=e;return c.texture}async readCubeTargets(){if(!e.cubeRender)throw new Error("No cube render");const t=e.cubeRender.target.texture,n=[],a=[];for(let s=0;s<t.images.length;++s){const{width:r,height:i}=t.images[s],o=new Uint8Array(r*i*4);a.push(o);const l=this.renderer.readRenderTargetPixelsAsync(e.cubeRender.target,0,0,r,i,o,s);n.push(l)}return await Promise.all(n),a}async renderEnvMap({scene:n,worldCenter:a,size:s=256,near:r=.1,far:i=1e3,hideObjects:o=[],update:l=!0}){var u;const c=await this.renderCubeMap({scene:n,worldCenter:a,size:s,near:r,far:i,hideObjects:o,update:l,filter:!0});return e.pmrem||(e.pmrem=new t.PMREMGenerator(this.renderer)),null==(u=e.pmrem)?void 0:u.fromCubemap(c).texture}recurseSetEnvMap(e,n){e.traverse((e=>{if(e instanceof t.Mesh)if(Array.isArray(e.material))for(const a of e.material)a instanceof t.MeshStandardMaterial&&(a.envMap=n);else e.material instanceof t.MeshStandardMaterial&&(e.material.envMap=n)}))}async getLodTreeLevel(t,e,n=!1){var a,s;const r=this.lodInstances.get(t);if(!r)return null;const i=await this.ensureLodWorker().exclusive((async t=>await t.call("getLodTreeLevel",{lodId:r.lodId,level:e})));if(null==(a=t.packedSplats)?void 0:a.lodSplats){const e=t.packedSplats.lodSplats.extractSplats(i.indices,n);return new Yl({packedSplats:e})}if(null==(s=t.extSplats)?void 0:s.lodSplats){const e=t.extSplats.lodSplats.extractSplats(i.indices,n);return new Yl({extSplats:e})}throw new Error("Only LoD-enabled PackedSplats and ExtSplats are supported")}get premultipliedAlpha(){return this.material.premultipliedAlpha}set premultipliedAlpha(t){this.material.premultipliedAlpha!==t&&(this.material.premultipliedAlpha=t,this.material.needsUpdate=!0)}};iu.emptyOrdering=(()=>{const e=new Uint32Array(16384),n=new t.DataTexture(e,4096,1);return n.format=t.RGBAIntegerFormat,n.type=t.UnsignedIntType,n.internalFormat="RGBA32UI",n.needsUpdate=!0,n})(),iu.cubeRender=null,iu.pmrem=null;let ou=iu;var lu=(t=>(t.DUAL_QUATERNION="dual_quaternion",t.LINEAR_BLEND="linear_blend",t))(lu||{});const uu=class e{constructor(e){this.mesh=e.mesh,this.numSplats=e.numSplats??this.mesh.numSplats,this.mode=e.mode??"dual_quaternion";const{width:n,height:a,depth:s,maxSplats:r}=ea(this.numSplats);this.skinData=new Uint16Array(4*r),this.skinTexture=new t.DataArrayTexture(this.skinData,n,a,s),this.skinTexture.format=t.RGBAIntegerFormat,this.skinTexture.type=t.UnsignedShortType,this.skinTexture.internalFormat="RGBA16UI",this.skinTexture.needsUpdate=!0,this.numBones=e.numBones??256,this.boneData=new Float32Array(16*this.numBones),this.boneTexture=new t.DataTexture(this.boneData,4,this.numBones,t.RGBAFormat,t.FloatType),this.boneTexture.internalFormat="RGBA32F",this.boneTexture.needsUpdate=!0,this.boneRestQuatPosScale=Qn(this.numBones,(()=>({quat:new t.Quaternion,pos:new t.Vector3,scale:new t.Vector3}))),"linear_blend"===this.mode?this.boneRestInvMats=Qn(this.numBones,(()=>new t.Matrix4)):this.boneRestInvMats=[],this.uniform=new ne({key:"skinning",type:pu,globals:()=>[du],value:{numSplats:this.numSplats,numBones:this.numBones,skinTexture:this.skinTexture,boneTexture:this.boneTexture}})}modify(t){if("linear_blend"===this.mode)throw new Error("Linear blend skinning requires covSplats=true");return function(t,e){const n=new B({inTypes:{gsplat:Y,skinning:pu},outTypes:{gsplat:Y},globals:()=>[du,hu],inputs:{gsplat:t,skinning:e},statements:({inputs:t,outputs:e})=>{const{skinning:n}=t,{gsplat:a}=e;return W(`\n ${a} = ${t.gsplat};\n if (isGsplatActive(${a}.flags)) {\n applyGsplatSkinning(\n ${n}.numSplats, ${n}.numBones,\n ${n}.skinTexture, ${n}.boneTexture,\n ${a}.index, ${a}.center, ${a}.quaternion\n );\n }\n `)}});return n.outputs.gsplat}(t,this.uniform)}modifyCov(t){return"dual_quaternion"===this.mode?function(t,e){const n=new B({inTypes:{covsplat:J,skinning:pu},outTypes:{covsplat:J},globals:()=>[du,xu],inputs:{covsplat:t,skinning:e},statements:({inputs:t,outputs:e})=>{const{skinning:n}=t,{covsplat:a}=e;return W(`\n ${a} = ${t.covsplat};\n if (isCovSplatActive(${a}.flags)) {\n applyCovSplatDQSkinning(\n ${n}.numSplats, ${n}.numBones,\n ${n}.skinTexture, ${n}.boneTexture,\n ${a}.index, ${a}.center, ${a}.xxyyzz, ${a}.xyxzyz\n );\n }\n `)}});return n.outputs.covsplat}(t,this.uniform):function(t,e){const n=new B({inTypes:{covsplat:J,skinning:pu},outTypes:{covsplat:J},globals:()=>[du,fu],inputs:{covsplat:t,skinning:e},statements:({inputs:t,outputs:e})=>{const{skinning:n}=t,{covsplat:a}=e;return W(`\n ${a} = ${t.covsplat};\n if (isCovSplatActive(${a}.flags)) {\n applyCovSplatLBSkinning(\n ${n}.numSplats, ${n}.numBones,\n ${n}.skinTexture, ${n}.boneTexture,\n ${a}.index, ${a}.center, ${a}.xxyyzz, ${a}.xyxzyz\n );\n }\n `)}});return n.outputs.covsplat}(t,this.uniform)}setRestQuatPos(t,n,a){this.boneRestQuatPosScale[t].quat.copy(n),this.boneRestQuatPosScale[t].pos.copy(a),this.boneRestQuatPosScale[t].scale.copy(e.UNIT_SCALE),"linear_blend"===this.mode&&this.boneRestInvMats[t].compose(a,n,e.UNIT_SCALE).invert(),this.setBoneQuatPos(t,n,a)}getRestQuatPos(t,e,n){e.copy(this.boneRestQuatPosScale[t].quat),n.copy(this.boneRestQuatPosScale[t].pos)}setRestQuatPosScale(t,e,n,a){this.boneRestQuatPosScale[t].quat.copy(e),this.boneRestQuatPosScale[t].pos.copy(n),this.boneRestQuatPosScale[t].scale.copy(a),"linear_blend"===this.mode&&this.boneRestInvMats[t].compose(n,e,a).invert(),this.setBoneQuatPosScale(t,e,n,a)}getRestQuatPosScale(t,e,n,a){e.copy(this.boneRestQuatPosScale[t].quat),n.copy(this.boneRestQuatPosScale[t].pos),a.copy(this.boneRestQuatPosScale[t].scale)}setRestMatrix(t,e){if("linear_blend"!==this.mode)throw new Error("setRestMat only supported for linear blend skinning");this.boneRestInvMats[t].copy(e).invert(),this.setBoneMatrix(t,e)}getRestMatrix(t,e){if("linear_blend"!==this.mode)throw new Error("getRestMat only supported for linear blend skinning");e.copy(this.boneRestInvMats[t]).invert()}setBoneQuatPos(t,n,a){if("dual_quaternion"===this.mode){e.relQuat.copy(this.boneRestQuatPosScale[t].quat).invert(),e.relPos.copy(a).sub(this.boneRestQuatPosScale[t].pos),e.relQuat.multiply(n),e.dual.set(e.relPos.x,e.relPos.y,e.relPos.z,0).multiply(e.relQuat);const s=16*t;this.boneData[s+0]=e.relQuat.x,this.boneData[s+1]=e.relQuat.y,this.boneData[s+2]=e.relQuat.z,this.boneData[s+3]=e.relQuat.w,this.boneData[s+4]=.5*e.dual.x,this.boneData[s+5]=.5*e.dual.y,this.boneData[s+6]=.5*e.dual.z,this.boneData[s+7]=.5*e.dual.w}else this.setBoneQuatPosScale(t,n,a,e.UNIT_SCALE)}setBoneQuatPosScale(t,n,a,s){if("dual_quaternion"===this.mode)throw new Error("setBoneQuatPosScale only supported for linear blend skinning");e.skinMat.compose(a,n,s),this.setBoneMatrix(t,e.skinMat)}setBoneMatrix(t,n){if("linear_blend"!==this.mode)throw new Error("setBoneMatrix only supported for linear blend skinning");e.skinMat.multiplyMatrices(this.boneRestInvMats[t],n);const a=16*t;this.boneData[a+0]=e.skinMat.elements[0],this.boneData[a+1]=e.skinMat.elements[1],this.boneData[a+2]=e.skinMat.elements[2],this.boneData[a+3]=e.skinMat.elements[4],this.boneData[a+4]=e.skinMat.elements[5],this.boneData[a+5]=e.skinMat.elements[6],this.boneData[a+6]=e.skinMat.elements[8],this.boneData[a+7]=e.skinMat.elements[9],this.boneData[a+8]=e.skinMat.elements[10],this.boneData[a+9]=e.skinMat.elements[12],this.boneData[a+10]=e.skinMat.elements[13],this.boneData[a+11]=e.skinMat.elements[14]}setSplatBones(t,e,n){const a=4*t;this.skinData[a+0]=Math.min(255,Math.max(0,Math.round(255*n.x)))+(e.x<<8),this.skinData[a+1]=Math.min(255,Math.max(0,Math.round(255*n.y)))+(e.y<<8),this.skinData[a+2]=Math.min(255,Math.max(0,Math.round(255*n.z)))+(e.z<<8),this.skinData[a+3]=Math.min(255,Math.max(0,Math.round(255*n.w)))+(e.w<<8)}updateBones(){this.boneTexture.needsUpdate=!0,this.mesh.needsUpdate=!0}};uu.UNIT_SCALE=new t.Vector3(1,1,1),uu.relQuat=new t.Quaternion,uu.relPos=new t.Vector3,uu.dual=new t.Quaternion,uu.skinMat=new t.Matrix4;let cu=uu;const pu={type:"GsplatSkinning"},du=j("\n struct GsplatSkinning {\n int numSplats;\n int numBones;\n usampler2DArray skinTexture;\n sampler2D boneTexture;\n };\n"),hu=j("\n void applyGsplatSkinning(\n int numSplats, int numBones,\n usampler2DArray skinTexture, sampler2D boneTexture,\n int splatIndex, inout vec3 center, inout vec4 quaternion\n ) {\n if ((splatIndex < 0) || (splatIndex >= numSplats)) {\n return;\n }\n\n uvec4 skinData = texelFetch(skinTexture, splatTexCoord(splatIndex), 0);\n\n float weights[4];\n weights[0] = float(skinData.x & 0xffu) / 255.0;\n weights[1] = float(skinData.y & 0xffu) / 255.0;\n weights[2] = float(skinData.z & 0xffu) / 255.0;\n weights[3] = float(skinData.w & 0xffu) / 255.0;\n\n uint boneIndices[4];\n boneIndices[0] = (skinData.x >> 8u) & 0xffu;\n boneIndices[1] = (skinData.y >> 8u) & 0xffu;\n boneIndices[2] = (skinData.z >> 8u) & 0xffu;\n boneIndices[3] = (skinData.w >> 8u) & 0xffu;\n\n vec4 quat = vec4(0.0);\n vec4 dual = vec4(0.0);\n for (int i = 0; i < 4; i++) {\n if (weights[i] > 0.0) {\n int boneIndex = int(boneIndices[i]);\n vec4 boneQuat = vec4(0.0, 0.0, 0.0, 1.0);\n vec4 boneDual = vec4(0.0);\n if (boneIndex < numBones) {\n boneQuat = texelFetch(boneTexture, ivec2(0, boneIndex), 0);\n boneDual = texelFetch(boneTexture, ivec2(1, boneIndex), 0);\n }\n\n if ((i > 0) && (dot(quat, boneQuat) < 0.0)) {\n // Flip sign if next blend is pointing in the opposite direction\n boneQuat = -boneQuat;\n boneDual = -boneDual;\n }\n quat += weights[i] * boneQuat;\n dual += weights[i] * boneDual;\n }\n }\n\n // Normalize dual quaternion\n float norm = length(quat);\n quat /= norm;\n dual /= norm;\n vec3 translate = vec3(\n 2.0 * (-dual.w * quat.x + dual.x * quat.w - dual.y * quat.z + dual.z * quat.y),\n 2.0 * (-dual.w * quat.y + dual.x * quat.z + dual.y * quat.w - dual.z * quat.x),\n 2.0 * (-dual.w * quat.z - dual.x * quat.y + dual.y * quat.x + dual.z * quat.w)\n );\n\n center = quatVec(quat, center) + translate;\n quaternion = quatQuat(quat, quaternion);\n }\n");const xu=j("\n void applyCovSplatDQSkinning(\n int numSplats, int numBones,\n usampler2DArray skinTexture, sampler2D boneTexture,\n int splatIndex, inout vec3 center, inout vec3 xxyyzz, inout vec3 xyxzyz\n ) {\n if ((splatIndex < 0) || (splatIndex >= numSplats)) {\n return;\n }\n\n uvec4 skinData = texelFetch(skinTexture, splatTexCoord(splatIndex), 0);\n\n float weights[4];\n weights[0] = float(skinData.x & 0xffu) / 255.0;\n weights[1] = float(skinData.y & 0xffu) / 255.0;\n weights[2] = float(skinData.z & 0xffu) / 255.0;\n weights[3] = float(skinData.w & 0xffu) / 255.0;\n\n uint boneIndices[4];\n boneIndices[0] = (skinData.x >> 8u) & 0xffu;\n boneIndices[1] = (skinData.y >> 8u) & 0xffu;\n boneIndices[2] = (skinData.z >> 8u) & 0xffu;\n boneIndices[3] = (skinData.w >> 8u) & 0xffu;\n\n vec4 quat = vec4(0.0);\n vec4 dual = vec4(0.0);\n for (int i = 0; i < 4; i++) {\n if (weights[i] > 0.0) {\n int boneIndex = int(boneIndices[i]);\n vec4 boneQuat = vec4(0.0, 0.0, 0.0, 1.0);\n vec4 boneDual = vec4(0.0);\n if (boneIndex < numBones) {\n boneQuat = texelFetch(boneTexture, ivec2(0, boneIndex), 0);\n boneDual = texelFetch(boneTexture, ivec2(1, boneIndex), 0);\n }\n\n if ((i > 0) && (dot(quat, boneQuat) < 0.0)) {\n // Flip sign if next blend is pointing in the opposite direction\n boneQuat = -boneQuat;\n boneDual = -boneDual;\n }\n quat += weights[i] * boneQuat;\n dual += weights[i] * boneDual;\n }\n }\n\n // Normalize dual quaternion\n float norm = length(quat);\n quat /= norm;\n dual /= norm;\n vec3 translate = vec3(\n 2.0 * (-dual.w * quat.x + dual.x * quat.w - dual.y * quat.z + dual.z * quat.y),\n 2.0 * (-dual.w * quat.y + dual.x * quat.z + dual.y * quat.w - dual.z * quat.x),\n 2.0 * (-dual.w * quat.z - dual.x * quat.y + dual.y * quat.x + dual.z * quat.w)\n );\n mat3 basis = quaternionToMatrix(quat);\n\n center = quatVec(quat, center) + translate;\n\n mat3 cov = mat3(xxyyzz.x, xyxzyz.x, xyxzyz.y, xyxzyz.x, xxyyzz.y, xyxzyz.z, xyxzyz.y, xyxzyz.z, xxyyzz.z);\n cov = basis * cov * transpose(basis);\n xxyyzz = vec3(cov[0][0], cov[1][1], cov[2][2]);\n xyxzyz = vec3(cov[0][1], cov[0][2], cov[1][2]);\n }\n"),fu=j("\n void applyCovSplatLBSkinning(\n int numSplats, int numBones,\n usampler2DArray skinTexture, sampler2D boneTexture,\n int splatIndex, inout vec3 center, inout vec3 xxyyzz, inout vec3 xyxzyz\n ) {\n if ((splatIndex < 0) || (splatIndex >= numSplats)) {\n return;\n }\n\n uvec4 skinData = texelFetch(skinTexture, splatTexCoord(splatIndex), 0);\n\n float weights[4];\n weights[0] = float(skinData.x & 0xffu) / 255.0;\n weights[1] = float(skinData.y & 0xffu) / 255.0;\n weights[2] = float(skinData.z & 0xffu) / 255.0;\n weights[3] = float(skinData.w & 0xffu) / 255.0;\n\n uint boneIndices[4];\n boneIndices[0] = (skinData.x >> 8u) & 0xffu;\n boneIndices[1] = (skinData.y >> 8u) & 0xffu;\n boneIndices[2] = (skinData.z >> 8u) & 0xffu;\n boneIndices[3] = (skinData.w >> 8u) & 0xffu;\n\n mat3 basis = mat3(0.0);\n vec3 offset = vec3(0.0);\n\n for (int i = 0; i < 4; i++) {\n if (weights[i] > 0.0) {\n int boneIndex = int(boneIndices[i]);\n if (boneIndex < numBones) {\n vec4 v0 = texelFetch(boneTexture, ivec2(0, boneIndex), 0);\n vec4 v1 = texelFetch(boneTexture, ivec2(1, boneIndex), 0);\n vec4 v2 = texelFetch(boneTexture, ivec2(2, boneIndex), 0);\n basis += weights[i] * mat3(v0.x, v0.y, v0.z, v0.w, v1.x, v1.y, v1.z, v1.w, v2.x);\n offset += weights[i] * vec3(v2.y, v2.z, v2.w);\n }\n }\n }\n\n center = basis * center + offset;\n\n mat3 cov = mat3(xxyyzz.x, xyxzyz.x, xyxzyz.y, xyxzyz.x, xxyyzz.y, xyxzyz.z, xyxzyz.y, xyxzyz.z, xxyyzz.z);\n cov = basis * cov * transpose(basis);\n xxyyzz = vec3(cov[0][0], cov[1][1], cov[2][2]);\n xyxzyz = vec3(cov[0][1], cov[0][2], cov[1][2]);\n }\n");const mu={box:new t.Box3(new t.Vector3(-1,-1,-1),new t.Vector3(1,1,1)),density:100,fallDirection:new t.Vector3(-1,-3,1).normalize(),fallVelocity:.02,wanderScale:.04,wanderVariance:2,color1:new t.Color(1,1,1),color2:new t.Color(.5,.5,1),minScale:.001,maxScale:.005,anisoScale:new t.Vector3(1,1,1)},yu={box:new t.Box3(new t.Vector3(-2,-1,-2),new t.Vector3(2,5,2)),density:10,fallDirection:new t.Vector3(0,-1,0),fallVelocity:2,wanderScale:.1,wanderVariance:1,color1:new t.Color(1,1,1),color2:new t.Color(.25,.25,.5),minScale:.005,maxScale:.01,anisoScale:new t.Vector3(.1,1,.1)};const gu=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_RAIN:yu,DEFAULT_SNOW:mu,snowBox:function({box:e,minY:n,numSplats:a,density:s,anisoScale:r,minScale:i,maxScale:o,fallDirection:l,fallVelocity:u,wanderScale:c,wanderVariance:p,color1:d,color2:h,opacity:x,onFrame:f}){const m=((e=e??new t.Box3(new t.Vector3(-1,-1,-1),new t.Vector3(1,1,1))).max.x-e.min.x)*(e.max.y-e.min.y)*(e.max.z-e.min.z);s=s??100,a=a??Math.max(1,Math.min(1e6,Math.round(m*s)));const y=te(i??.001),g=te(o??.005),v=ee(((null==r?void 0:r.clone())??new t.Vector3(1,1,1)).normalize()),w=ee((l??new t.Vector3(0,-1,0)).normalize()),b=te(u??.02),S=te(c??.01),T=te(p??2),_=ee(d??new t.Color(1,1,1)),M=ee(h??new t.Color(.5,.5,1)),k=te(x??1),$=te(0),D=ee(new t.Vector3(0,0,0)),z=ee(e.min),I=ee(e.max),E=te(n??Number.NEGATIVE_INFINITY),A=ss(I,z),F=new Eo({numSplats:a,generator:O({index:"int"},{gsplat:Y},(({index:e})=>{if(!e)throw new Error("index not defined");const n=Si(e),a=Kr(n).outputs.w;let s=hr(n),r=cs(rs(a,R("float",100)));r=Ki(rs(C("float","PI"),r)),r=as(y,rs(r,ss(g,y)));const i=rs(r,v),o=cs(rs(a,R("float",10))),l=cs(a),u=ds(_,M,l),c=rs(u,o),p=Si(Xr({vectorType:"ivec2",x:e,y:R("int",6837)}));let d=hr(p),h=rs(Kr(p).outputs.w,T);h=as($,h),s=as(s,D);const x=ls(s,R("vec3",new t.Vector3(1,1,1)));s=as(z,rs(A,x));const f=R("vec4",new t.Quaternion(0,0,0,1));d=Ki(as(hr(h),d)),d=rs(d,S);let m=as(s,d),w=Kr(m).outputs.y;w=ps(E,w),m=Xr({vector:m,y:w});let b=ot({flags:C("uint","GSPLAT_FLAG_ACTIVE"),index:e,center:m,scales:i,quaternion:f,rgb:c,opacity:k});return b=P.applyGsplat(b),{gsplat:b}}),{globals:()=>[dt]}),update:({object:t,time:e,deltaTime:n})=>{$.value=e,P.update(F);const a=w.value.clone().multiplyScalar(b.value*n);D.value.add(a),t.visible=k.value>0,null==f||f({object:t,time:e,deltaTime:n}),F.updateVersion()}}),P=new zo;return{snow:F,min:z,max:I,minY:E,color1:_,color2:M,opacity:k,fallVelocity:b,wanderVariance:T,wanderScale:S,fallDirection:w,minScale:y,maxScale:g,anisoScale:v}},staticBox:function({box:e,cells:n,dotScale:a,color:s,opacity:r}){n.x=Math.max(1,Math.round(n.x)),n.y=Math.max(1,Math.round(n.y)),n.z=Math.max(1,Math.round(n.z)),r=r??1;const i=n.x*n.y*n.z,o=R("int",n.x),l=R("int",n.y);R("int",n.z);const u=te(0),c=new Eo({numSplats:i,generator:O({index:"int"},{gsplat:Y},(({index:i})=>{if(!i)throw new Error("index is undefined");const c=os(i,o),d=is(i,o),h=os(d,l),x=is(d,l),f=Xr({vectorType:"ivec3",x:c,y:h,z:x}),m=fr(u),y=Xr({vectorType:"ivec2",x:i,y:m}),g=bi(y),v=R("vec3",e.min),w=R("vec3",e.max),b=ss(w,v),S=is(as(hr(f),g),R("vec3",n));let T,_,M;s?(T=R("float",s.r),_=R("float",s.g),M=R("float",s.b)):({r:T,g:_,b:M}=Kr(S).outputs);const k=Xr({vectorType:"vec4",r:T,g:_,b:M,a:R("float",r)}),$=as(v,rs(b,S)),D=hr(R("float",a)),z=R("vec4",new t.Quaternion(0,0,0,1));let I=ot({flags:C("uint","GSPLAT_FLAG_ACTIVE"),index:i,center:$,scales:D,quaternion:z,rgba:k});return I=p.applyGsplat(I),{gsplat:I}}),{globals:()=>[dt]}),update:({time:t})=>{u.value=t,p.update(c),c.updateVersion()}}),p=new zo;return c}},Symbol.toStringTag,{value:"Module"}));function vu(t){return O({gsplat:Y},{gsplat:Y},(({gsplat:e})=>{if(!e)throw new Error("No gsplat input");let n=lt(e);const a=t.applyGsplat(e),s=it(a).outputs.center,r=lt(a),i=jr(s,r),o=Gs(i,R("float",0));n=Hs(o,us(n),n);const l=as(rs(n,R("float",.5)),R("float",.5));return{gsplat:e=ot({gsplat:e,rgb:l})}}))}function wu(t,e,n,a){return O({gsplat:Y},{gsplat:Y},(({gsplat:s})=>{if(!s)throw new Error("No gsplat input");let{center:r}=it(s).outputs;r=t.apply(r);const{z:i}=Kr(r).outputs;let o=Ti(us(i),e,n);return o=Hs(a,ss(R("float",1),o),o),{gsplat:s=ot({gsplat:s,r:o,g:o,b:o})}}))}const bu=Object.freeze(Object.defineProperty({__proto__:null,makeDepthColorModifier:wu,makeNormalColorModifier:vu,setDepthColor:function(t,e,n,a){t.enableWorldToView=!0;const s=R("float",e),r=R("float",n),i=R("bool",a??!1);return t.worldModifier=wu(t.context.worldToView,s,r,i),t.updateGenerator(),{minDepth:s,maxDepth:r,reverse:i}},setWorldNormalColor:function(t){t.enableWorldToView=!0,t.worldModifier=vu(t.context.worldToView),t.updateGenerator()}},Symbol.toStringTag,{value:"Module"})),Su=(e,n)=>{var a,s,r,i;return e.leftIsHand?new t.Vector3:new t.Vector3((null==(a=e.left)?void 0:a.axes[2])??0,((null==(s=e.left)?void 0:s.buttons[0].value)??0)-((null==(r=e.left)?void 0:r.buttons[1].value)??0),(null==(i=e.left)?void 0:i.axes[3])??0)},Tu=(e,n)=>{var a;return e.rightIsHand?new t.Vector3:new t.Vector3((null==(a=e.right)?void 0:a.axes[2])??0,0,0)},_u=(t,e)=>{var n,a;return!t.rightIsHand&&((null==(a=null==(n=t.right)?void 0:n.buttons[0])?void 0:a.pressed)??!1)},Mu=(t,e)=>{var n,a;return!t.rightIsHand&&((null==(a=null==(n=t.right)?void 0:n.buttons[1])?void 0:a.pressed)??!1)};var ku=(t=>(t.w="wrist",t.t0="thumb-metacarpal",t.t1="thumb-phalanx-proximal",t.t2="thumb-phalanx-distal",t.t3="thumb-tip",t.i0="index-finger-metacarpal",t.i1="index-finger-phalanx-proximal",t.i2="index-finger-phalanx-intermediate",t.i3="index-finger-phalanx-distal",t.i4="index-finger-tip",t.m0="middle-finger-metacarpal",t.m1="middle-finger-phalanx-proximal",t.m2="middle-finger-phalanx-intermediate",t.m3="middle-finger-phalanx-distal",t.m4="middle-finger-tip",t.r0="ring-finger-metacarpal",t.r1="ring-finger-phalanx-proximal",t.r2="ring-finger-phalanx-intermediate",t.r3="ring-finger-phalanx-distal",t.r4="ring-finger-tip",t.p0="pinky-finger-metacarpal",t.p1="pinky-finger-phalanx-proximal",t.p2="pinky-finger-phalanx-intermediate",t.p3="pinky-finger-phalanx-distal",t.p4="pinky-finger-tip",t))(ku||{});const $u=Object.keys(ku),Du=$u.length,zu={w:.02,t0:.015,t1:.012,t2:.0105,t3:.0085,i0:.022,i1:.012,i2:.0085,i3:.0075,i4:.0065,m0:.021,m1:.012,m2:.008,m3:.0075,m4:.0065,r0:.019,r1:.011,r2:.0075,r3:.007,r4:.006,p0:.012,p1:.01,p2:.007,p3:.0065,p4:.0055};var Iu=(t=>(t.left="left",t.right="right",t))(Iu||{});const Eu=Object.keys(Iu),Au=/Quest|OculusBrowser|VisionOS|XRBrowser|Pico|Lynx|MagicLeap/i;const Fu=class e{constructor(t){this.lastControllersUpdate=0,this.hands=[],this.renderer=t.renderer,this.xr=navigator.xr,this.mode="initializing",this.onEnterXr=t.onEnterXr,this.onExitXr=t.onExitXr,this.enableHands=t.enableHands??!1,this.controllers=t.controllers,Promise.resolve().then((()=>{var n;if(!this.xr)return void(this.mode="not_supported");if(!t.allowMobileXr&&function(){const t=navigator.userAgent??"";if(Au.test(t))return!1;if(/Android/i.test(t)||/Mobile/i.test(t))return!0;const e=navigator.userAgentData;return!(!e||"boolean"!=typeof e.mobile)&&e.mobile}())return void(this.mode="not_supported");let a,s;if(this.enableHands&&(this.hands=[new Uu("left"),new Uu("right")]),t.element?a=t.element:t.elementId?a=document.getElementById(t.elementId)??void 0:(a=e.createButton(),s=null==t.button||"boolean"==typeof t.button?{}:t.button),!a)throw new Error("No element or button provided");a.style.display="none",a.classList.add("hidden"),this.button=s,this.element=a;const r=null==(n=t.onMouseLeaveOpacity)?void 0:n.toString();return void 0!==r&&(a.addEventListener("mouseleave",(()=>{a.style.opacity=r})),a.addEventListener("mouseenter",(()=>{a.style.opacity=""}))),this.initializeXr(t)})).then((()=>{var e;return null==(e=t.onReady)?void 0:e.call(t,"not_supported"!==this.mode)})).catch((t=>{alert(`Error initializing SparkXr: ${t}`)}))}async initializeXr(t){var e,n;if(!this.xr||!this.element)return;const a=this.element,s={vr:["immersive-vr"],ar:["immersive-ar"],arvr:["immersive-ar","immersive-vr"],vrar:["immersive-vr","immersive-ar"]}[t.mode??"vrar"];if(!s)throw new Error(`Invalid mode: ${t.mode}`);let r=null;for(const c of s)if(await this.xr.isSessionSupported(c)){r=c;break}if(!r)return void(this.mode="not_supported");this.mode=r;const i=t.referenceSpaceType??"local";this.renderer.xr.enabled=!0,this.renderer.xr.setReferenceSpaceType(i),void 0!==t.fixedFoveation&&this.renderer.xr.setFoveation(t.fixedFoveation);const o=t.frameBufferScaleFactor??.5;this.renderer.xr.setFramebufferScaleFactor(o);const l=(null==(e=t.sessionInit)?void 0:e.optionalFeatures)??[];t.enableHands&&l.push("hand-tracking");const u=(null==(n=t.sessionInit)?void 0:n.requiredFeatures)??[];u.push(i),this.sessionInit={...t.sessionInit,optionalFeatures:l,requiredFeatures:u},a.addEventListener("click",(()=>{this.toggleXr()})),this.updateElement()}async toggleXr(){var t,e,n;if(this.xr&&this.sessionInit)if(this.session)this.session.end();else try{const a=this.mode,s=await this.xr.requestSession(a,this.sessionInit);this.session=s;const r=()=>{var t;null==s||s.removeEventListener("end",r),null==s||s.removeEventListener("visibilitychange",o),this.session=void 0,this.updateElement(),null==(t=this.onExitXr)||t.call(this)};let i=s.visibilityState;const o=()=>{"visible-blurred"===(null==s?void 0:s.visibilityState)&&"visible"===i&&(null==s||s.end()),i=null==s?void 0:s.visibilityState};return null==(t=this.session)||t.addEventListener("end",r),null==(e=this.session)||e.addEventListener("visibilitychange",o),await this.renderer.xr.setSession(this.session),null==(n=this.onEnterXr)?void 0:n.call(this)}catch(a){return}}updateElement(){const t=this.mode,e=this.element;if(e){e.style.display="",e.classList.remove("hidden");const n="boolean"==typeof this.button?{}:this.button;if(n){if(this.session){const a=("immersive-vr"===t?n.exitVrHtml:n.exitArHtml)??n.exitXrHtml,s=("immersive-vr"===t?n.exitVrText:n.exitArText)??n.exitXrText;a?e.innerHTML=a:e.textContent=s||("immersive-vr"===t?"EXIT VR":"EXIT AR")}else{const a=("immersive-vr"===t?n.enterVrHtml:n.enterArHtml)??n.enterXrHtml,s=("immersive-vr"===t?n.enterVrText:n.enterArText)??n.enterXrText;a?e.innerHTML=a:e.textContent=s||("immersive-vr"===t?"ENTER VR":"ENTER AR")}e.style.display=""}}}static createButton(){const t=document.createElement("button");return Object.assign(t.style,{position:"absolute",bottom:"20px",left:"50%",transform:"translateX(-50%)",padding:"40px 40px",border:"2px solid #fff",borderRadius:"16px",background:"rgba(0,0,0,0.1)",color:"#fff",font:"bold 28px sans-serif",textAlign:"center",userSelect:"none",zIndex:"999"}),document.body.appendChild(t),t}xrSupported(){return!!this.xr}left(){return this.hands[0]}right(){return this.hands[1]}updateControllers(e){var n,a,s,r,i,o,l,u,c,p,d,h;const x=e.parent,f=performance.now(),m=(f-(this.lastControllersUpdate||f))/1e3;this.lastControllersUpdate=f;const y={};for(const t of(null==(n=this.renderer.xr.getSession())?void 0:n.inputSources)??[]){const e=t.gamepad;!e||"left"!==t.handedness&&"right"!==t.handedness||(y[t.handedness]=e,"left"===t.handedness?y.leftIsHand=!!t.hand:"right"===t.handedness&&(y.rightIsHand=!!t.hand))}const g=((null==(a=this.controllers)?void 0:a.getRotate)??Tu)(y,this);if(g.multiply(new t.Vector3((null==(s=this.controllers)?void 0:s.rotateSpeed)??4,(null==(r=this.controllers)?void 0:r.rotateSpeed)??4,(null==(i=this.controllers)?void 0:i.rollSpeed)??2)),g.manhattanLength()>0){g.multiplyScalar(m);const n=new t.Euler(-g.y,-g.x,g.z,"YXZ"),a=(new t.Quaternion).setFromEuler(n),s=e.getWorldPosition(new t.Vector3);null==(o=x.parent)||o.worldToLocal(s),x.position.sub(s),x.position.applyQuaternion(a),x.position.add(s),x.quaternion.premultiply(a)}const v=((null==(l=this.controllers)?void 0:l.getMove)??Su)(y,this);let w=(null==(u=this.controllers)?void 0:u.moveSpeed)??1;((null==(c=this.controllers)?void 0:c.getFast)??_u)(y,this)&&(w*=5),((null==(p=this.controllers)?void 0:p.getSlow)??Mu)(y,this)&&(w*=.2),(null==(d=this.controllers)?void 0:d.moveHeading)?v.applyQuaternion(e.quaternion):(null==(h=this.controllers)?void 0:h.moveDirection)&&(Lu.setFromQuaternion(e.quaternion,"YXZ"),Lu.x=0,Lu.z=0,Ru.setFromEuler(Lu),v.applyQuaternion(Ru)),v.applyQuaternion(x.quaternion),v.multiplyScalar(m*w),x.position.add(v)}updateHands({xrFrame:e}){const n=this.renderer.xr.getSession();if(!n)return;const a=this.renderer.xr.getReferenceSpace();if(a&&e.getJointPose){for(const t of this.hands)t&&(t.lastJoints=t.joints,t.joints=void 0);for(const s of n.inputSources){if(!s.hand)continue;const n=s.handedness,r=this.hands["left"===n?0:1];if(r)for(const i of $u){const n=s.hand.get(ku[i]);if(n){const s=e.getJointPose(n,a);if(s){const{position:e,orientation:n}=s.transform;r.joints||(r.joints={}),r.joints[i]={position:new t.Vector3(e.x,e.y,e.z),quaternion:new t.Quaternion(n.x,n.y,n.z,n.w),radius:zu[i]}}}}}}}makeJointSplats(t){const e=new Nu(t);return e.onFrame=()=>{const n=this.hands["left"===t?0:1],a=null==n?void 0:n.joints;e.updateJoints(a)},e}snapshotHands(t){var e,n;return{time:t,hands:[null==(e=this.hands[0])?void 0:e.snapshotJoints(),null==(n=this.hands[1])?void 0:n.snapshotJoints()]}}};Fu.JointEnum=ku,Fu.JOINT_IDS=$u,Fu.NUM_JOINTS=Du,Fu.JOINT_INDEX={w:0,t0:1,t1:2,t2:3,t3:4,i0:5,i1:6,i2:7,i3:8,i4:9,m0:10,m1:11,m2:12,m3:13,m4:14,r0:15,r1:16,r2:17,r3:18,r4:19,p0:20,p1:21,p2:22,p3:23,p4:24},Fu.JOINT_RADIUS=zu,Fu.JOINT_SEGMENTS=[["w","t0","t1","t2","t3"],["w","i0","i1","i2","i3","i4"],["w","m0","m1","m2","m3","m4"],["w","r0","r1","r2","r3","r4"],["w","p0","p1","p2","p3","p4"]],Fu.JOINT_SEGMENT_STEPS=[[8,10,8,6],[8,19,14,8,6],[8,19,14,8,6],[8,19,14,8,6],[8,19,14,8,6]],Fu.JOINT_TIPS=["t3","i4","m4","r4","p4"],Fu.FINGER_TIPS=["i4","m4","r4","p4"],Fu.Hand=Iu,Fu.HANDS=Eu;let Pu=Fu;const Cu=t=>Math.round(1e4*t)/1e4,Lu=new t.Euler(0,0,0,"YXZ"),Ru=new t.Quaternion,qu=new t.Quaternion;class Uu{constructor(t){this.hand=t}static newFromSnapshot(e,n){const a=new Uu(e);a.joints={};for(const s of $u){const e=n[s];e&&(a.joints[s]={position:new t.Vector3(e.pos[0],e.pos[1],e.pos[2]),quaternion:new t.Quaternion(e.quat[0],e.quat[1],e.quat[2],e.quat[3]),radius:e.radius})}return a}valid(){return!!this.joints}snapshotJoints(){if(!this.joints)return;const t={};for(const e of $u){const n=this.joints[e];n&&(t[e]={pos:n.position.toArray().map(Cu),quat:n.quaternion.toArray().map(Cu),radius:Cu(n.radius)})}return t}toFlatArray(){if(!this.joints)return;const t=new Float32Array(176);t[0]="left"===this.hand?0:1;let e=1;for(const n of $u){const a=this.joints[n];a&&(t[e]=a.position.x,t[e+1]=a.position.y,t[e+2]=a.position.z,t[e+3]=a.quaternion.x,t[e+4]=a.quaternion.y,t[e+5]=a.quaternion.z,t[e+6]=a.quaternion.w),e+=7}return t}}function Vu(t,e,n=0){if(!t||!e)return;return{pos:t.pos.map(((t,a)=>t+(e.pos[a]-t)*n)),quat:Ru.fromArray(t.quat).slerp(qu.fromArray(e.quat),n).toArray(),radius:t.radius+(e.radius-t.radius)*n}}function Bu(t){return{pos:[...t.pos],quat:[...t.quat],radius:t.radius}}class Nu extends Yl{constructor(e){super({}),this.scratchCenter=new t.Vector3,this.scratchQuat=new t.Quaternion(0,0,0,1),this.scratchScales=(new t.Vector3).setScalar(.01),this.scratchColor=new t.Color(1,1,1),this.hand=e}updateJoints(t){if(this.visible=!1,!t||!this.packedSplats)return;this.visible=!0;let e=0;for(const n of $u){const a=t[n];if(!a)continue;this.scratchCenter.copy(a.position),this.scratchQuat.copy(a.quaternion),this.scratchScales.set(a.radius,.75*a.radius,1.5*a.radius);const s=.75;this.packedSplats.setSplat(e,this.scratchCenter,this.scratchScales,this.scratchQuat,s,this.scratchColor),e+=1}this.packedSplats.numSplats=e,this.packedSplats.needsUpdate=!0,this.numSplats=e,this.updateVersion()}}var Ou=(t=>(t.w="wrist",t.t0="thumb-metacarpal",t.t1="thumb-phalanx-proximal",t.t2="thumb-phalanx-distal",t.t3="thumb-tip",t.i0="index-finger-metacarpal",t.i1="index-finger-phalanx-proximal",t.i2="index-finger-phalanx-intermediate",t.i3="index-finger-phalanx-distal",t.i4="index-finger-tip",t.m0="middle-finger-metacarpal",t.m1="middle-finger-phalanx-proximal",t.m2="middle-finger-phalanx-intermediate",t.m3="middle-finger-phalanx-distal",t.m4="middle-finger-tip",t.r0="ring-finger-metacarpal",t.r1="ring-finger-phalanx-proximal",t.r2="ring-finger-phalanx-intermediate",t.r3="ring-finger-phalanx-distal",t.r4="ring-finger-tip",t.p0="pinky-finger-metacarpal",t.p1="pinky-finger-phalanx-proximal",t.p2="pinky-finger-phalanx-intermediate",t.p3="pinky-finger-phalanx-distal",t.p4="pinky-finger-tip",t))(Ou||{});const Gu=Object.keys(Ou),Hu=Gu.length,Wu={w:.02,t0:.02,t1:.014,t2:.0115,t3:.0085,i0:.022,i1:.012,i2:.0085,i3:.0075,i4:.0065,m0:.021,m1:.012,m2:.008,m3:.0075,m4:.0065,r0:.019,r1:.011,r2:.0075,r3:.007,r4:.006,p0:.012,p1:.01,p2:.007,p3:.0065,p4:.0055},ju=[["w","t0","t1","t2","t3"],["w","i0","i1","i2","i3","i4"],["w","m0","m1","m2","m3","m4"],["w","r0","r1","r2","r3","r4"],["w","p0","p1","p2","p3","p4"]],Qu=[[8,10,8,6],[8,19,14,8,6],[8,19,14,8,6],[8,19,14,8,6],[8,19,14,8,6]];var Ku=(t=>(t.left="left",t.right="right",t))(Ku||{});const Xu=Object.keys(Ku);const Yu=1e-4,Ju={KeyW:new t.Vector3(0,0,-1),KeyS:new t.Vector3(0,0,1),KeyA:new t.Vector3(-1,0,0),KeyD:new t.Vector3(1,0,0),KeyE:new t.Vector3(0,1,0),KeyQ:new t.Vector3(0,-1,0)},Zu={ArrowUp:new t.Vector3(0,0,-1),ArrowDown:new t.Vector3(0,0,1),ArrowLeft:new t.Vector3(-1,0,0),ArrowRight:new t.Vector3(1,0,0),PageUp:new t.Vector3(0,1,0),PageDown:new t.Vector3(0,-1,0)},tc={Home:new t.Vector3(0,-1,0),End:new t.Vector3(0,1,0),Insert:new t.Vector3(-1,0,0),Delete:new t.Vector3(1,0,0)};class ec{constructor({moveSpeed:e,rollSpeed:n,stickThreshold:a,rotateSpeed:s,keycodeMoveMapping:r,keycodeRotateMapping:i,gamepadMapping:o,capsMultiplier:l,shiftMultiplier:u,ctrlMultiplier:c,xr:p}={}){this.enable=!0,this.extraMove=new t.Vector3,this.moveSpeed=e??1,this.rollSpeed=n??2,this.stickThreshold=a??.1,this.rotateSpeed=s??2,this.keycodeMoveMapping=r??{...Ju,...Zu},this.keycodeRotateMapping=i??{...tc},this.gamepadMapping=o??{4:"rollLeft",5:"rollRight",6:"ctrl",7:"shift"},this.capsMultiplier=l??10,this.shiftMultiplier=u??5,this.ctrlMultiplier=c??.2,this.xr=p,this.keydown={},this.keycode={},document.addEventListener("keydown",(t=>{this.keydown[t.key]=!0,this.keycode[t.code]=!0})),document.addEventListener("keyup",(t=>{this.keydown[t.key]=!1,this.keycode[t.code]=!1})),window.addEventListener("blur",(()=>{this.keydown={},this.keycode={}}))}update(e,n){var a,s;if(!this.enable)return!1;const r=[new t.Vector2,new t.Vector2],i=navigator.getGamepads()[0];i&&(r[0].set(i.axes[0],i.axes[1]),r[1].set(i.axes[2],i.axes[3]));const o=(null==i?void 0:i.buttons.map((t=>t.pressed)))||[],l=Array.from((null==(s=null==(a=this.xr)?void 0:a.getSession())?void 0:s.inputSources)??[]);for(const t of l){const e=t.gamepad;if(e)switch(t.handedness){case"none":r[0].x+=e.axes[0],r[0].y+=e.axes[1],r[1].x+=e.axes[2],r[1].y+=e.axes[3];break;case"left":r[0].x+=e.axes[2],r[0].y+=e.axes[3];break;case"right":r[1].x+=e.axes[2],r[1].y+=e.axes[3]}}for(const t of r)t.x=Math.abs(t.x)>=this.stickThreshold?t.x:0,t.y=Math.abs(t.y)>=this.stickThreshold?t.y:0;const u=new t.Vector3(r[1].x,r[1].y,0).multiplyScalar(this.rotateSpeed);for(const[t,h]of Object.entries(this.keycodeRotateMapping))this.keycode[t]&&u.add(h);for(const t in this.gamepadMapping)if(o[Number.parseInt(t)])switch(this.gamepadMapping[t]){case"rollLeft":u.z+=1;break;case"rollRight":u.z-=1}u.multiply(new t.Vector3(this.rotateSpeed,this.rotateSpeed,this.rollSpeed));let c=u.length()>Yu;if(u.manhattanLength()>0){u.multiplyScalar(e);const a=(new t.Euler).setFromQuaternion(n.quaternion,"YXZ");a.y-=u.x,a.x=Math.max(-Math.PI/2,Math.min(Math.PI/2,a.x-u.y)),a.z=Math.max(-Math.PI,Math.min(Math.PI,a.z+u.z)),n.quaternion.setFromEuler(a)}const p=new t.Vector3(r[0].x,0,r[0].y);p.add(this.extraMove);for(const[t,h]of Object.entries(this.keycodeMoveMapping))this.keycode[t]&&p.add(h);let d=1;this.keydown.CapsLock&&(d*=this.capsMultiplier),(this.keycode.ShiftLeft||this.keycode.ShiftRight)&&(d*=this.shiftMultiplier),(this.keycode.ControlLeft||this.keycode.ControlRight)&&(d*=this.ctrlMultiplier);for(const t in this.gamepadMapping)if(o[Number.parseInt(t)])switch(this.gamepadMapping[t]){case"shift":d*=this.shiftMultiplier;break;case"ctrl":d*=this.ctrlMultiplier}return p.length()>Yu&&(c=!0),p.applyQuaternion(n.quaternion),n.position.add(p.multiplyScalar(this.moveSpeed*d*e)),c}}class nc{constructor({canvas:e,rotateSpeed:n,slideSpeed:a,scrollSpeed:s,swapRotateSlide:r,reverseRotate:i,reverseSlide:o,reverseSwipe:l,reverseScroll:u,moveInertia:c,rotateInertia:p,pointerRollScale:d,doublePress:h,pressMoveDelayMs:x,pressMoveAccelMs:f,pressMoveSpeed:m,doublePressMoveSpeed:y,triplePressMoveSpeed:g,pressMoveCenter:v}){this.enable=!0,this.canvas=e,this.rotateSpeed=n??.002,this.slideSpeed=a??.006,this.scrollSpeed=s??.0015,this.swapRotateSlide=r??!1,this.reverseRotate=i??(aa()||ia()),this.reverseSlide=o??!1,this.reverseSwipe=l??!1,this.reverseScroll=u??!1,this.moveInertia=c??.15,this.rotateInertia=p??.15,this.pointerRollScale=d??0,this.doublePress=h??(()=>{}),this.doublePressLimitMs=400,this.doublePressDistance=25,this.pressMoveDelayMs=x??500,this.pressMoveAccelMs=f??500,this.pressMoveSpeed=m??0,this.doublePressMoveSpeed=y??5*this.pressMoveSpeed,this.triplePressMoveSpeed=g??5*this.doublePressMoveSpeed,this.pressMoveCenter=v??!0,this.doublePressed=void 0,this.triplePressed=!1,this.lastUp=null,this.lastLastUp=null,this.rotating=null,this.sliding=null,this.lastDown=null,this.dualPress=!1,this.scroll=new t.Vector3,this.rotateVelocity=new t.Vector3,this.moveVelocity=new t.Vector3,e.addEventListener("pointerdown",(t=>{const n=this.getPointerPosition(t),a=n.clone(),s=n.clone(),r=!this.swapRotateSlide&&!this.rotating&&("mouse"!==t.pointerType||0===t.button)||this.swapRotateSlide&&this.sliding&&!this.rotating&&("mouse"!==t.pointerType||1===t.button),{pointerId:i}=t,o=performance.now();if(r)this.rotating={initial:a,last:s,position:n,pointerId:i,timeStamp:o},this.lastDown=this.rotating,e.setPointerCapture(t.pointerId),this.dualPress=!1;else if(!this.sliding){const r="mouse"===t.pointerType?t.button:void 0;this.sliding={initial:a,last:s,position:n,pointerId:i,button:r,timeStamp:o},this.lastDown=this.sliding,e.setPointerCapture(t.pointerId),this.dualPress=null!=this.rotating&&o-this.rotating.timeStamp<200}if(this.lastUp){const t=this.lastUp.position.distanceTo(n),e=o-this.lastUp.timeStamp;if(t<this.doublePressDistance&&e<this.doublePressLimitMs&&(this.doublePressed=performance.now(),this.triplePressed=!1,this.lastLastUp)){const t=this.lastLastUp.position.distanceTo(this.lastUp.position),e=this.lastUp.timeStamp-this.lastLastUp.timeStamp;t<this.doublePressDistance&&e<this.doublePressLimitMs&&(this.triplePressed=!0)}}}));const w=t=>{var n,a;(null==(n=this.rotating)?void 0:n.pointerId)===t.pointerId?(this.rotating=null,e.releasePointerCapture(t.pointerId),this.dualPress&&this.sliding&&(e.releasePointerCapture(this.sliding.pointerId),this.sliding=null)):(null==(a=this.sliding)?void 0:a.pointerId)===t.pointerId&&(this.sliding=null,e.releasePointerCapture(t.pointerId),this.dualPress&&this.rotating&&(e.releasePointerCapture(this.rotating.pointerId),this.rotating=null)),this.doublePressed=void 0,this.triplePressed=!1;const s=this.getPointerPosition(t),r=this.lastUp;this.lastLastUp=this.lastUp;const i=performance.now();if(this.lastUp={position:s,timeStamp:i},r){if(r.position.distanceTo(s)<this.doublePressDistance){const t=i-r.timeStamp;t<this.doublePressLimitMs&&this.doublePress({position:s,intervalMs:t})}}};document.addEventListener("pointerup",w),document.addEventListener("pointercancel",w),document.addEventListener("pointermove",(t=>{var e,n;(null==(e=this.rotating)?void 0:e.pointerId)===t.pointerId?this.rotating.position=this.getPointerPosition(t):(null==(n=this.sliding)?void 0:n.pointerId)===t.pointerId&&(this.sliding.position=this.getPointerPosition(t))})),e.addEventListener("contextmenu",(t=>{t.preventDefault()})),e.addEventListener("wheel",(e=>{this.scroll.add(new t.Vector3(e.deltaX,e.deltaY,e.deltaZ)),e.preventDefault()}))}getPointerPosition(e){const n=this.canvas.getBoundingClientRect();return new t.Vector2(e.clientX-n.left,e.clientY-n.top)}update(e,n,a){var s,r;if(!this.enable)return!1;const i=performance.now();let o=!1;if(this.dualPress&&this.rotating&&this.sliding){const s=[this.rotating.position.clone().sub(this.rotating.last),this.sliding.position.clone().sub(this.sliding.last)],r=s[0].dot(s[1]);if(r>=.2){const a=s[0].clone().add(s[1]),r=new t.Vector3(a.x,-a.y,0);r.multiplyScalar(this.slideSpeed*(this.reverseSwipe?1:-1)),r.applyQuaternion(n.quaternion),n.position.add(r),this.moveVelocity=r.clone().multiplyScalar(1/e),r.length()>Yu&&(o=!0)}else if(r<=-.2){const r=this.sliding.last.clone().sub(this.rotating.last),i=r.length();r.multiplyScalar(1/i).normalize();const l=new t.Vector2(-r.y,r.x),u=[s[0].dot(r),s[1].dot(r)],c=[s[0].dot(l),s[1].dot(l)],p=this.rotating.last.clone().add(this.sliding.last).multiplyScalar(.5);let d=new t.Vector3;const h=a??(n instanceof t.Camera?n:void 0);if(h){const e=new t.Vector2(p.x/this.canvas.clientWidth*2-1,-p.y/this.canvas.clientHeight*2+1),n=new t.Raycaster;n.setFromCamera(e,h),d=n.ray.direction}const x=u[1]-u[0],f=d.multiplyScalar(x*this.slideSpeed);n.position.add(f),this.moveVelocity=f.clone().multiplyScalar(1/e),f.length()>Yu&&(o=!0);const m=[Math.atan(c[0]/(-.5*i)),Math.atan(c[1]/(.5*i))],y=.5*(m[0]+m[1])*this.pointerRollScale,g=(new t.Euler).setFromQuaternion(n.quaternion,"YXZ");g.z=Math.max(-Math.PI,Math.min(Math.PI,g.z+.5*y)),n.quaternion.setFromEuler(g),Math.abs(y)>Yu&&(o=!0)}this.rotating.last.copy(this.rotating.position),this.sliding.last.copy(this.sliding.position)}else{const l=new t.Vector3;if(this.rotating&&!this.dualPress){const t=this.rotating.position.clone().sub(this.rotating.last);this.rotating.last.copy(this.rotating.position),l.set(t.x,t.y,0),l.multiplyScalar(this.rotateSpeed*(this.reverseRotate?-1:1)),this.rotateVelocity=l.clone().multiplyScalar(1/e),l.length()>Yu&&(o=!0)}else this.rotateVelocity.multiplyScalar(Math.exp(-e/this.rotateInertia)),l.addScaledVector(this.rotateVelocity,e),.1*this.rotateVelocity.length()>Yu&&(o=!0);const u=(new t.Euler).setFromQuaternion(n.quaternion,"YXZ");if(u.y-=l.x,u.x=Math.max(-Math.PI/2,Math.min(Math.PI/2,u.x-l.y)),u.z*=Math.exp(-0*e),n.quaternion.setFromEuler(u),this.sliding&&!this.dualPress){const a=this.sliding.position.clone().sub(this.sliding.last);this.sliding.last.copy(this.sliding.position);const s=2!==this.sliding.button?new t.Vector3(a.x,0,a.y):new t.Vector3(a.x,-a.y,0);s.multiplyScalar(this.slideSpeed*(this.reverseSlide?-1:1)),s.applyQuaternion(n.quaternion),n.position.add(s),this.moveVelocity=s.clone().multiplyScalar(1/e),s.length()>Yu&&(o=!0)}else{const l=new t.Vector3;if(this.sliding||this.rotating){const e=(null==(s=this.lastDown)?void 0:s.last)??new t.Vector2,o=a??(n instanceof t.Camera?n:void 0);if(o){const n=this.pressMoveCenter?new t.Vector2(0,0):new t.Vector2(e.x/this.canvas.clientWidth*2-1,-e.y/this.canvas.clientHeight*2+1),a=new t.Raycaster;a.setFromCamera(n,o),l.copy(a.ray.direction).normalize()}if(this.doublePressed){this.pressHeld=!1;let t=(performance.now()-this.doublePressed)/this.pressMoveAccelMs;t=Math.max(0,Math.min(1,t)),l.multiplyScalar((this.triplePressed?this.triplePressMoveSpeed:this.doublePressMoveSpeed)*t)}else{let t=0;this.lastDown&&(t=(i-((null==(r=this.lastDown)?void 0:r.timeStamp)??i)-this.pressMoveDelayMs)/this.pressMoveAccelMs,this.lastDown.position.distanceTo(this.lastDown.initial)<this.doublePressDistance?void 0===this.pressHeld&&t>0&&(this.pressHeld=!0):void 0===this.pressHeld&&(this.pressHeld=!1)),this.pressHeld?l.multiplyScalar(this.pressMoveSpeed*Math.max(0,Math.min(1,t))):l.set(0,0,0)}}else this.pressHeld=void 0;const u=Math.exp(-e/this.moveInertia);this.moveVelocity.lerpVectors(l,this.moveVelocity,u),n.position.addScaledVector(this.moveVelocity,e),.1*this.moveVelocity.length()>Yu&&(o=!0)}}const l=this.scroll.multiplyScalar(this.scrollSpeed);return l.set(l.x,l.z,l.y),this.reverseScroll&&l.multiplyScalar(-1),l.applyQuaternion(n.quaternion),n.position.add(l),l.length()>Yu&&(o=!0),this.scroll.set(0,0,0),o}}const ac='\nprecision highp float;\nprecision highp int;\n\n#include <splatDefines>\n\nuniform float near;\nuniform float far;\nuniform mat4 projectionMatrix;\nuniform bool encodeLinear;\nuniform float time;\nuniform bool debugFlag;\nuniform float maxStdDev;\nuniform float minAlpha;\nuniform bool disableFalloff;\nuniform float falloff;\n\nuniform vec3 diskCenter;\nuniform vec3 diskNormal;\nuniform float diskRadius;\nuniform bool diskTwoSided;\n\nout vec4 fragColor;\n\nin vec4 vRgba;\nin vec2 vSplatUv;\nin vec3 vNdc;\nflat in uint vSplatIndex;\nflat in float adjustedStdDev;\n\nvoid main() {\n if (diskRadius != 0.0) {\n // Portal rendering:\n // - diskRadius > 0: render "behind portal" only through the disk (discard outside or in-front-of plane).\n // - diskRadius < 0: render "in front of portal" everywhere, but discard fragments behind the plane when looking through the disk.\n\n // View ray direction from NDC (view space is -Z forward).\n vec3 viewDir = normalize(vec3(\n vNdc.x / projectionMatrix[0][0],\n vNdc.y / projectionMatrix[1][1],\n -1.0\n ));\n\n // Reconstruct view-space *axial* depth (-viewPos.z) from NDC Z.\n float ndcZ = vNdc.z;\n float depth = (2.0 * near * far) / (far + near - ndcZ * (far - near));\n // Convert axial depth to ray-parameter t (viewPos = t * viewDir).\n float rayT = depth / max(1e-6, -viewDir.z);\n\n float radius = abs(diskRadius);\n float radius2 = radius * radius;\n bool renderBehind = (diskRadius > 0.0);\n\n vec3 diskN = normalize(diskNormal);\n\n // Ray-plane intersection for plane (diskCenter, diskN), with ray origin at (0,0,0).\n float denom = dot(viewDir, diskN);\n bool allowPortal = diskTwoSided ? (abs(denom) > 1e-6) : (denom < -1e-6);\n\n bool hitsDisk = false;\n float t = 0.0;\n if (allowPortal) {\n t = dot(diskCenter, diskN) / denom;\n if (t > 0.0) {\n vec3 q = t * viewDir - diskCenter;\n hitsDisk = (dot(q, q) <= radius2);\n }\n }\n\n // Small bias to avoid flicker at the plane.\n float eps = 1e-4 * max(1.0, abs(t));\n\n if (renderBehind) {\n // Behind-pass: only render through the portal disk, and only behind the plane along the ray.\n if (!hitsDisk) discard;\n if (rayT <= t + eps) discard;\n } else {\n // Front-pass: render everything, except when the ray goes through the disk, discard what\'s behind the plane.\n if (hitsDisk && (rayT >= t - eps)) discard;\n }\n }\n\n vec4 rgba = vRgba;\n\n float z2 = dot(vSplatUv, vSplatUv);\n if (z2 > (adjustedStdDev * adjustedStdDev)) {\n discard;\n }\n\n float a = rgba.a;\n float shifted = sqrt(z2) - max(0.0, a - 1.0);\n float exponent = -0.5 * max(1.0, a) * sqr(max(0.0, shifted));\n rgba.a = min(1.0, a) * exp(exponent);\n\n if (rgba.a < minAlpha) {\n discard;\n }\n if (encodeLinear) {\n rgba.rgb = srgbToLinear(rgba.rgb);\n }\n\n #ifdef PREMULTIPLIED_ALPHA\n fragColor = vec4(rgba.rgb * rgba.a, rgba.a);\n #else\n fragColor = rgba;\n #endif\n}\n';exports.DEFAULT_CONTROLLER_FAST_MULTIPLIER=5,exports.DEFAULT_CONTROLLER_GETFAST=_u,exports.DEFAULT_CONTROLLER_GETMOVE=Su,exports.DEFAULT_CONTROLLER_GETROTATE=Tu,exports.DEFAULT_CONTROLLER_GETSLOW=Mu,exports.DEFAULT_CONTROLLER_MOVE_HEADING=!1,exports.DEFAULT_CONTROLLER_MOVE_SPEED=1,exports.DEFAULT_CONTROLLER_ROLL_SPEED=2,exports.DEFAULT_CONTROLLER_ROTATE_SPEED=4,exports.DEFAULT_CONTROLLER_SLOW_MULTIPLIER=.2,exports.DISK_PORTAL_FRAGMENT_SHADER=ac,exports.ExtSplats=El,exports.FINGER_TIPS=["i4","m4","r4","p4"],exports.FpsMovement=ec,exports.HANDS=Xu,exports.Hand=Ku,exports.HandMovement=class{constructor({xrHands:e,control:n,moveInertia:a,rotateInertia:s}){this.lastGrip={},this.lastPivot=new t.Vector3,this.rotateVelocity=0,this.velocity=new t.Vector3,this.xrHands=e,this.control=n,this.moveInertia=a??.5,this.rotateInertia=s??.5}update(e){var n,a,s,r,i;const o={};for(const c of Xu){const e=this.xrHands.hands[c];e&&this.xrHands.tests[`${c}MiddleThumb`]&&(o[c]=(new t.Vector3).add((null==(n=e.t3)?void 0:n.position)??new t.Vector3).add((null==(a=e.i4)?void 0:a.position)??new t.Vector3).add((null==(s=e.m4)?void 0:s.position)??new t.Vector3).add((null==(r=e.r4)?void 0:r.position)??new t.Vector3).add((null==(i=e.p4)?void 0:i.position)??new t.Vector3).multiplyScalar(.2))}if(o.left&&o.right&&this.lastGrip.left&&this.lastGrip.right){const t=o.left.clone().add(o.right).multiplyScalar(.5),n=this.lastGrip.left.clone().add(this.lastGrip.right).multiplyScalar(.5);this.lastPivot=t;const a=t.clone().applyMatrix4(this.control.matrix);a.sub(n.clone().applyMatrix4(this.control.matrix)),a.multiplyScalar(1/e),this.velocity.lerp(a,1-Math.exp(-20*e));let s=Math.atan2(o.left.z-t.z,o.left.x-t.x)-Math.atan2(this.lastGrip.left.z-n.z,this.lastGrip.left.x-n.x);s>Math.PI?s-=2*Math.PI:s<-Math.PI&&(s+=2*Math.PI);const r=s/e,i=Math.exp(-20*e);this.rotateVelocity=this.rotateVelocity*i+r*(1-i)}else if(this.rotateVelocity*=Math.exp(-e/this.rotateInertia),o.left&&this.lastGrip.left){const t=o.left.clone().applyMatrix4(this.control.matrix);t.sub(this.lastGrip.left.clone().applyMatrix4(this.control.matrix)),t.multiplyScalar(1/e),this.velocity.lerp(t,1-Math.exp(-20*e))}else if(o.right&&this.lastGrip.right){const t=o.right.clone().applyMatrix4(this.control.matrix);t.sub(this.lastGrip.right.clone().applyMatrix4(this.control.matrix)),t.multiplyScalar(1/e),this.velocity.lerp(t,1-Math.exp(-20*e))}else this.velocity.multiplyScalar(Math.exp(-e/this.moveInertia));const l=this.lastPivot.clone().negate(),u=(new t.Matrix4).makeTranslation(l).premultiply((new t.Matrix4).makeRotationY(this.rotateVelocity*e)).premultiply((new t.Matrix4).makeTranslation(this.lastPivot));this.control.matrix.multiply(u),this.control.matrix.decompose(this.control.position,this.control.quaternion,this.control.scale),this.control.updateMatrixWorld(!0),this.control.position.sub(this.velocity.clone().multiplyScalar(e)),this.lastGrip=o}},exports.JOINT_IDS=Gu,exports.JOINT_INDEX={w:0,t0:1,t1:2,t2:3,t3:4,i0:5,i1:6,i2:7,i3:8,i4:9,m0:10,m1:11,m2:12,m3:13,m4:14,r0:15,r1:16,r2:17,r3:18,r4:19,p0:20,p1:21,p2:22,p3:23,p4:24},exports.JOINT_RADIUS=Wu,exports.JOINT_SEGMENTS=ju,exports.JOINT_SEGMENT_STEPS=Qu,exports.JOINT_TIPS=["t3","i4","m4","r4","p4"],exports.JointEnum=Ou,exports.JointSplats=Nu,exports.LN_SCALE_MAX=9,exports.LN_SCALE_MIN=n,exports.NUM_JOINTS=Hu,exports.PackedSplats=bl,exports.PagedSplats=Ol,exports.PointerControls=nc,exports.Readback=mo,exports.RgbaArray=Ul,exports.Sint8ToFloat=Wn,exports.SparkControls=class{constructor({canvas:t}){this.lastTime=0,this.fpsMovement=new ec({}),this.pointerControls=new nc({canvas:t})}update(t,e){const n=performance.now(),a=(n-(this.lastTime||n))/1e3;this.lastTime=n;let s=this.fpsMovement.update(a,t);return this.pointerControls.update(a,t,e)&&(s=!0),s}},exports.SparkPortals=class{constructor(e){this.portalPairs=[],this.lastCameraWorld=(new t.Vector3).setScalar(Number.NaN),this.prefetchActive=!1,this.scratch={quat:new t.Quaternion,scale:new t.Vector3,center0:new t.Vector3,center1:new t.Vector3,normal0:new t.Vector3,normal1:new t.Vector3,centerT:new t.Vector3,normalT:new t.Vector3,prevCameraWorld:new t.Vector3,currCameraWorld:new t.Vector3,hit:new t.Vector3,offset:new t.Vector3,camWorld:new t.Matrix4,newCamWorld:new t.Matrix4,invCamLocal:new t.Matrix4,newLocalFrame:new t.Matrix4,cameraWorldPos:new t.Vector3,viewDir:new t.Vector3,portalCenter:new t.Vector3,toPortal:new t.Vector3},this.renderer=e.renderer,this.scene=e.scene,this.camera=e.camera,this.localFrame=e.localFrame,this.defaultPortalRadius=e.defaultPortalRadius??1,this.portalCrossEps=e.portalCrossEps??1e-6;const n=e.sparkOptions??{};this.portalRenderer=new ou({renderer:this.renderer,extraUniforms:{diskCenter:{value:new t.Vector3},diskNormal:{value:new t.Vector3},diskRadius:{value:0},diskTwoSided:{value:!1}},fragmentShader:ac,...n}),this.scene.add(this.portalRenderer),this.behindRenderer=new ou({renderer:this.renderer,enableDriveLod:!1,...n}),this.camera2=this.camera.clone(),this.scene.add(this.camera2)}addPortalPair(e){const n={entryPortal:new t.Object3D,exitPortal:new t.Object3D,radius:(null==e?void 0:e.radius)??this.defaultPortalRadius,onCross:null==e?void 0:e.onCross,_entryBefore:new t.Matrix4,_exitBefore:new t.Matrix4};return this.scene.add(n.entryPortal),this.scene.add(n.exitPortal),this.portalPairs.push(n),n}removePortalPair(t){const e=this.portalPairs.indexOf(t);-1!==e&&(this.scene.remove(t.entryPortal),this.scene.remove(t.exitPortal),this.portalPairs.splice(e,1))}getEntryToExitTransform(t){return t.entryPortal.matrixWorld.clone().invert().premultiply(t.exitPortal.matrixWorld)}getExitToEntryTransform(t){return t.exitPortal.matrixWorld.clone().invert().premultiply(t.entryPortal.matrixWorld)}setPortalDiskUniforms(e,n,a,s){e.updateMatrixWorld(!0),n.updateMatrixWorld(!0);const r=e.matrixWorld.clone().invert(),i=n.matrixWorld.clone().premultiply(r),o=new t.Quaternion,l=this.portalRenderer.uniforms;i.decompose(l.diskCenter.value,o,new t.Vector3),l.diskNormal.value.set(0,0,1).applyQuaternion(o),l.diskRadius.value=a,l.diskTwoSided.value=s}getPortalPlane(t,e,n){t.decompose(e,this.scratch.quat,this.scratch.scale),n.set(0,0,1).applyQuaternion(this.scratch.quat).normalize()}getSegmentDiskCrossing(t,e,n,a,s){this.getPortalPlane(n,this.scratch.center0,this.scratch.normal0),this.getPortalPlane(a,this.scratch.center1,this.scratch.normal1);const r=this.scratch.offset.copy(t).sub(this.scratch.center0).dot(this.scratch.normal0),i=this.scratch.offset.copy(e).sub(this.scratch.center1).dot(this.scratch.normal1);if(r>this.portalCrossEps&&i>this.portalCrossEps||r<-this.portalCrossEps&&i<-this.portalCrossEps)return null;const o=r-i;if(Math.abs(o)<this.portalCrossEps)return null;const l=r/o;return l<0||l>1?null:(this.scratch.hit.lerpVectors(t,e,l),this.scratch.centerT.copy(this.scratch.center0).lerp(this.scratch.center1,l),this.scratch.normalT.copy(this.scratch.normal0).lerp(this.scratch.normal1,l).normalize(),this.scratch.offset.copy(this.scratch.hit).sub(this.scratch.centerT),this.scratch.offset.addScaledVector(this.scratch.normalT,-this.scratch.offset.dot(this.scratch.normalT)),this.scratch.offset.lengthSq()>s*s?null:l)}teleport(t){this.scratch.camWorld.copy(this.camera.matrixWorld),this.scratch.newCamWorld.copy(this.scratch.camWorld).premultiply(t),this.scratch.invCamLocal.copy(this.camera.matrix).invert(),this.scratch.newLocalFrame.copy(this.scratch.newCamWorld).multiply(this.scratch.invCamLocal),this.scratch.newLocalFrame.decompose(this.localFrame.position,this.localFrame.quaternion,this.localFrame.scale),this.localFrame.updateMatrixWorld(!0),this.camera.updateMatrixWorld(!0)}updateTeleportation(){if(0===this.portalPairs.length)return;if(this.camera.getWorldPosition(this.scratch.currCameraWorld),!Number.isFinite(this.lastCameraWorld.x))return void this.lastCameraWorld.copy(this.scratch.currCameraWorld);this.scratch.prevCameraWorld.copy(this.lastCameraWorld);let t=null,e=null,n=!0;for(const a of this.portalPairs){a.entryPortal.updateMatrixWorld(!0),a.exitPortal.updateMatrixWorld(!0),a._entryBefore.copy(a.entryPortal.matrixWorld),a._exitBefore.copy(a.exitPortal.matrixWorld);const s=this.getSegmentDiskCrossing(this.scratch.prevCameraWorld,this.scratch.currCameraWorld,a._entryBefore,a.entryPortal.matrixWorld,a.radius);null!==s&&(null===t||s<t)&&(t=s,e=a,n=!0);const r=this.getSegmentDiskCrossing(this.scratch.prevCameraWorld,this.scratch.currCameraWorld,a._exitBefore,a.exitPortal.matrixWorld,a.radius);null!==r&&(null===t||r<t)&&(t=r,e=a,n=!1)}null!==e?(n?this.teleport(this.getEntryToExitTransform(e)):this.teleport(this.getExitToEntryTransform(e)),this.camera.getWorldPosition(this.lastCameraWorld),e.onCross&&Promise.resolve(e.onCross(e,n)).catch((t=>{}))):this.lastCameraWorld.copy(this.scratch.currCameraWorld)}findPrimaryPortal(){if(0===this.portalPairs.length)return null;this.camera.getWorldPosition(this.scratch.cameraWorldPos),this.camera.getWorldDirection(this.scratch.viewDir);let t=Number.NEGATIVE_INFINITY,e=null,n=!0;for(const a of this.portalPairs){a.entryPortal.getWorldPosition(this.scratch.portalCenter),this.scratch.toPortal.copy(this.scratch.portalCenter).sub(this.scratch.cameraWorldPos);const s=this.scratch.toPortal.length(),r=this.scratch.toPortal.normalize().dot(this.scratch.viewDir)/s;r>t&&(t=r,e=a,n=!0),a.exitPortal.getWorldPosition(this.scratch.portalCenter),this.scratch.toPortal.copy(this.scratch.portalCenter).sub(this.scratch.cameraWorldPos);const i=this.scratch.toPortal.length(),o=this.scratch.toPortal.normalize().dot(this.scratch.viewDir)/i;o>t&&(t=o,e=a,n=!1)}return e?{pair:e,primaryIsEntry:n,primaryPortal:n?e.entryPortal:e.exitPortal,otherPortal:n?e.exitPortal:e.entryPortal}:null}render(){const t=this.findPrimaryPortal();if(!t)return this.prefetchActive&&(this.prefetchActive=!1),this.renderer.autoClear=!0,void this.renderer.render(this.scene,this.camera);this.prefetchActive||(this.prefetchActive=!0);const{pair:e,primaryIsEntry:n,primaryPortal:a,otherPortal:s}=t;(n?this.camera.matrixWorld.clone().premultiply(this.getEntryToExitTransform(e)):this.camera.matrixWorld.clone().premultiply(this.getExitToEntryTransform(e))).decompose(this.camera2.position,this.camera2.quaternion,this.camera2.scale),this.camera2.updateMatrixWorld(!0),this.shareLodInstances(),this.setPortalDiskUniforms(this.camera2,s,e.radius,!0),this.renderer.autoClear=!0,this.behindRenderer.render(this.scene,this.camera2),this.setPortalDiskUniforms(this.camera,a,-e.radius,!0),this.renderer.autoClear=!1,this.portalRenderer.render(this.scene,this.camera)}shareLodInstances(){this.behindRenderer.lodInstances.clear();for(const[t,e]of this.portalRenderer.lodInstances)this.behindRenderer.lodInstances.set(t,e)}animateLoopHook(){this.updateTeleportation(),this.render()}updateAspect(t){this.camera2.aspect=t,this.camera2.updateProjectionMatrix()}dispose(){this.scene.remove(this.portalRenderer),this.scene.remove(this.camera2);for(const t of this.portalPairs)this.scene.remove(t.entryPortal),this.scene.remove(t.exitPortal);this.portalPairs=[],this.portalRenderer.dispose(),this.behindRenderer.dispose()}},exports.SparkRenderer=ou,exports.SparkXr=Pu,exports.SplatAccumulator=nu,exports.SplatEdit=To,exports.SplatEditRgbaBlendMode=vo,exports.SplatEditSdf=bo,exports.SplatEditSdfType=yo,exports.SplatEdits=_o,exports.SplatFileType=l,exports.SplatGenerator=Eo,exports.SplatLoader=$l,exports.SplatMesh=Yl,exports.SplatModifier=class{constructor(t){this.modifier=t,this.cache=new Map}apply(t){let e=this.cache.get(t);return e||(e=O({index:"int"},{gsplat:Y},(({index:e})=>{const{gsplat:n}=t.apply({index:e});return this.modifier.apply({gsplat:n})})),this.cache.set(t,e)),e}},exports.SplatPager=Hl,exports.SplatSkinning=cu,exports.SplatSkinningMode=lu,exports.SplatTransformer=zo,exports.Uint8ToFloat=Hn,exports.XrHand=Uu,exports.XrHands=class{constructor(){this.hands={},this.last={},this.values={},this.tests={},this.lastTests={},this.updated=!1}update({xr:e,xrFrame:n}){const a=e.getSession();if(!a)return;const s=e.getReferenceSpace();if(s&&n.getJointPose){this.last=this.hands,this.lastTests=this.tests,this.hands={},this.values={},this.tests={};for(const e of a.inputSources){if(!e.hand)continue;const a=e.handedness;this.hands[a]={};for(const r of Gu){const i=e.hand.get(Ou[r]);if(i){const e=n.getJointPose(i,s);if(e){const{position:n,orientation:s}=e.transform;this.hands[a][r]={position:new t.Vector3(n.x,n.y,n.z),quaternion:new t.Quaternion(s.x,s.y,s.z,s.w),radius:e.radius||.001}}}}}for(const t of Xu)for(const{key:e,value:n}of[{key:`${t}AllTips`,value:this.allTipsTouching(t)},{key:`${t}IndexThumb`,value:this.touching(t,"i4",t,"t3")},{key:`${t}MiddleThumb`,value:this.touching(t,"m4",t,"t3")},{key:`${t}RingThumb`,value:this.touching(t,"r4",t,"t3")},{key:`${t}PinkyThumb`,value:this.touching(t,"p4",t,"t3")},{key:`${t}TriTips`,value:this.triTipsTouching(t)}])this.values[e]=n,this.tests[e]=1===n||0!==n&&(this.lastTests[e]??!1)}}makeGhostMesh(){const e=new t.Vector3,n=new t.Vector3(.01,.01,.01),a=new t.Quaternion(0,0,0,1),s=new t.Color(1,1,1),r=3*Math.PI;new t.Color(1,1,1);let i=1;const o=new Yl({onFrame:()=>{if(!o.packedSplats)return;let t=0;for(const l of Xu){const u=this.hands[l];for(const[c,p]of ju.entries())for(let d=1;d<p.length;++d){const h=2*Qu[c][d-1],x=d+1===p.length,f=null==u?void 0:u[p[d-1]],m=null==u?void 0:u[p[d]];for(let u=0;u<h;++u){const c=(u+.5)/h;if(i=0,f&&m){e.copy(f.position).lerp(m.position,c),a.copy(f.quaternion).slerp(m.quaternion,c);let t=(1-c)*Wu[p[d-1]]+c*Wu[p[d]];x&&c>.8&&(t*=Math.sqrt(1-((c-.8)/.2)**2)),n.set(.65*t,.5*t,.003),s.set(.55+.45*Math.sin(e.x*r),.55+.45*Math.sin(e.y*r),.55+.45*Math.sin(e.z*r)),"right"===l&&s.set(1-s.r,1-s.g,1-s.b),i=.75}o.packedSplats.setSplat(t,e,n,a,i,s),t+=1}}}o.packedSplats.numSplats=t,o.packedSplats.needsUpdate=!0,o.numSplats=t,o.updateVersion()}});return o}distance(t,e,n,a,s=!1){const r=s?this.last[t]:this.hands[t],i=s?this.last[n]:this.hands[n],o=null==r?void 0:r[e],l=null==i?void 0:i[a];return o&&l?o.position.distanceTo(l.position):Number.POSITIVE_INFINITY}separation(t,e,n,a,s=!1){const r=this.distance(t,e,n,a,s);return r===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:r-Wu[e]-Wu[a]}touching(t,e,n,a,s=!1){const r=this.separation(t,e,n,a,s);return r===Number.POSITIVE_INFINITY?Number.POSITIVE_INFINITY:1-Math.max(0,Math.min(1,r/.01-0))}allTipsTouching(t,e=!1){return Math.min(this.touching(t,"t3",t,"i4",e),this.touching(t,"i4",t,"m4",e),this.touching(t,"m4",t,"r4",e),this.touching(t,"r4",t,"p4",e))}triTipsTouching(t,e=!1){return Math.min(this.touching(t,"t3",t,"i4",e),this.touching(t,"i4",t,"m4",e),this.touching(t,"m4",t,"t3",e))}},exports.constructAxes=function({splats:e,scale:n=.25,axisRadius:a=.0075,axisShadowScale:s=2,origins:r=[new t.Vector3]}){const i=new t.Vector3,o=new t.Vector3,l=new t.Quaternion(0,0,0,1),u=new t.Color;for(const t of r)for(let r=0;r<3;++r){i.set(t.x+(0===r?n:0),t.y+(1===r?n:0),t.z+(2===r?n:0));for(let t=0;t<2;++t)o.set((0===r?n:a)*(t?1:s),(1===r?n:a)*(t?1:s),(2===r?n:a)*(t?1:s)),u.setRGB(0===t?0:0===r?1:0,0===t?0:1===r?1:0,0===t?0:2===r?1:0),e.pushSplat(i,o,l,1,u)}},exports.constructGrid=function({splats:e,extents:n,stepSize:a=1,pointRadius:s=.01,pointShadowScale:r=2,opacity:i=1,color:o}){const l=1e-6,u=new t.Vector3,c=new t.Vector3,p=new t.Quaternion(0,0,0,1);null==o&&(o=(t,e)=>t.set(.55+.45*Math.cos(1*e.x),.55+.45*Math.cos(1*e.y),.55+.45*Math.cos(1*e.z)));const d=new t.Color;for(let t=n.min.z;t<n.max.z+l;t+=a)for(let h=n.min.y;h<n.max.y+l;h+=a)for(let x=n.min.x;x<n.max.x+l;x+=a){u.set(x,h,t);for(let t=0;t<2;++t)c.setScalar(s*(t?1:r)),t?"function"==typeof o?o(d,u):d.copy(o):d.setScalar(0),e.pushSplat(u,c,p,i,d)}},exports.constructSpherePoints=function({splats:e,origin:n=new t.Vector3,radius:a=1,maxDepth:s=3,filter:r=null,pointRadius:i=.02,pointThickness:o=.001,color:l=new t.Color(1,1,1)}){const u={};function c(t){if(r&&!r(t))return;const e=`${t.x},${t.y},${t.z}`;u[e]||(u[e]=t)}function p(e,n,a,r){if(c(n),c(a),c(r),e>=s)return;const i=(new t.Vector3).addVectors(n,a).normalize(),o=(new t.Vector3).addVectors(a,r).normalize(),l=(new t.Vector3).addVectors(r,n).normalize();p(e+1,n,i,l),p(e+1,i,a,o),p(e+1,l,o,r),p(e+1,i,o,l)}for(const m of[-1,1])for(const e of[-1,1])for(const n of[-1,1]){p(0,new t.Vector3(m,0,0),new t.Vector3(0,e,0),new t.Vector3(0,0,n))}const d=Object.values(u),h=new t.Vector3(i,i,o),x=new t.Quaternion,f="function"==typeof l?new t.Color:l;for(const m of d)x.setFromUnitVectors(new t.Vector3(0,0,-1),m),"function"==typeof l&&l(f,m),m.multiplyScalar(a),m.add(n),e.pushSplat(m,h,x,1,f)},exports.defines=c,exports.dyno=po,exports.flipPixels=la,exports.floatToSint8=Gn,exports.floatToUint8=On,exports.fromHalf=Nn,exports.generators=gu,exports.getSplatFileType=Dl,exports.imageSplats=function({url:e,dotRadius:n,subXY:a,forEachSplat:s}){return n=n??.8,a=Math.max(1,Math.floor(a??1)),new Yl({constructSplats:async r=>new Promise(((i,o)=>{const l=new Image;l.crossOrigin="anonymous",l.onerror=o,l.onload=()=>{const{width:e,height:u}=l,c=document.createElement("canvas");c.width=e,c.height=u;const p=c.getContext("2d");if(!p)return void o(new Error("Failed to create canvas context"));p.imageSmoothingEnabled=!0,p.imageSmoothingQuality="high";const d=Math.round(e/a),h=Math.round(u/a);p.drawImage(l,0,0,d,h);try{const e=p.getImageData(0,0,d,h),a=new Uint8Array(e.data.buffer),o=new t.Vector3,l=(new t.Vector3).setScalar(n),u=new t.Quaternion(0,0,0,1),c=new t.Color;let x=0;for(let t=0;t<h;++t)for(let e=0;e<d;++e){const i=4*x,p=a[i+3];if(p>0){let f=p/255;c.set(a[i+0]/255,a[i+1]/255,a[i+2]/255),o.set(e-.5*(d-1),.5*(h-1)-t,0),l.setScalar(n),u.set(0,0,0,1);let m=!0;if(s){const t=s(d,h,x,o,l,u,f,c);f=t??f,m=null!==t}m&&r.pushSplat(o,l,u,f,c)}x+=1}i()}catch(x){o(x)}},l.src=e}))})},exports.isAndroid=aa,exports.isIos=ia,exports.isMobile=na,exports.isOculus=sa,exports.isQuest2=ra,exports.isVisionPro=oa,exports.lerpHandsSnapshots=function(t,e){if(!t.length)return null;const n=t[0],a=t[t.length-1];if(e<n.time||e>a.time)return null;const s=function(t,e){let n=0,a=t.length-1;for(;n<=a;){const s=n+a>>1;t[s].time<=e?n=s+1:a=s-1}return a}(t,e);if(-1===s)return null;const r=t[s],i=t[s+1];if(!i)return function(t,e){return{time:e,hands:t.hands.map((t=>function(t){if(!t)return;const e={};for(const n of $u){const a=t[n];a&&(e[n]=Bu(a))}return e}(t)))}}(r,e);const o=i.time-r.time;return function(t,e,n,a){const s=Math.max(t.hands.length,e.hands.length),r=Array.from({length:s},((a,s)=>function(t,e,n=0){if(!t||!e)return;const a={};for(const s of $u){const r=Vu(t[s],e[s],n);r&&(a[s]=r)}return a}(t.hands[s],e.hands[s],n)));return{time:a,hands:r}}(r,i,o>0?(e-r.time)/o:0,e)},exports.modifiers=bu,exports.pixelsToPngUrl=ua,exports.readRgbaArray=function(t,e){return new B({inTypes:{rgba:Vl,index:"int"},outTypes:{rgba:"vec4"},inputs:{rgba:t,index:e},globals:()=>[Bl],statements:({inputs:t,outputs:e})=>W(`\n if ((${t.index} >= 0) && (${t.index} < ${t.rgba}.count)) {\n ${e.rgba} = texelFetch(${t.rgba}.texture, splatTexCoord(${t.index}), 0);\n } else {\n ${e.rgba} = vec4(0.0, 0.0, 0.0, 0.0);\n }\n `)}).outputs.rgba},exports.setPackedSplat=Yn,exports.textSplats=function({text:e,font:n,fontSize:a,color:s,rgb:r,dotRadius:i,textAlign:o,lineHeight:l,objectScale:u}){n=n??"Arial",a=a??32,s=s??new t.Color(1,1,1),i=i??.8,o=o??"start",l=l??1,u=u??1;const c=e.split("\n"),p=document.createElement("canvas"),d=p.getContext("2d");if(!d)throw new Error("Failed to create canvas context");d.font=`${a}px ${n}`,d.textAlign=o;const h=d.measureText(""),x=h.fontBoundingBoxAscent+h.fontBoundingBoxDescent;let f=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,y=Number.POSITIVE_INFINITY,g=Number.NEGATIVE_INFINITY;for(let t=0;t<c.length;++t){const e=d.measureText(c[t]),n=x*l*t;f=Math.min(f,-e.actualBoundingBoxLeft),m=Math.max(m,e.actualBoundingBoxRight),y=Math.min(y,n-e.actualBoundingBoxAscent),g=Math.max(g,n+e.actualBoundingBoxDescent)}const v=Math.floor(f),w=Math.floor(y),b=Math.ceil(m)-v,S=Math.ceil(g)-w;p.width=b,p.height=S,d.font=`${a}px ${n}`,d.textAlign=o,d.textBaseline="alphabetic",d.fillStyle="#FFFFFF";for(let t=0;t<c.length;++t){const e=x*l*t-w;d.fillText(c[t],-v,e)}const T=d.getImageData(0,0,b,S),_=new Uint8Array(T.data.buffer),M=new bl,k=new t.Vector3,$=(new t.Vector3).setScalar(i*u),D=new t.Quaternion(0,0,0,1);r=r??new t.Color(1,1,1);let z=0;for(let t=0;t<S;++t)for(let e=0;e<b;++e){const n=_[z+3];if(n>0){const a=n/255;k.set(e-.5*(b-1),.5*(S-1)-t,0),k.multiplyScalar(u),M.pushSplat(k,$,D,a,r)}z+=4}const I=new Yl({packedSplats:M});return I.recolor=s,I},exports.toHalf=Bn,exports.transcodeSpz=async function(t){var e,n,a;const s=[],{inputs:r,clipXyz:i,maxSh:o,fractionalBits:l=12,opacityThreshold:u}=t;for(const p of r){const t=(null==(e=p.transform)?void 0:e.scale)??1,r=(null==(n=p.transform)?void 0:n.quaternion)??[0,0,0,1],o=(null==(a=p.transform)?void 0:a.translate)??[0,0,0],l=i?[...i.min,...i.max]:void 0;let c=p.fileType;c||(c=Dl(p.fileBytes),!c&&p.pathOrUrl&&(c=zl(p.pathOrUrl)));const d=Lo(c,p.pathOrUrl),h=p.fileBytes,x=1048576;for(let e=0;e<h.length;e+=x)d.push(h.subarray(e,Math.min(e+x,h.length)));const f=d.finish();f.transform({translation:o,rotation:r,scale:t,clip:l,opacityThreshold:u??0}),s.push(f)}const c=s[0];for(let p=1;p<s.length;p++)c.concat(s[p]);return{fileBytes:c.encode_to_spz(o??3,l),clippedCount:0}},exports.unpackSplat=ta,exports.utils=Ta,exports.writeSpz=function(t,e,n){if(!t.packedArray)throw new Error("");return{fileBytes:function(t,e,n,a){const s=cl.packedsplats_to_gsplatarray(t,e,al(n)?0:Oo(n),a);if(s[2])throw rl(s[1]);return Po.__wrap(s[0])}(t.numSplats,t.packedArray,t.extra,t.splatEncoding).encode_to_spz(e??3,n??12)}};
|