You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
}`;constF=(r,s=!1)=>{consto=s?r.width*s:r.width,a=s?r.height*s:r.height;returnu.useMemo(()=>newn.Vector2(o,a),[o,a])},P=(r,s,o)=>{consta=u.useMemo(()=>newn.Mesh(s,o),[s,o]);returnu.useEffect(()=>{r.add(a)},[r,a]),u.useEffect(()=>()=>{r.remove(a),s.dispose(),o.dispose()},[r,s,o,a]),a},i=(r,s,o)=>{r.uniforms&&r.uniforms[s]&&o!==void0&&o!==null?r.uniforms[s].value=o:console.error(`Uniform key "${String(s)}" does not exist in the material. or "${String(s)}" is null | undefined`)},ve=({scene:r,size:s,dpr:o})=>{consta=u.useMemo(()=>newn.PlaneGeometry(2,2),[]),e=u.useMemo(()=>newn.ShaderMaterial({uniforms:{uMap:{value:newn.Texture},uResolution:{value:newn.Vector2(0,0)},uAspect:{value:0},uTexture:{value:newn.Texture},uRadius:{value:0},uSmudge:{value:0},uDissipation:{value:0},uMotionBlur:{value:0},uMotionSample:{value:0},uMouse:{value:newn.Vector2(0,0)},uPrevMouse:{value:newn.Vector2(0,0)},uVelocity:{value:newn.Vector2(0,0)},uColor:{value:newn.Color(16777215)}},vertexShader:le,fragmentShader:ce}),[]),l=F(s,o);returnu.useEffect(()=>{i(e,"uAspect",l.width/l.height),i(e,"uResolution",l.clone())},[l,e]),P(r,a,e),e},fe=(r,s)=>{consto=s,a=r/s,[e,l]=[o*a/2,o/2];return{width:e,height:l,near:-1e3,far:1e3}},b=r=>{consts=F(r),{width:o,height:a,near:e,far:l}=fe(s.x,s.y);returnu.useMemo(()=>newn.OrthographicCamera(-o,o,a,-a,e,l),[o,a,e,l])},$=()=>{constr=u.useRef(newn.Vector2(0,0)),s=u.useRef(newn.Vector2(0,0)),o=u.useRef(0),a=u.useRef(newn.Vector2(0,0)),e=u.useRef(!1);returnu.useCallback(d=>{constf=performance.now(),t=d.clone();o.current===0&&(o.current=f,r.current=t);constc=Math.max(1,f-o.current);o.current=f,a.current.copy(t).sub(r.current).divideScalar(c);constp=a.current.length()>0,m=e.current?r.current.clone():t;return!e.current&&p&&(e.current=!0),r.current=t,{currentPointer:t,prevPointer:m,diffPointer:s.current.subVectors(t,m),velocity:a.current,isVelocityUpdate:p}},[])},C=r=>{consts=e=>Object.values(e).some(l=>typeofl=="function"),o=u.useRef(s(r)?r:structuredClone(r)),a=u.useCallback(e=>{for(constline){constd=l;dino.current&&e[d]!==void0&&e[d]!==null?o.current[d]=e[d]:console.error(`"${String(d)}" does not exist in the params. or "${String(d)}" is null | undefined`)}},[]);return[o.current,a]},N={minFilter:n.LinearFilter,magFilter:n.LinearFilter,type:n.HalfFloatType,stencilBuffer:!1},D=({scene:r,camera:s,size:o,dpr:a=!1,isSizeUpdate:e=!1,samples:l=0,depthBuffer:d=!1,depthTexture:f=!1})=>{constt=u.useRef(),c=F(o,a);t.current=u.useMemo(()=>{constm=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d});returnf&&(m.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType)),m},[]),u.useLayoutEffect(()=>{varm;e&&((m=t.current)==null||m.setSize(c.x,c.y))},[c,e]),u.useEffect(()=>{constm=t.current;return()=>{m==null||m.dispose()}},[]);constp=u.useCallback((m,v)=>{constg=t.current;returnm.setRenderTarget(g),v&&v({read:g.texture}),m.render(r,s),m.setRenderTarget(null),m.clear(),g.texture},[r,s]);return[t.current,p]},I=({scene:r,camera:s,size:o,dpr:a=!1,isSizeUpdate:e=!1,samples:l=0,depthBuffer:d=!1,depthTexture:f=!1})=>{constt=u.useRef({read:null,write:null,swap:function(){letv=this.read;this.read=this.write,this.write=v}}),c=F(o,a),p=u.useMemo(()=>{constv=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d}),g=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d});returnf&&(v.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType),g.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType)),{read:v,write:g}},[]);t.current.read=p.read,t.current.write=p.write,u.useLayoutEffect(()=>{varv,g;e&&((v=t.current.read)==null||v.setSize(c.x,c.y),(g=t.current.write)==null||g.setSize(c.x,c.y))},[c,e]),u.useEffect(()=>{constv=t.current;return()=>{varg,h;(g=v.read)==null||g.dispose(),(h=v.write)==null||h.dispose()}},[]);constm=u.useCallback((v,g)=>{vary;consth=t.current;returnv.setRenderTarget(h.write),g&&g({read:h.read.texture,write:h.write.texture}),v.render(r,s),h.swap(),v.setRenderTarget(null),v.clear(),(y=h.read)==null?void0:y.texture},[r,s]);return[{read:t.current.read,write:t.current.write},m]},W={texture:newn.Texture,radius:.05,smudge:0,dissipation:1,motionBlur:0,motionSample:5,color:newn.Color(16777215)},de=({size:r,dpr:s,samples:o=0})=>{consta=u.useMemo(()=>newn.Scene,[]),e=ve({scene:a,size:r,dpr:s}),l=b(r),d=$(),[f,t]=I({scene:a,camera:l,size:r,dpr:s,samples:o}),[c,p]=C(W);return[u.useCallback((v,g)=>{const{gl:h,pointer:y}=v;g&&p(g),i(e,"uTexture",c.texture),i(e,"uRadius",c.radius),i(e,"uSmudge",c.smudge),i(e,"uDissipation",c.dissipation),i(e,"uMotionBlur",c.motionBlur),i(e,"uMotionSample",c.motionSample),i(e,"uColor",c.color);const{currentPointer:M,prevPointer:w,velocity:T}=d(y);returni(e,"uMouse",M),i(e,"uPrevMouse",w),i(e,"uVelocity",T),t(h,({read:U})=>{i(e,"uMap",U)})},[e,d,t,c,p]),p,{scene:a,material:e,camera:l,renderTarget:f}]};varme=`varying vec2 vUv;
108
+
}`;constF=(r,s=!1)=>{consto=s?r.width*s:r.width,a=s?r.height*s:r.height;returnu.useMemo(()=>newn.Vector2(o,a),[o,a])},P=(r,s,o)=>{consta=u.useMemo(()=>newn.Mesh(s,o),[s,o]);returnu.useEffect(()=>{r.add(a)},[r,a]),u.useEffect(()=>()=>{r.remove(a),s.dispose(),o.dispose()},[r,s,o,a]),a},i=(r,s,o)=>{r.uniforms&&r.uniforms[s]&&o!==void0&&o!==null?r.uniforms[s].value=o:console.error(`Uniform key "${String(s)}" does not exist in the material. or "${String(s)}" is null | undefined`)},ve=({scene:r,size:s,dpr:o})=>{consta=u.useMemo(()=>newn.PlaneGeometry(2,2),[]),e=u.useMemo(()=>newn.ShaderMaterial({uniforms:{uMap:{value:newn.Texture},uResolution:{value:newn.Vector2(0,0)},uAspect:{value:0},uTexture:{value:newn.Texture},uRadius:{value:0},uSmudge:{value:0},uDissipation:{value:0},uMotionBlur:{value:0},uMotionSample:{value:0},uMouse:{value:newn.Vector2(0,0)},uPrevMouse:{value:newn.Vector2(0,0)},uVelocity:{value:newn.Vector2(0,0)},uColor:{value:newn.Color(16777215)}},vertexShader:le,fragmentShader:ce}),[]),l=F(s,o);returnu.useEffect(()=>{i(e,"uAspect",l.width/l.height),i(e,"uResolution",l.clone())},[l,e]),P(r,a,e),e},fe=(r,s)=>{consto=s,a=r/s,[e,l]=[o*a/2,o/2];return{width:e,height:l,near:-1e3,far:1e3}},b=r=>{consts=F(r),{width:o,height:a,near:e,far:l}=fe(s.x,s.y);returnu.useMemo(()=>newn.OrthographicCamera(-o,o,a,-a,e,l),[o,a,e,l])},$=()=>{constr=u.useRef(newn.Vector2(0,0)),s=u.useRef(newn.Vector2(0,0)),o=u.useRef(0),a=u.useRef(newn.Vector2(0,0)),e=u.useRef(!1);returnu.useCallback(d=>{constf=performance.now(),t=d.clone();o.current===0&&(o.current=f,r.current=t);constc=Math.max(1,f-o.current);o.current=f,a.current.copy(t).sub(r.current).divideScalar(c);constp=a.current.length()>0,m=e.current?r.current.clone():t;return!e.current&&p&&(e.current=!0),r.current=t,{currentPointer:t,prevPointer:m,diffPointer:s.current.subVectors(t,m),velocity:a.current,isVelocityUpdate:p}},[])},C=r=>{consts=e=>Object.values(e).some(l=>typeofl=="function"),o=u.useRef(s(r)?r:structuredClone(r)),a=u.useCallback(e=>{for(constline){constd=l;dino.current&&e[d]!==void0&&e[d]!==null?o.current[d]=e[d]:console.error(`"${String(d)}" does not exist in the params. or "${String(d)}" is null | undefined`)}},[]);return[o.current,a]},N={minFilter:n.LinearFilter,magFilter:n.LinearFilter,type:n.HalfFloatType,stencilBuffer:!1},D=({scene:r,camera:s,size:o,dpr:a=!1,isSizeUpdate:e=!1,samples:l=0,depthBuffer:d=!1,depthTexture:f=!1})=>{constt=u.useRef(),c=F(o,a);t.current=u.useMemo(()=>{constm=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d});returnf&&(m.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType)),m},[]),u.useLayoutEffect(()=>{varm;e&&((m=t.current)==null||m.setSize(c.x,c.y))},[c,e]),u.useEffect(()=>{constm=t.current;return()=>{m==null||m.dispose()}},[]);constp=u.useCallback((m,v)=>{constg=t.current;returnm.setRenderTarget(g),v&&v({read:g.texture}),m.clear(),m.render(r,s),m.setRenderTarget(null),m.clear(),g.texture},[r,s]);return[t.current,p]},I=({scene:r,camera:s,size:o,dpr:a=!1,isSizeUpdate:e=!1,samples:l=0,depthBuffer:d=!1,depthTexture:f=!1})=>{constt=u.useRef({read:null,write:null,swap:function(){letv=this.read;this.read=this.write,this.write=v}}),c=F(o,a),p=u.useMemo(()=>{constv=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d}),g=newn.WebGLRenderTarget(c.x,c.y,{...N,samples:l,depthBuffer:d});returnf&&(v.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType),g.depthTexture=newn.DepthTexture(c.x,c.y,n.FloatType)),{read:v,write:g}},[]);t.current.read=p.read,t.current.write=p.write,u.useLayoutEffect(()=>{varv,g;e&&((v=t.current.read)==null||v.setSize(c.x,c.y),(g=t.current.write)==null||g.setSize(c.x,c.y))},[c,e]),u.useEffect(()=>{constv=t.current;return()=>{varg,h;(g=v.read)==null||g.dispose(),(h=v.write)==null||h.dispose()}},[]);constm=u.useCallback((v,g)=>{vary;consth=t.current;returnv.setRenderTarget(h.write),g&&g({read:h.read.texture,write:h.write.texture}),v.clear(),v.render(r,s),h.swap(),v.setRenderTarget(null),v.clear(),(y=h.read)==null?void0:y.texture},[r,s]);return[{read:t.current.read,write:t.current.write},m]},W={texture:newn.Texture,radius:.05,smudge:0,dissipation:1,motionBlur:0,motionSample:5,color:newn.Color(16777215)},de=({size:r,dpr:s,samples:o=0})=>{consta=u.useMemo(()=>newn.Scene,[]),e=ve({scene:a,size:r,dpr:s}),l=b(r),d=$(),[f,t]=I({scene:a,camera:l,size:r,dpr:s,samples:o}),[c,p]=C(W);return[u.useCallback((v,g)=>{const{gl:h,pointer:y}=v;g&&p(g),i(e,"uTexture",c.texture),i(e,"uRadius",c.radius),i(e,"uSmudge",c.smudge),i(e,"uDissipation",c.dissipation),i(e,"uMotionBlur",c.motionBlur),i(e,"uMotionSample",c.motionSample),i(e,"uColor",c.color);const{currentPointer:M,prevPointer:w,velocity:T}=d(y);returni(e,"uMouse",M),i(e,"uPrevMouse",w),i(e,"uVelocity",T),t(h,({read:U})=>{i(e,"uMap",U)})},[e,d,t,c,p]),p,{scene:a,material:e,camera:l,renderTarget:f}]};varme=`varying vec2 vUv;
0 commit comments