glodrei
Version:
useful add-ons for react-three-fiber
1 lines • 375 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("react-dom/client"),n=require("three"),a=require("@react-three/fiber"),o=require("zustand"),i=require("@use-gesture/react"),s=require("maath"),l=require("@react-spring/three"),c=require("zustand/middleware"),u=require("three-stdlib"),d=require("zustand/shallow"),m=require("troika-three-text"),f=require("suspend-react"),p=require("meshline"),h=require("camera-controls"),x=require("hls.js"),y=require("stats.js"),v=require("stats-gl"),g=require("detect-gpu"),w=require("three-mesh-bvh"),z=require("react-composer"),b=require("@monogrid/gainmap-js"),E=require("uuid"),M=require("tunnel-rat");function S(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function T(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var C=S(e),P=T(t),R=T(r),D=T(n),F=S(h),k=S(y),_=S(v),A=S(z),L=S(M);const I=new n.Vector3,B=new n.Vector3,V=new n.Vector3,U=new n.Vector2;function O(e,t,r){const n=I.setFromMatrixPosition(e.matrixWorld);n.project(t);const a=r.width/2,o=r.height/2;return[n.x*a+a,-n.y*o+o]}const N=e=>Math.abs(e)<1e-10?0:e;function j(e,t,r=""){let n="matrix3d(";for(let r=0;16!==r;r++)n+=N(t[r]*e.elements[r])+(15!==r?",":")");return r+n}const W=(G=[1,-1,1,1,1,-1,1,1,1,-1,1,1,1,-1,1,1],e=>j(e,G));var G;const H=(e,t)=>{return j(e,[1/(r=t),1/r,1/r,1,-1/r,-1/r,-1/r,-1,1/r,1/r,1/r,1,1,1,1,1],"translate(-50%,-50%)");var r};const $=P.forwardRef((({children:e,eps:t=.001,style:r,className:o,prepend:i,center:s,fullscreen:l,portal:c,distanceFactor:u,sprite:d=!1,transform:m=!1,occlude:f,onOcclude:p,castShadow:h,receiveShadow:x,material:y,geometry:v,zIndexRange:g=[16777271,0],calculatePosition:w=O,as:z="div",wrapperClass:b,pointerEvents:E="auto",...M},S)=>{const{gl:T,camera:D,scene:F,size:k,raycaster:_,events:A,viewport:L}=a.useThree(),[j]=P.useState((()=>document.createElement(z))),G=P.useRef(),$=P.useRef(null),q=P.useRef(0),X=P.useRef([0,0]),Z=P.useRef(null),Y=P.useRef(null),Q=(null==c?void 0:c.current)||A.connected||T.domElement.parentNode,K=P.useRef(null),J=P.useRef(!1),ee=P.useMemo((()=>f&&"blending"!==f||Array.isArray(f)&&f.length&&function(e){return e&&"object"==typeof e&&"current"in e}(f[0])),[f]);P.useLayoutEffect((()=>{const e=T.domElement;f&&"blending"===f?(e.style.zIndex=`${Math.floor(g[0]/2)}`,e.style.position="absolute",e.style.pointerEvents="none"):(e.style.zIndex=null,e.style.position=null,e.style.pointerEvents=null)}),[f]),P.useLayoutEffect((()=>{if($.current){const e=G.current=R.createRoot(j);if(F.updateMatrixWorld(),m)j.style.cssText="position:absolute;top:0;left:0;pointer-events:none;overflow:hidden;";else{const e=w($.current,D,k);j.style.cssText=`position:absolute;top:0;left:0;transform:translate3d(${e[0]}px,${e[1]}px,0);transform-origin:0 0;`}return Q&&(i?Q.prepend(j):Q.appendChild(j)),()=>{Q&&Q.removeChild(j),e.unmount()}}}),[Q,m]),P.useLayoutEffect((()=>{b&&(j.className=b)}),[b]);const te=P.useMemo((()=>m?{position:"absolute",top:0,left:0,width:k.width,height:k.height,transformStyle:"preserve-3d",pointerEvents:"none"}:{position:"absolute",transform:s?"translate3d(-50%,-50%,0)":"none",...l&&{top:-k.height/2,left:-k.width/2,width:k.width,height:k.height},...r}),[r,s,l,k,m]),re=P.useMemo((()=>({position:"absolute",pointerEvents:E})),[E]);P.useLayoutEffect((()=>{var t,n;(J.current=!1,m)?null==(t=G.current)||t.render(P.createElement("div",{ref:Z,style:te},P.createElement("div",{ref:Y,style:re},P.createElement("div",{ref:S,className:o,style:r,children:e})))):null==(n=G.current)||n.render(P.createElement("div",{ref:S,style:te,className:o,children:e}))}));const ne=P.useRef(!0);a.useFrame((e=>{if($.current){D.updateMatrixWorld(),$.current.updateWorldMatrix(!0,!1);const e=m?X.current:w($.current,D,k);if(m||Math.abs(q.current-D.zoom)>t||Math.abs(X.current[0]-e[0])>t||Math.abs(X.current[1]-e[1])>t){const t=function(e,t){const r=I.setFromMatrixPosition(e.matrixWorld),n=B.setFromMatrixPosition(t.matrixWorld),a=r.sub(n),o=t.getWorldDirection(V);return a.angleTo(o)>Math.PI/2}($.current,D);let r=!1;ee&&(Array.isArray(f)?r=f.map((e=>e.current)):"blending"!==f&&(r=[F]));const a=ne.current;if(r){const e=function(e,t,r,n){const a=I.setFromMatrixPosition(e.matrixWorld),o=a.clone();o.project(t),U.set(o.x,o.y),r.setFromCamera(U,t);const i=r.intersectObjects(n,!0);if(i.length){const e=i[0].distance;return a.distanceTo(r.ray.origin)<e}return!0}($.current,D,_,r);ne.current=e&&!t}else ne.current=!t;a!==ne.current&&(p?p(!ne.current):j.style.display=ne.current?"block":"none");const o=Math.floor(g[0]/2),i=f?ee?[g[0],o]:[o-1,0]:g;if(j.style.zIndex=`${function(e,t,r){if(t instanceof n.PerspectiveCamera||t instanceof n.OrthographicCamera){const n=I.setFromMatrixPosition(e.matrixWorld),a=B.setFromMatrixPosition(t.matrixWorld),o=n.distanceTo(a),i=(r[1]-r[0])/(t.far-t.near),s=r[1]-i*t.far;return Math.round(i*o+s)}}($.current,D,i)}`,m){const[e,t]=[k.width/2,k.height/2],r=D.projectionMatrix.elements[5]*t,{isOrthographicCamera:n,top:a,left:o,bottom:i,right:s}=D,l=W(D.matrixWorldInverse),c=n?`scale(${r})translate(${N(-(s+o)/2)}px,${N((a+i)/2)}px)`:`translateZ(${r}px)`;let m=$.current.matrixWorld;d&&(m=D.matrixWorldInverse.clone().transpose().copyPosition(m).scale($.current.scale),m.elements[3]=m.elements[7]=m.elements[11]=0,m.elements[15]=1),j.style.width=k.width+"px",j.style.height=k.height+"px",j.style.perspective=n?"":`${r}px`,Z.current&&Y.current&&(Z.current.style.transform=`${c}${l}translate(${e}px,${t}px)`,Y.current.style.transform=H(m,1/((u||10)/400)))}else{const t=void 0===u?1:function(e,t){if(t instanceof n.OrthographicCamera)return t.zoom;if(t instanceof n.PerspectiveCamera){const r=I.setFromMatrixPosition(e.matrixWorld),n=B.setFromMatrixPosition(t.matrixWorld),a=t.fov*Math.PI/180,o=r.distanceTo(n);return 1/(2*Math.tan(a/2)*o)}return 1}($.current,D)*u;j.style.transform=`translate3d(${e[0]}px,${e[1]}px,0) scale(${t})`}X.current=e,q.current=D.zoom}}if(!ee&&K.current&&!J.current)if(m){if(Z.current){const e=Z.current.children[0];if(null!=e&&e.clientWidth&&null!=e&&e.clientHeight){const{isOrthographicCamera:t}=D;if(t||v)M.scale&&(Array.isArray(M.scale)?M.scale instanceof n.Vector3?K.current.scale.copy(M.scale.clone().divideScalar(1)):K.current.scale.set(1/M.scale[0],1/M.scale[1],1/M.scale[2]):K.current.scale.setScalar(1/M.scale));else{const t=(u||10)/400,r=e.clientWidth*t,n=e.clientHeight*t;K.current.scale.set(r,n,1)}J.current=!0}}}else{const t=j.children[0];if(null!=t&&t.clientWidth&&null!=t&&t.clientHeight){const e=1/L.factor,r=t.clientWidth*e,n=t.clientHeight*e;K.current.scale.set(r,n,1),J.current=!0}K.current.lookAt(e.camera.position)}}));const ae=P.useMemo((()=>({vertexShader:m?void 0:'\n /*\n This shader is from the THREE\'s SpriteMaterial.\n We need to turn the backing plane into a Sprite\n (make it always face the camera) if "transfrom"\n is false.\n */\n #include <common>\n\n void main() {\n vec2 center = vec2(0., 1.);\n float rotation = 0.0;\n\n // This is somewhat arbitrary, but it seems to work well\n // Need to figure out how to derive this dynamically if it even matters\n float size = 0.03;\n\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale * size;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n\n gl_Position = projectionMatrix * mvPosition;\n }\n ',fragmentShader:"\n void main() {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n }\n "})),[m]);return P.createElement("group",C.default({},M,{ref:$}),f&&!ee&&P.createElement("mesh",{castShadow:h,receiveShadow:x,ref:K},v||P.createElement("planeGeometry",null),y||P.createElement("shaderMaterial",{side:n.DoubleSide,vertexShader:ae.vertexShader,fragmentShader:ae.fragmentShader})))}));let q=0;const X=o.create((e=>(n.DefaultLoadingManager.onStart=(t,r,n)=>{e({active:!0,item:t,loaded:r,total:n,progress:(r-q)/(n-q)*100})},n.DefaultLoadingManager.onLoad=()=>{e({active:!1})},n.DefaultLoadingManager.onError=t=>e((e=>({errors:[...e.errors,t]}))),n.DefaultLoadingManager.onProgress=(t,r,n)=>{r===n&&(q=n),e({active:!0,item:t,loaded:r,total:n,progress:(r-q)/(n-q)*100||100})},{errors:[],active:!1,progress:0,item:"",loaded:0,total:0})));const Z=e=>`Loading ${e.toFixed(2)}%`;const Y={container:{position:"absolute",top:0,left:0,width:"100%",height:"100%",background:"#171717",display:"flex",alignItems:"center",justifyContent:"center",transition:"opacity 300ms ease",zIndex:1e3},inner:{width:100,height:3,background:"#272727",textAlign:"center"},bar:{height:3,width:"100%",background:"white",transition:"transform 200ms",transformOrigin:"left center"},data:{display:"inline-block",position:"relative",fontVariantNumeric:"tabular-nums",marginTop:"0.8em",color:"#f0f0f0",fontSize:"0.6em",fontFamily:'-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", Helvetica, Arial, Roboto, Ubuntu, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',whiteSpace:"nowrap"}},Q=P.createContext(null);function K(){return P.useContext(Q)}const J=P.forwardRef((({children:e},t)=>{const r=P.useRef(null);P.useImperativeHandle(t,(()=>r.current),[]);const n=K(),{width:o,height:i}=a.useThree((e=>e.viewport));return a.useFrame((()=>{r.current.position.x=n.horizontal?-o*(n.pages-1)*n.offset:0,r.current.position.y=n.horizontal?0:i*(n.pages-1)*n.offset})),P.createElement("group",{ref:r},e)})),ee=P.forwardRef((({children:e,style:t,...r},n)=>{const o=K(),i=P.useRef(null);P.useImperativeHandle(n,(()=>i.current),[]);const{width:s,height:l}=a.useThree((e=>e.size)),c=P.useContext(a.context),u=P.useMemo((()=>R.createRoot(o.fixed)),[o.fixed]);return a.useFrame((()=>{o.delta>o.eps&&(i.current.style.transform=`translate3d(${o.horizontal?-s*(o.pages-1)*o.offset:0}px,${o.horizontal?0:l*(o.pages-1)*-o.offset}px,0)`)})),u.render(P.createElement("div",C.default({ref:i,style:{...t,position:"absolute",top:0,left:0,willChange:"transform"}},r),P.createElement(Q.Provider,{value:o},P.createElement(a.context.Provider,{value:c},e)))),null})),te=P.forwardRef((({html:e,...t},r)=>{const n=e?ee:J;return P.createElement(n,C.default({ref:r},t))}));const re=P.createContext(null);const ne=P.createContext([]);const ae=P.forwardRef((function({children:e,follow:t=!0,lockX:r=!1,lockY:o=!1,lockZ:i=!1,...s},l){const c=P.useRef(null),u=P.useRef(null),d=new n.Quaternion;return a.useFrame((({camera:e})=>{if(!t||!u.current)return;const n=u.current.rotation.clone();u.current.updateMatrix(),u.current.updateWorldMatrix(!1,!1),u.current.getWorldQuaternion(d),e.getWorldQuaternion(c.current.quaternion).premultiply(d.invert()),r&&(u.current.rotation.x=n.x),o&&(u.current.rotation.y=n.y),i&&(u.current.rotation.z=n.z)})),P.useImperativeHandle(l,(()=>u.current),[]),P.createElement("group",C.default({ref:u},s),P.createElement("group",{ref:c},e))})),oe=P.forwardRef((({children:e,depth:t=-1,...r},n)=>{const o=P.useRef(null);return P.useImperativeHandle(n,(()=>o.current),[]),a.useFrame((({camera:e})=>{o.current.quaternion.copy(e.quaternion),o.current.position.copy(e.position)})),P.createElement("group",C.default({ref:o},r),P.createElement("group",{"position-z":-t},e))})),ie=new D.Vector3,se=new D.Vector3,le=new D.Vector3,ce=(e,t,r,n=1)=>{const a=ie.set(e.x/r.width*2-1,-e.y/r.height*2+1,n);return a.unproject(t),a},ue=(e,t,r,n)=>{const a=((e,t,r)=>{const n=r.width/2,a=r.height/2;t.updateMatrixWorld(!1);const o=e.project(t);return o.x=o.x*n+n,o.y=-o.y*a+a,o})(le.copy(e),r,n);let o=0;for(let i=0;i<2;++i){const s=se.copy(a).setComponent(i,a.getComponent(i)+t),l=ce(s,r,n,s.z);o=Math.max(o,e.distanceTo(l))}return o},de=new n.Vector3,me=t.forwardRef((({scale:e=1,...r},n)=>{const o=t.useRef(null);return P.useImperativeHandle(n,(()=>o.current),[]),a.useFrame((t=>{const r=o.current;if(!r)return;const n=ue(r.getWorldPosition(de),e,t.camera,t.size);r.scale.setScalar(n*e)})),P.createElement("object3D",C.default({ref:o},r))})),fe=P.forwardRef((function({points:e,color:t=16777215,vertexColors:r,linewidth:o,lineWidth:i,segments:s,dashed:l,...c},d){var m,f;const p=a.useThree((e=>e.size)),h=P.useMemo((()=>s?new u.LineSegments2:new u.Line2),[s]),[x]=P.useState((()=>new u.LineMaterial)),y=4===(null==r||null==(m=r[0])?void 0:m.length)?4:3,v=P.useMemo((()=>{const a=s?new u.LineSegmentsGeometry:new u.LineGeometry,o=e.map((e=>{const t=Array.isArray(e);return e instanceof n.Vector3||e instanceof n.Vector4?[e.x,e.y,e.z]:e instanceof n.Vector2?[e.x,e.y,0]:t&&3===e.length?[e[0],e[1],e[2]]:t&&2===e.length?[e[0],e[1],0]:e}));if(a.setPositions(o.flat()),r){t=16777215;const e=r.map((e=>e instanceof n.Color?e.toArray():e));a.setColors(e.flat(),y)}return a}),[e,s,r,y]);return P.useLayoutEffect((()=>{h.computeLineDistances()}),[e,h]),P.useLayoutEffect((()=>{l?x.defines.USE_DASH="":delete x.defines.USE_DASH,x.needsUpdate=!0}),[l,x]),P.useEffect((()=>()=>{v.dispose(),x.dispose()}),[v]),P.createElement("primitive",C.default({object:h,ref:d},c),P.createElement("primitive",{object:v,attach:"geometry"}),P.createElement("primitive",C.default({object:x,attach:"material",color:t,vertexColors:Boolean(r),resolution:[p.width,p.height],linewidth:null!==(f=null!=o?o:i)&&void 0!==f?f:1,dashed:l,transparent:4===y},c)))})),pe=new n.Vector3,he=P.forwardRef((function({start:e=[0,0,0],end:t=[0,0,0],mid:r,segments:a=20,...o},i){const s=P.useRef(null);P.useImperativeHandle(i,(()=>s.current));const[l]=P.useState((()=>new n.QuadraticBezierCurve3(void 0,void 0,void 0))),c=P.useCallback(((e,t,r,a=20)=>(e instanceof n.Vector3?l.v0.copy(e):l.v0.set(...e),t instanceof n.Vector3?l.v2.copy(t):l.v2.set(...t),r instanceof n.Vector3?l.v1.copy(r):Array.isArray(r)?l.v1.set(...r):l.v1.copy(l.v0.clone().add(l.v2.clone().sub(l.v0)).add(pe.set(0,l.v0.y-l.v2.y,0))),l.getPoints(a))),[]);P.useLayoutEffect((()=>{s.current.setPoints=(e,t,r)=>{const n=c(e,t,r);s.current.geometry&&s.current.geometry.setPositions(n.map((e=>e.toArray())).flat())}}),[]);const u=P.useMemo((()=>c(e,t,r,a)),[e,t,r,a]);return P.createElement(fe,C.default({ref:s,points:u},o))})),xe=P.forwardRef((function({start:e,end:t,midA:r,midB:a,segments:o=20,...i},s){const l=P.useMemo((()=>{const i=e instanceof n.Vector3?e:new n.Vector3(...e),s=t instanceof n.Vector3?t:new n.Vector3(...t),l=r instanceof n.Vector3?r:new n.Vector3(...r),c=a instanceof n.Vector3?a:new n.Vector3(...a);return new n.CubicBezierCurve3(i,l,c,s).getPoints(o)}),[e,t,r,a,o]);return P.createElement(fe,C.default({ref:s,points:l},i))})),ye=P.forwardRef((function({points:e,closed:t=!1,curveType:r="centripetal",tension:a=.5,segments:o=20,vertexColors:i,...s},l){const c=P.useMemo((()=>{const o=e.map((e=>e instanceof n.Vector3?e:new n.Vector3(...e)));return new n.CatmullRomCurve3(o,t,r,a)}),[e,t,r,a]),u=P.useMemo((()=>c.getPoints(o)),[c,o]),d=P.useMemo((()=>{if(!i||i.length<2)return;if(i.length===o+1)return i;const e=i.map((e=>e instanceof n.Color?e:new n.Color(...e)));t&&e.push(e[0].clone());const r=[e[0]],a=o/(e.length-1);for(let t=1;t<o;t++){const n=t%a/a,o=Math.floor(t/a);r.push(e[o].clone().lerp(e[o+1],n))}return r.push(e[e.length-1]),r}),[i,o]);return P.createElement(fe,C.default({ref:l,points:u,vertexColors:d},s))})),ve=P.forwardRef((({url:e,distance:t=1,loop:r=!0,autoplay:o,...i},s)=>{const l=P.useRef(null);P.useImperativeHandle(s,(()=>l.current),[]);const c=a.useThree((({camera:e})=>e)),[u]=P.useState((()=>new n.AudioListener)),d=a.useLoader(n.AudioLoader,e);return P.useEffect((()=>{const e=l.current;e&&(e.setBuffer(d),e.setRefDistance(t),e.setLoop(r),o&&!e.isPlaying&&e.play())}),[d,c,t,r]),P.useEffect((()=>{const e=l.current;return c.add(u),()=>{c.remove(u),e&&(e.isPlaying&&e.stop(),e.source&&e.source._connected&&e.disconnect())}}),[]),P.createElement("positionalAudio",C.default({ref:l,args:[u]},i))})),ge=P.forwardRef((({sdfGlyphSize:e=64,anchorX:t="center",anchorY:r="middle",font:n,fontSize:o=1,children:i,characters:s,onSync:l,...c},u)=>{const d=a.useThree((({invalidate:e})=>e)),[p]=P.useState((()=>new m.Text)),[h,x]=P.useMemo((()=>{const e=[];let t="";return P.Children.forEach(i,(r=>{"string"==typeof r||"number"==typeof r?t+=r:e.push(r)})),[e,t]}),[i]);return f.suspend((()=>new Promise((e=>m.preloadFont({font:n,characters:s},e)))),["troika-text",n,s]),P.useLayoutEffect((()=>{p.sync((()=>{d(),l&&l(p)}))})),P.useEffect((()=>()=>p.dispose()),[p]),P.createElement("primitive",C.default({object:p,ref:u,font:n,text:x,anchorX:t,anchorY:r,fontSize:o,sdfGlyphSize:e},c),h)}));let we=null;async function ze(e){const t=await async function(e){return"string"==typeof e?await(await fetch(e)).json():e}(e);return r=t,we||(we=new u.FontLoader),we.parse(r);var r}function be(e){return f.suspend(ze,[e])}be.preload=e=>f.preload(ze,[e]),be.clear=e=>f.clear([e]);const Ee=["string","number"],Me=P.forwardRef((({font:e,letterSpacing:r=0,lineHeight:n=1,size:o=1,height:i=.2,bevelThickness:s=.1,bevelSize:l=.01,bevelEnabled:c=!1,bevelOffset:d=0,bevelSegments:m=4,curveSegments:f=8,smooth:p,children:h,...x},y)=>{P.useMemo((()=>a.extend({RenamedTextGeometry:u.TextGeometry})),[]);const v=P.useRef(null),g=be(e),w=t.useMemo((()=>({font:g,size:o,height:i,bevelThickness:s,bevelSize:l,bevelEnabled:c,bevelSegments:m,bevelOffset:d,curveSegments:f,letterSpacing:r,lineHeight:n})),[g,o,i,s,l,c,m,d,f,r,n]),[z,...b]=t.useMemo((()=>(e=>{let t="";const r=[];return P.Children.forEach(e,(e=>{Ee.includes(typeof e)?t+=e+"":r.push(e)})),[t,...r]})(h)),[h]),E=P.useMemo((()=>[z,w]),[z,w]);return P.useLayoutEffect((()=>{p&&(v.current.geometry=u.mergeVertices(v.current.geometry,p),v.current.geometry.computeVertexNormals())}),[E,p]),P.useImperativeHandle(y,(()=>v.current),[]),P.createElement("mesh",C.default({},x,{ref:v}),P.createElement("renamedTextGeometry",{args:E}),b)})),Se=P.forwardRef((({children:e,multisamping:t=8,renderIndex:r=1,disableRender:o,disableGamma:i,disableRenderPass:s,depthBuffer:l=!0,stencilBuffer:c=!1,anisotropy:d=1,encoding:m,type:f,...p},h)=>{P.useMemo((()=>a.extend({EffectComposer:u.EffectComposer,RenderPass:u.RenderPass,ShaderPass:u.ShaderPass})),[]);const x=P.useRef(null);P.useImperativeHandle(h,(()=>x.current),[]);const{scene:y,camera:v,gl:g,size:w,viewport:z}=a.useThree(),[b]=P.useState((()=>{const e=new n.WebGLRenderTarget(w.width,w.height,{type:f||n.HalfFloatType,format:n.RGBAFormat,depthBuffer:l,stencilBuffer:c,anisotropy:d});return f===n.UnsignedByteType&&null!=m&&("colorSpace"in e?e.texture.colorSpace=m:e.texture.encoding=m),e.samples=t,e}));P.useEffect((()=>{var e,t;null==(e=x.current)||e.setSize(w.width,w.height),null==(t=x.current)||t.setPixelRatio(z.dpr)}),[g,w,z.dpr]),a.useFrame((()=>{var e;o||null==(e=x.current)||e.render()}),r);const E=[];return s||E.push(P.createElement("renderPass",{key:"renderpass",attach:`passes-${E.length}`,args:[y,v]})),i||E.push(P.createElement("shaderPass",{attach:`passes-${E.length}`,key:"gammapass",args:[u.GammaCorrectionShader]})),P.Children.forEach(e,(e=>{e&&E.push(P.cloneElement(e,{key:E.length,attach:`passes-${E.length}`}))})),P.createElement("effectComposer",C.default({ref:x,args:[g,b]},p),E)}));let Te=function(e){return e.Linear="linear",e.Radial="radial",e}({});function Ce(e,t,r,n){const a=class extends D.ShaderMaterial{constructor(a={}){const o=Object.entries(e);super({uniforms:o.reduce(((e,[t,r])=>({...e,...D.UniformsUtils.clone({[t]:{value:r}})})),{}),vertexShader:t,fragmentShader:r}),this.key="",o.forEach((([e])=>Object.defineProperty(this,e,{get:()=>this.uniforms[e].value,set:t=>this.uniforms[e].value=t}))),Object.assign(this,a),n&&n(this)}};return a.key=D.MathUtils.generateUUID(),a}const Pe=e=>e===Object(e)&&!Array.isArray(e)&&"function"!=typeof e;function Re(e,r){const o=a.useThree((e=>e.gl)),i=a.useLoader(n.TextureLoader,Pe(e)?Object.values(e):e);t.useLayoutEffect((()=>{null==r||r(i)}),[r]),t.useEffect((()=>{if("initTexture"in o){let e=[];Array.isArray(i)?e=i:i instanceof n.Texture?e=[i]:Pe(i)&&(e=Object.values(i)),e.forEach((e=>{e instanceof n.Texture&&o.initTexture(e)}))}}),[o,i]);const s=t.useMemo((()=>{if(Pe(e)){const t={};let r=0;for(const n in e)t[n]=i[r++];return t}return i}),[e,i]);return s}Re.preload=e=>a.useLoader.preload(n.TextureLoader,e),Re.clear=e=>a.useLoader.clear(n.TextureLoader,e);const De=(()=>parseInt(n.REVISION.replace(/\D+/g,"")))(),Fe=Ce({color:new D.Color("white"),scale:new D.Vector2(1,1),imageBounds:new D.Vector2(1,1),resolution:1024,map:null,zoom:1,radius:0,grayscale:0,opacity:1},"\n varying vec2 vUv;\n varying vec2 vPos;\n void main() {\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);\n vUv = uv;\n vPos = position.xy;\n }\n",`\n // mostly from https://gist.github.com/statico/df64c5d167362ecf7b34fca0b1459a44\n varying vec2 vUv;\n varying vec2 vPos;\n uniform vec2 scale;\n uniform vec2 imageBounds;\n uniform float resolution;\n uniform vec3 color;\n uniform sampler2D map;\n uniform float radius;\n uniform float zoom;\n uniform float grayscale;\n uniform float opacity;\n const vec3 luma = vec3(.299, 0.587, 0.114);\n vec4 toGrayscale(vec4 color, float intensity) {\n return vec4(mix(color.rgb, vec3(dot(color.rgb, luma)), intensity), color.a);\n }\n vec2 aspect(vec2 size) {\n return size / min(size.x, size.y);\n }\n \n const float PI = 3.14159265;\n \n // from https://iquilezles.org/articles/distfunctions\n float udRoundBox( vec2 p, vec2 b, float r ) {\n return length(max(abs(p)-b+r,0.0))-r;\n }\n\n void main() {\n vec2 s = aspect(scale);\n vec2 i = aspect(imageBounds);\n float rs = s.x / s.y;\n float ri = i.x / i.y;\n vec2 new = rs < ri ? vec2(i.x * s.y / i.y, s.y) : vec2(s.x, i.y * s.x / i.x);\n vec2 offset = (rs < ri ? vec2((new.x - s.x) / 2.0, 0.0) : vec2(0.0, (new.y - s.y) / 2.0)) / new;\n vec2 uv = vUv * s / new + offset;\n vec2 zUv = (uv - vec2(0.5, 0.5)) / zoom + vec2(0.5, 0.5);\n\n vec2 res = vec2(scale * resolution);\n vec2 halfRes = 0.5 * res;\n float b = udRoundBox(vUv.xy * res - halfRes, halfRes, resolution * radius); \n\t vec3 a = mix(vec3(1.0,0.0,0.0), vec3(0.0,0.0,0.0), smoothstep(0.0, 1.0, b));\n gl_FragColor = toGrayscale(texture2D(map, zUv) * vec4(color, opacity * a), grayscale);\n \n #include <tonemapping_fragment>\n #include <${De>=154?"colorspace_fragment":"encodings_fragment"}>\n }\n`),ke=P.forwardRef((({children:e,color:t,segments:r=1,scale:n=1,zoom:o=1,grayscale:i=0,opacity:s=1,radius:l=0,texture:c,toneMapped:u,transparent:d,side:m,...f},p)=>{a.extend({ImageMaterial:Fe});const h=P.useRef(null),x=a.useThree((e=>e.size)),y=Array.isArray(n)?[n[0],n[1]]:[n,n],v=[c.image.width,c.image.height],g=Math.max(x.width,x.height);return P.useImperativeHandle(p,(()=>h.current),[]),P.useLayoutEffect((()=>{h.current.geometry.parameters&&h.current.material.scale.set(y[0]*h.current.geometry.parameters.width,y[1]*h.current.geometry.parameters.height)}),[y[0],y[1]]),P.createElement("mesh",C.default({ref:h,scale:Array.isArray(n)?[...n,1]:n},f),P.createElement("planeGeometry",{args:[1,1,r,r]}),P.createElement("imageMaterial",{color:t,map:c,zoom:o,grayscale:i,opacity:s,scale:y,imageBounds:v,resolution:g,radius:l,toneMapped:u,transparent:d,side:m,key:Fe.key}),e)})),_e=P.forwardRef((({url:e,...t},r)=>{const n=Re(e);return P.createElement(ke,C.default({},t,{texture:n,ref:r}))})),Ae=P.forwardRef((({url:e,...t},r)=>P.createElement(ke,C.default({},t,{ref:r})))),Le=P.forwardRef(((e,t)=>{if(e.url)return P.createElement(_e,C.default({},e,{ref:t}));if(e.texture)return P.createElement(Ae,C.default({},e,{ref:t}));throw new Error("<Image /> requires a url or texture")})),Ie=P.forwardRef((({threshold:e=15,geometry:t,...r},n)=>{const a=P.useRef(null);P.useImperativeHandle(n,(()=>a.current),[]);const o=P.useMemo((()=>[0,0,0,1,0,0]),[]),i=P.useRef(),s=P.useRef();return P.useLayoutEffect((()=>{const r=a.current.parent,n=null!=t?t:null==r?void 0:r.geometry;if(!n)return;if(i.current===n&&s.current===e)return;i.current=n,s.current=e;const o=new D.EdgesGeometry(n,e).attributes.position.array;a.current.geometry.setPositions(o),a.current.geometry.attributes.instanceStart.needsUpdate=!0,a.current.geometry.attributes.instanceEnd.needsUpdate=!0,a.current.computeLineDistances()})),P.createElement(fe,C.default({segments:!0,points:o,ref:a,raycast:()=>null},r))})),Be=Ce({screenspace:!1,color:new D.Color("black"),opacity:1,thickness:.05,size:new D.Vector2},"#include <common>\n #include <morphtarget_pars_vertex>\n #include <skinning_pars_vertex>\n uniform float thickness;\n uniform bool screenspace;\n uniform vec2 size;\n void main() {\n #if defined (USE_SKINNING)\n\t #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #endif\n #include <begin_vertex>\n\t #include <morphtarget_vertex>\n\t #include <skinning_vertex>\n #include <project_vertex>\n vec4 tNormal = vec4(normal, 0.0);\n vec4 tPosition = vec4(transformed, 1.0);\n #ifdef USE_INSTANCING\n tNormal = instanceMatrix * tNormal;\n tPosition = instanceMatrix * tPosition;\n #endif\n if (screenspace) {\n vec3 newPosition = tPosition.xyz + tNormal.xyz * thickness;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0); \n } else {\n vec4 clipPosition = projectionMatrix * modelViewMatrix * tPosition;\n vec4 clipNormal = projectionMatrix * modelViewMatrix * tNormal;\n vec2 offset = normalize(clipNormal.xy) * thickness / size * clipPosition.w * 2.0;\n clipPosition.xy += offset;\n gl_Position = clipPosition;\n }\n }",`uniform vec3 color;\n uniform float opacity;\n void main(){\n gl_FragColor = vec4(color, opacity);\n #include <tonemapping_fragment>\n #include <${De>=154?"colorspace_fragment":"encodings_fragment"}>\n }`);const Ve={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},Ue=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function Oe(e,t){const{length:r,local:o,decay:i,interval:s,stride:l}={...Ve,...t},c=P.useRef(),[u]=P.useState((()=>new n.Vector3));P.useLayoutEffect((()=>{e&&(c.current=Float32Array.from({length:10*r*3},((t,r)=>e.position.getComponent(r%3))))}),[r,e]);const d=P.useRef(new n.Vector3),m=P.useRef(0);return a.useFrame((()=>{if(e&&c.current){if(0===m.current){let t;o?t=e.position:(e.getWorldPosition(u),t=u);const r=1*i;for(let e=0;e<r;e++)t.distanceTo(d.current)<l||(Ue(c.current,3),c.current.set(t.toArray(),c.current.length-3));d.current.copy(t)}m.current++,m.current=m.current%s}})),c}const Ne=P.forwardRef(((e,t)=>{const{children:r}=e,{width:o,length:i,decay:s,local:l,stride:c,interval:u}={...Ve,...e},{color:d="hotpink",attenuation:m,target:f}=e,h=a.useThree((e=>e.size)),x=a.useThree((e=>e.scene)),y=P.useRef(null),[v,g]=P.useState(null),w=Oe(v,{length:i,decay:s,local:l,stride:c,interval:u});P.useEffect((()=>{const e=(null==f?void 0:f.current)||y.current.children.find((e=>e instanceof n.Object3D));e&&g(e)}),[w,f]);const z=P.useMemo((()=>new p.MeshLineGeometry),[]),b=P.useMemo((()=>{var e;const t=new p.MeshLineMaterial({lineWidth:.1*o,color:d,sizeAttenuation:1,resolution:new n.Vector2(h.width,h.height)});let a;if(r)if(Array.isArray(r))a=r.find((e=>{const t=e;return"string"==typeof t.type&&"meshLineMaterial"===t.type}));else{const e=r;"string"==typeof e.type&&"meshLineMaterial"===e.type&&(a=e)}return"object"==typeof(null==(e=a)?void 0:e.props)&&t.setValues(a.props),t}),[o,d,h,r]);return P.useEffect((()=>{b.uniforms.resolution.value.set(h.width,h.height)}),[h]),a.useFrame((()=>{w.current&&z.setPoints(w.current,m)})),P.createElement("group",null,a.createPortal(P.createElement("mesh",{ref:t,geometry:z,material:b}),x),P.createElement("group",{ref:y},r))}));function je(e,t=16,r,a,o){const[i,s]=P.useState((()=>{const e=Array.from({length:t},(()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])).flat();return new n.InstancedBufferAttribute(Float32Array.from(e),16)}));return P.useLayoutEffect((()=>{if(void 0===e.current)return;const l=new u.MeshSurfaceSampler(e.current);a&&l.setWeightAttribute(a),l.build();const c=new n.Vector3,d=new n.Vector3,m=new n.Color,f=new n.Object3D;e.current.updateMatrixWorld(!0);for(let n=0;n<t;n++)l.sample(c,d,m),"function"==typeof r?r({dummy:f,sampledMesh:e.current,position:c,normal:d,color:m},n):f.position.copy(c),f.updateMatrix(),null!=o&&o.current&&o.current.setMatrixAt(n,f.matrix),f.matrix.toArray(i.array,16*n);null!=o&&o.current&&(o.current.instanceMatrix.needsUpdate=!0),i.needsUpdate=!0,s(new n.InstancedBufferAttribute(i.array,i.itemSize).copy(i))}),[e,o,a,t,r]),i}const We=P.forwardRef((({isChild:e=!1,object:t,children:r,deep:n,castShadow:a,receiveShadow:o,inject:i,keys:s,...l},c)=>{const d={keys:s,deep:n,inject:i,castShadow:a,receiveShadow:o};if(t=P.useMemo((()=>{if(!1===e&&!Array.isArray(t)){let e=!1;if(t.traverse((t=>{t.isSkinnedMesh&&(e=!0)})),e)return u.SkeletonUtils.clone(t)}return t}),[t,e]),Array.isArray(t))return P.createElement("group",C.default({},l,{ref:c}),t.map((e=>P.createElement(We,C.default({key:e.uuid,object:e},d)))),r);const{children:m,...f}=function(e,{keys:t=["near","far","color","distance","decay","penumbra","angle","intensity","skeleton","visible","castShadow","receiveShadow","morphTargetDictionary","morphTargetInfluences","name","geometry","material","position","rotation","scale","up","userData","bindMode","bindMatrix","bindMatrixInverse","skeleton"],deep:r,inject:n,castShadow:a,receiveShadow:o}){let i={};for(const r of t)i[r]=e[r];return r&&(i.geometry&&"materialsOnly"!==r&&(i.geometry=i.geometry.clone()),i.material&&"geometriesOnly"!==r&&(i.material=i.material.clone())),n&&(i="function"==typeof n?{...i,children:n(e)}:P.isValidElement(n)?{...i,children:n}:{...i,...n}),e instanceof D.Mesh&&(a&&(i.castShadow=!0),o&&(i.receiveShadow=!0)),i}(t,d),p=t.type[0].toLowerCase()+t.type.slice(1);return P.createElement(p,C.default({},f,l,{ref:c}),t.children.map((e=>"Bone"===e.type?P.createElement("primitive",C.default({key:e.uuid,object:e},d)):P.createElement(We,C.default({key:e.uuid,object:e},d,{isChild:!0})))),r,m)})),Ge=P.createContext(null),He=P.forwardRef((({resolution:e=28,maxPolyCount:t=1e4,enableUvs:r=!1,enableColors:n=!1,children:o,...i},s)=>{const l=P.useRef(null);P.useImperativeHandle(s,(()=>l.current),[]);const c=P.useMemo((()=>new u.MarchingCubes(e,null,r,n,t)),[e,t,r,n]),d=P.useMemo((()=>({getParent:()=>l})),[]);return a.useFrame((()=>{c.update(),c.reset()}),-1),P.createElement(P.Fragment,null,P.createElement("primitive",C.default({object:c,ref:l},i),P.createElement(Ge.Provider,{value:d},o)))})),$e=P.forwardRef((({strength:e=.5,subtract:t=12,color:r,...n},o)=>{const{getParent:i}=P.useContext(Ge),s=P.useMemo((()=>i()),[i]),l=P.useRef(null);P.useImperativeHandle(o,(()=>l.current),[]);const c=new D.Vector3;return a.useFrame((n=>{s.current&&l.current&&(l.current.getWorldPosition(c),s.current.addBall(.5+.5*c.x,.5+.5*c.y,.5+.5*c.z,e,t,r))})),P.createElement("group",C.default({ref:l},n))})),qe=P.forwardRef((({planeType:e="x",strength:t=.5,subtract:r=12,...n},o)=>{const{getParent:i}=P.useContext(Ge),s=P.useMemo((()=>i()),[i]),l=P.useRef(null);P.useImperativeHandle(o,(()=>l.current),[]);const c=P.useMemo((()=>"x"===e?"addPlaneX":"y"===e?"addPlaneY":"addPlaneZ"),[e]);return a.useFrame((()=>{s.current&&l.current&&s.current[c](t,r)})),P.createElement("group",C.default({ref:l},n))}));function Xe(e=[0,0,0]){return function(e){return Array.isArray(e)}(e)?e:e instanceof D.Vector3||e instanceof D.Euler?[e.x,e.y,e.z]:[e,e,e]}const Ze=P.forwardRef((function({debug:e,depthTest:t=!1,polygonOffsetFactor:r=-10,map:n,mesh:o,children:i,position:s,rotation:l,scale:c,...d},m){const f=P.useRef(null);P.useImperativeHandle(m,(()=>f.current));const p=P.useRef(null),h=P.useRef({position:new D.Vector3,rotation:new D.Euler,scale:new D.Vector3(1,1,1)});return P.useLayoutEffect((()=>{const e=(null==o?void 0:o.current)||f.current.parent,t=f.current;if(!(e instanceof D.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');if(e){a.applyProps(h.current,{position:s,scale:c});const r=e.matrixWorld.clone();if(e.matrixWorld.identity(),l&&"number"!=typeof l)a.applyProps(h.current,{rotation:l});else{const t=new D.Object3D;t.position.copy(h.current.position);const r=e.geometry.attributes.position.array;void 0===e.geometry.attributes.normal&&e.geometry.computeVertexNormals();const n=e.geometry.attributes.normal.array;let o=1/0;new D.Vector3;let i=new D.Vector3;const s=t.position.x,c=t.position.y,u=t.position.z,d=r.length;let m=-1;for(let e=0;e<d;e+=3){const t=r[e]-s,n=r[e+1]-c,a=r[e+2]-u,i=t*t+n*n+a*a;i<o&&(o=i,m=e)}i.fromArray(n,m),t.lookAt(t.position.clone().add(i)),t.rotateZ(Math.PI),t.rotateY(Math.PI),"number"==typeof l&&t.rotateZ(l),a.applyProps(h.current,{rotation:t.rotation})}return t.geometry=new u.DecalGeometry(e,h.current.position,h.current.rotation,h.current.scale),e.matrixWorld=r,()=>{t.geometry.dispose()}}}),[o,...Xe(s),...Xe(c),...Xe(l)]),P.useLayoutEffect((()=>{p.current&&(a.applyProps(p.current,h.current),p.current.traverse((e=>e.raycast=()=>null)))}),[e]),P.createElement("mesh",C.default({ref:f,"material-transparent":!0,"material-polygonOffset":!0,"material-polygonOffsetFactor":r,"material-depthTest":t,"material-map":n},d),i,e&&P.createElement("mesh",{ref:p},P.createElement("boxGeometry",null),P.createElement("meshNormalMaterial",{wireframe:!0}),P.createElement("axesHelper",null)))})),Ye=t.forwardRef((function({src:e,skipFill:r,skipStrokes:o,fillMaterial:i,strokeMaterial:s,fillMeshProps:l,strokeMeshProps:c,...d},m){const f=a.useLoader(u.SVGLoader,e.startsWith("<svg")?`data:image/svg+xml;utf8,${e}`:e),p=t.useMemo((()=>o?[]:f.paths.map((e=>{var t;return void 0===(null==(t=e.userData)?void 0:t.style.stroke)||"none"===e.userData.style.stroke?null:e.subPaths.map((t=>u.SVGLoader.pointsToStroke(t.getPoints(),e.userData.style)))}))),[f,o]);t.useEffect((()=>()=>p.forEach((e=>e&&e.map((e=>e.dispose()))))),[p]);let h=0;return P.createElement("object3D",C.default({ref:m},d),P.createElement("object3D",{scale:[1,-1,1]},f.paths.map(((e,a)=>{var d,m;return P.createElement(t.Fragment,{key:a},!r&&void 0!==(null==(d=e.userData)?void 0:d.style.fill)&&"none"!==e.userData.style.fill&&u.SVGLoader.createShapes(e).map(((t,r)=>P.createElement("mesh",C.default({key:r},l,{renderOrder:h++}),P.createElement("shapeGeometry",{args:[t]}),P.createElement("meshBasicMaterial",C.default({color:e.userData.style.fill,opacity:e.userData.style.fillOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},i))))),!o&&void 0!==(null==(m=e.userData)?void 0:m.style.stroke)&&"none"!==e.userData.style.stroke&&e.subPaths.map(((t,r)=>P.createElement("mesh",C.default({key:r,geometry:p[a][r]},c,{renderOrder:h++}),P.createElement("meshBasicMaterial",C.default({color:e.userData.style.stroke,opacity:e.userData.style.strokeOpacity,transparent:!0,side:n.DoubleSide,depthWrite:!1},s))))))}))))}));let Qe=null,Ke="https://www.gstatic.com/draco/versioned/decoders/1.5.5/";function Je(e=!0,t=!0,r){return n=>{r&&r(n),e&&(Qe||(Qe=new u.DRACOLoader),Qe.setDecoderPath("string"==typeof e?e:Ke),n.setDRACOLoader(Qe)),t&&n.setMeshoptDecoder("function"==typeof u.MeshoptDecoder?u.MeshoptDecoder():u.MeshoptDecoder)}}const et=(e,t,r,n)=>a.useLoader(u.GLTFLoader,e,Je(t,r,n));et.preload=(e,t,r,n)=>a.useLoader.preload(u.GLTFLoader,e,Je(t,r,n)),et.clear=e=>a.useLoader.clear(u.GLTFLoader,e),et.setDecoderPath=e=>{Ke=e};const tt=P.forwardRef((({src:e,useDraco:t,useMeshOpt:r,extendLoader:n,...a},o)=>{const{scene:i}=et(e,t,r,n);return P.createElement(We,C.default({ref:o},a,{object:i}))}));const rt=Ce({alphaTest:0,viewport:new D.Vector2(1980,1080),focal:1e3,centerAndScaleTexture:null,covAndColorTexture:null},"\n precision highp sampler2D;\n precision highp usampler2D;\n out vec4 vColor;\n out vec3 vPosition;\n uniform vec2 resolution;\n uniform vec2 viewport;\n uniform float focal;\n attribute uint splatIndex;\n uniform sampler2D centerAndScaleTexture;\n uniform usampler2D covAndColorTexture; \n\n vec2 unpackInt16(in uint value) {\n int v = int(value);\n int v0 = v >> 16;\n int v1 = (v & 0xFFFF);\n if((v & 0x8000) != 0)\n v1 |= 0xFFFF0000;\n return vec2(float(v1), float(v0));\n }\n\n void main () {\n ivec2 texSize = textureSize(centerAndScaleTexture, 0);\n ivec2 texPos = ivec2(splatIndex%uint(texSize.x), splatIndex/uint(texSize.x));\n vec4 centerAndScaleData = texelFetch(centerAndScaleTexture, texPos, 0);\n vec4 center = vec4(centerAndScaleData.xyz, 1);\n vec4 camspace = modelViewMatrix * center;\n vec4 pos2d = projectionMatrix * camspace;\n\n float bounds = 1.2 * pos2d.w;\n if (pos2d.z < -pos2d.w || pos2d.x < -bounds || pos2d.x > bounds\n || pos2d.y < -bounds || pos2d.y > bounds) {\n gl_Position = vec4(0.0, 0.0, 2.0, 1.0);\n return;\n }\n\n uvec4 covAndColorData = texelFetch(covAndColorTexture, texPos, 0);\n vec2 cov3D_M11_M12 = unpackInt16(covAndColorData.x) * centerAndScaleData.w;\n vec2 cov3D_M13_M22 = unpackInt16(covAndColorData.y) * centerAndScaleData.w;\n vec2 cov3D_M23_M33 = unpackInt16(covAndColorData.z) * centerAndScaleData.w;\n mat3 Vrk = mat3(\n cov3D_M11_M12.x, cov3D_M11_M12.y, cov3D_M13_M22.x,\n cov3D_M11_M12.y, cov3D_M13_M22.y, cov3D_M23_M33.x,\n cov3D_M13_M22.x, cov3D_M23_M33.x, cov3D_M23_M33.y\n );\n\n mat3 J = mat3(\n focal / camspace.z, 0., -(focal * camspace.x) / (camspace.z * camspace.z),\n 0., focal / camspace.z, -(focal * camspace.y) / (camspace.z * camspace.z),\n 0., 0., 0.\n );\n\n mat3 W = transpose(mat3(modelViewMatrix));\n mat3 T = W * J;\n mat3 cov = transpose(T) * Vrk * T;\n vec2 vCenter = vec2(pos2d) / pos2d.w;\n float diagonal1 = cov[0][0] + 0.3;\n float offDiagonal = cov[0][1];\n float diagonal2 = cov[1][1] + 0.3;\n float mid = 0.5 * (diagonal1 + diagonal2);\n float radius = length(vec2((diagonal1 - diagonal2) / 2.0, offDiagonal));\n float lambda1 = mid + radius;\n float lambda2 = max(mid - radius, 0.1);\n vec2 diagonalVector = normalize(vec2(offDiagonal, lambda1 - diagonal1));\n vec2 v1 = min(sqrt(2.0 * lambda1), 1024.0) * diagonalVector;\n vec2 v2 = min(sqrt(2.0 * lambda2), 1024.0) * vec2(diagonalVector.y, -diagonalVector.x);\n uint colorUint = covAndColorData.w;\n vColor = vec4(\n float(colorUint & uint(0xFF)) / 255.0,\n float((colorUint >> uint(8)) & uint(0xFF)) / 255.0,\n float((colorUint >> uint(16)) & uint(0xFF)) / 255.0,\n float(colorUint >> uint(24)) / 255.0\n );\n vPosition = position;\n\n gl_Position = vec4(\n vCenter \n + position.x * v2 / viewport * 2.0 \n + position.y * v1 / viewport * 2.0, pos2d.z / pos2d.w, 1.0);\n }\n ",`\n #include <alphatest_pars_fragment>\n #include <alphahash_pars_fragment>\n in vec4 vColor;\n in vec3 vPosition;\n void main () {\n float A = -dot(vPosition.xy, vPosition.xy);\n if (A < -4.0) discard;\n float B = exp(A) * vColor.a;\n vec4 diffuseColor = vec4(vColor.rgb, B);\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <tonemapping_fragment>\n #include <${parseInt(D.REVISION.replace(/\D+/g,""))>=154?"colorspace_fragment":"encodings_fragment"}>\n }\n `);function nt(e){let t=null,r=0;e.onmessage=n=>{if("push"==n.data.method){0===r&&(t=new Float32Array(n.data.length));const e=new Float32Array(n.data.matrices);t.set(e,r),r+=e.length}else if("sort"==n.data.method&&null!==t){const r=function(e,r=!1){const n=t.length/16;let a=-1/0,o=1/0;const i=new Float32Array(n),s=new Int32Array(i.buffer),l=new Int32Array(n);let c=0;for(let s=0;s<n;s++){const n=e[0]*t[16*s+12]+e[1]*t[16*s+13]+e[2]*t[16*s+14]+e[3];(r||n<0&&t[16*s+15]>-1e-4*n)&&(i[c]=n,l[c]=s,c++,n>a&&(a=n),n<o&&(o=n))}const u=65535/(a-o),d=new Uint32Array(65536);for(let e=0;e<c;e++)s[e]=(i[e]-o)*u|0,d[s[e]]++;const m=new Uint32Array(65536);for(let e=1;e<65536;e++)m[e]=m[e-1]+d[e-1];const f=new Uint32Array(c);for(let e=0;e<c;e++)f[m[s[e]]++]=l[e];return f}(new Float32Array(n.data.view),n.data.hashed);e.postMessage({indices:r,key:n.data.key},[r.buffer])}}}class at extends D.Loader{constructor(...e){super(...e),this.gl=null,this.chunkSize=25e3}load(e,t,r,n){const a={gl:this.gl,url:this.manager.resolveURL(e),worker:new Worker(URL.createObjectURL(new Blob(["(",nt.toString(),")(self)"],{type:"application/javascript"}))),manager:this.manager,update:(e,t,r)=>function(e,t,r,n){if(e.updateMatrixWorld(),t.gl.getCurrentViewport(r.viewport),r.material.viewport.x=r.viewport.z,r.material.viewport.y=r.viewport.w,r.material.focal=r.viewport.w/2*Math.abs(e.projectionMatrix.elements[5]),r.ready){if(n&&r.sorted)return;r.ready=!1;const e=new Float32Array([r.modelViewMatrix.elements[2],-r.modelViewMatrix.elements[6],r.modelViewMatrix.elements[10],r.modelViewMatrix.elements[14]]);t.worker.postMessage({method:"sort",src:t.url,key:r.uuid,view:e.buffer,hashed:n},[e.buffer]),n&&t.loaded&&(r.sorted=!0)}}(t,a,e,r),connect:e=>function(e,t){e.loading||async function(e){e.loading=!0;let t=0,r=0;const n=[];let a=0;const o=0!==e.totalDownloadBytes;for(;;)try{const{value:i,done:s}=await e.stream.read();if(s)break;if(t+=i.length,null!=e.totalDownloadBytes){const r=t/e.totalDownloadBytes*100;if(e.onProgress&&r-a>1){const n=new ProgressEvent("progress",{lengthComputable:o,loaded:t,total:e.totalDownloadBytes});e.onProgress(n),a=r}}n.push(i);const l=t-r;if(null!=e.totalDownloadBytes&&l>e.rowLength*e.chunkSize){let t=Math.floor(l/e.rowLength);const a=new Uint8Array(l);let i=0;for(const e of n)a.set(e,i),i+=e.length;if(n.length=0,l>t*e.rowLength){const r=new Uint8Array(l-t*e.rowLength);r.set(a.subarray(l-r.length,l),0),n.push(r)}const s=new Uint8Array(t*e.rowLength);s.set(a.subarray(0,s.byteLength),0);const c=ot(e,s.buffer,t);if(e.worker.postMessage({method:"push",src:e.url,length:16*e.numVertices,matrices:c.buffer},[c.buffer]),r+=t*e.rowLength,e.onProgress){const t=new ProgressEvent("progress",{lengthComputable:o,loaded:e.totalDownloadBytes,total:e.totalDownloadBytes});e.onProgress(t)}}}catch(e){console.error(e);break}if(t-r>0){let t=new Uint8Array(n.reduce(((e,t)=>e+t.length),0)),r=0;for(const e of n)t.set(e,r),r+=e.length;let a=Math.floor(t.byteLength/e.rowLength);const o=ot(e,t.buffer,a);e.worker.postMessage({method:"push",src:e.url,length:16*a,matrices:o.buffer},[o.buffer])}e.loaded=!0,e.manager.itemEnd(e.url)}(e);t.ready=!1,t.pm=new D.Matrix4,t.vm1=new D.Matrix4,t.vm2=new D.Matrix4,t.viewport=new D.Vector4;let r=new Uint32Array(e.bufferTextureWidth*e.bufferTextureHeight);const n=new D.InstancedBufferAttribute(r,1,!1);n.setUsage(D.DynamicDrawUsage);const a=t.geometry=new D.InstancedBufferGeometry,o=new Float32Array(18),i=new D.BufferAttribute(o,3);function s(e){if(t&&e.data.key===t.uuid){let r=new Uint32Array(e.data.indices);a.attributes.splatIndex.set(r),a.attributes.splatIndex.needsUpdate=!0,a.instanceCount=r.length,t.ready=!0}}async function l(){for(;;){const t=e.gl.properties.get(e.centerAndScaleTexture),r=e.gl.properties.get(e.covAndColorTexture);if(null!=t&&t.__webglTexture&&null!=r&&r.__webglTexture&&e.loadedVertexCount>0)break;await new Promise((e=>setTimeout(e,10)))}t.ready=!0}return a.setAttribute("position",i),i.setXYZ(2,-2,2,0),i.setXYZ(1,2,2,0),i.setXYZ(0,-2,-2,0),i.setXYZ(5,-2,-2,0),i.setXYZ(4,2,2,0),i.setXYZ(3,2,-2,0),i.needsUpdate=!0,a.setAttribute("splatIndex",n),a.instanceCount=1,e.worker.addEventListener("message",s),l(),()=>e.worker.removeEventListener("message",s)}(a,e),loading:!1,loaded:!1,loadedVertexCount:0,chunkSize:this.chunkSize,totalDownloadBytes:0,numVertices:0,rowLength:32,maxVertexes:0,bufferTextureWidth:0,bufferTextureHeight:0,stream:null,centerAndScaleData:null,covAndColorData:null,covAndColorTexture:null,centerAndScaleTexture:null,onProgress:r};(async function(e){e.manager.itemStart(e.url);const t=await fetch(e.url);if(null===t.body)throw"Failed to fetch file";let r=t.headers.get("Content-Length");const n=r?parseInt(r):void 0;if(null==n)throw"Failed to get content length";e.stream=t.body.getReader(),e.totalDownloadBytes=n,e.numVertices=Math.floor(e.totalDownloadBytes/e.rowLength);const a=e.gl.getContext();let o=a.getParameter(a.MAX_TEXTURE_SIZE);e.maxVertexes=o*o,e.numVertices>e.maxVertexes&&(e.numVertices=e.maxVertexes);return e.bufferTextureWidth=o,e.bufferTextureHeight=Math.floor((e.numVertices-1)/o)+1,e.centerAndScaleData=new Float32Array(e.bufferTextureWidth*e.bufferTextureHeight*4),e.covAndColorData=new Uint32Array(e.bufferTextureWidth*e.bufferTextureHeight*4),e.centerAndScaleTexture=new D.DataTexture(e.centerAndScaleData,e.bufferTextureWidth,e.bufferTextureHeight,D.RGBAFormat,D.FloatType),e.centerAndScaleTexture.needsUpdate=!0,e.covAndColorTexture=new D.DataTexture(e.covAndColorData,e.bufferTextureWidth,e.bufferTextureHeight,D.RGBAIntegerFormat,D.UnsignedIntType),e.covAndColorTexture.internalFormat="RGBA32UI",e.covAndColorTexture.needsUpdate=!0,e})(a).then(t).catch((e=>{null==n||n(e),a.manager.itemError(a.url)}))}}function ot(e,t,r){const n=e.gl.getContext();if(e.loadedVertexCount+r>e.maxVertexes&&(r=e.maxVertexes-e.loadedVertexCount),r<=0)throw"Failed to parse file";const a=new Uint8Array(t),o=new Float32Array(t),i=new Float32Array(16*r),s=new Uint8Array(e.covAndColorData.buffer),l=new Int16Array(e.covAndColorData.buffer);for(let t=0;t<r;t++){const r=new D.Quaternion(-(a[32*t+28+1]-128)/128,(a[32*t+28+2]-128)/128,(a[32*t+28+3]-128)/128,-(a[32*t+28+0]-128)/128);r.invert();const n=new D.Vector3(o[8*t+0],o[8*t+1],-o[8*t+2]),c=new D.Vector3(o[8*t+3+0],o[8*t+3+1],o[8*t+3+2]),u=new D.Matrix4;u.makeRotationFromQuaternion(r),u.transpose(),u.scale(c);const d=u.clone();u.transpose(),u.premultiply(d),u.setPosition(n);const m=[0,1,2,5,6,10];let f=0;for(let e=0;e<m.length;e++)Math.abs(u.elements[m[e]])>f&&(f=Math.abs(u.elements[m[e]]));let p=4*e.loadedVertexCount+4*t;e.centerAndScaleData[p+0]=n.x,e.centerAndScaleData[p+1]=-n.y,e.centerAndScaleData[p+2]=n.z,e.centerAndScaleData[p+3]=f/32767,p=8*e.loadedVertexCount+4*t*2;for(let e=0;e<m.length;e++)l[p+e]=32767*u.elements[m[e]]/f;p=16*e.loadedVertexCount+4*(4*t+3);const h=new D.Color(a[32*t+24+0]/255,a[32*t+24+1]/255,a[32*t+24+2]/255);h.convertSRGBToLinear(),s[p+0]=255*h.r,s[p+1]=255*h.g,s[p+2]=255*h.b,s[p+3]=a[32*t+24+3],u.elements[15]=Math.max(c.x,c.y,c.z)*a[32*t+24+3]/255;for(let e=0;e<16;e++)i[16*t+e]=u.elements[e]}for(;r>0;){let t=0,a=0;const o=e.loadedVertexCount%e.bufferTextureWidth,i=Math.floor(e.loadedVertexCount/e.bufferTextureWidth);e.loadedVertexCount%e.bufferTextureWidth!=0?(t=Math.min(e.bufferTextureWidth,o+r)-o,a=1):Math.floor(r/e.bufferTextureWidth)>0?(t=e.bufferTextureWidth,a=Math.floor(r/e.bufferTextureWidth)):(t=r%e.bufferTextureWidth,a=1);const s=e.gl.properties.get(e.centerAndScaleTexture);n.bindTexture(n.TEXTURE_2D,s.__webglTexture),n.texSubImage2D(n.TEXTURE_2D,0,o,i,t,a,n.RGBA,n.FLOAT,e.centerAndScaleData,4*e.loadedVertexCount);const l=e.gl.properties.get(e.covAndColorTexture);n.bindTexture(n.TEXTURE_2D,l.__webglTexture),n.texSubImage2D(n.TEXTURE_2D,0,o,i,t,a,n.RGBA_INTEGER,n.UNSIGNED_INT,e.covAndColorData,4*e.loadedVertexCount),e.gl.resetState(),e.loadedVertexCount+=t*a,r-=t*a}return i}function it(e,t,r){const n=a.useThree((e=>e.size)),o=a.useThree((e=>e.viewport)),i="number"==typeof e?e:n.width*o.dpr,s="number"==typeof t?t:n.height*o.dpr,l=("number"==typeof e?r:e)||{},{samples:c=0,depth:u,...d}=l,m=P.useMemo((()=>{const e=new D.WebGLRenderTarget(i,s,{minFilter:D.LinearFilter,magFilter:D.LinearFilter,type:D.HalfFloatType,...d});return u&&(e.depthTexture=new D.DepthTexture(i,s,D.FloatType)),e.samples=c,e}),[]);return P.useLayoutEffect((()=>{m.setSize(i,s),c&&(m.samples=c)}),[c,m,i,s]),P.useEffect((()=>()=>m.dispose()),[]),m}const st=P.forwardRef((({envMap:e,resolution:t=256,frames:r=1/0,children:n,makeDefault:o,...i},s)=>{const l=a.useThree((({set:e})=>e)),c=a.useThree((({camera:e})=>e)),u=a.useThree((({size:e})=>e)),d=P.useRef(null);P.useImperativeHandle(s,(()=>d.current),[]);const m=P.useRef(null),f=it(t);P.useLayoutEffect((()=>{i.manual||d.current.updateProjectionMatrix()}),[u,i]),P.useLayoutEffect((()=>{d.current.updateProjectionMatrix()})),P.useLayoutEffect((()=>{if(o){const e=c;return l((()=>({camera:d.current}))),()=>l((()=>({camera:e})))}}),[d,o,l]);let p=0,h=null;const x="function"==typeof n;return a.useFrame((t=>{x&&(r===1/0||p<r)&&(m.current.visible=!1,t.gl.setRenderTarget(f),h=t.scene.background,e&&(t.scene.background=e),t.gl.render(t.scene,d.current),t.scene.background=h,t.gl.setRenderTarget(null),m.current.visible=!0,p++)})),P.createElement(P.Fragment,null,P.createElement("orthographicCamera",C.default({left:u.width/-2,right:u.width/2,top:u.height/2,bottom:u.height/-2,ref:d},i),!x&&n),P.createElement("group",{ref:m},x&&n(f.texture)))})),lt